texts:
Do you have to build the circuit on an external board every time you decide there is a need
for a pull-up or pull-down circuit? If not, then what is the alternative and how can you use
it?


texts: Can I use my Arduino nano to upload sketch in Uno's ATmega328p chip?

texts:
I can not upload sketch to my UNO directly. My ATmega16U2 doesn't work.But the Atmega328P processor still work.
 I have an arduino nano lying around. Can I use it to upload sketches to Atmega328P directly.
Thanks in advance


texts: Getting maximum value from HX711 and use it in the code further

texts:
i am using HX711 module to get value from load cell.my projects is a tensile strength testing machine,which will increase the load gradually and break at its maximum capacity.therefore i need the maximum value at which the specimen breaks.and use that value in the code to calcuate the tensile strengh of the specimen using the formula(tensile strength=load/cross section area of specimen).
Please help me with this and if possible ,i will be very gratefull if anyone can help me with the code too.
Thank you


texts: Interrupt on Analog Port - ESP8266 w/ Arduino

texts:
I'm trying to implement interrupts in my program. It essentially is constantly reading a photo-resistor and if it exceeds a certain threshold, we should send an update to our database. I'm struggling to understand how to do interrupts on a analog pin. I've tried reading this but honestly, it doesn't make much sense. Could anyone give me some advice? Here's out code.

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Initally send out false state
  sendState("18:FE:34:F4:D0:AF", false, false);
}

void loop() {

  if(analogRead(A0) < 20) {
    sendState("18:FE:34:F4:D0:AF", false, true);
    lastState = true;
    Serial.println("Waiting....");
    delay(15000);
  } else if(lastState == true){
    sendState("18:FE:34:F4:D0:AF", false, false);
    lastState = false;
  }

}

void sendState(String address, boolean lights, boolean occupied) {

  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  String lightsStr = (lights) ? "true" : "false";
  String occupiedStr = (occupied) ? "true" : "false";
  String json = "{\"MACAddress\":\"" + address + "\", \"occupied\":" + occupiedStr + "}";

  String postData;
  postData += "POST /sensor HTTP/1.0 \r\n";
  postData += "X-Parse-REST-API-Key: " + API_KEY + "\r\n";
  postData += "Content-Type: application/json \r\n";
  postData += "Host: " + String(host) + " \r\n";
  postData += "Content-Length: " + String(json.length()) + "\r\n\r\n";
  postData += json;

  // Send the postdata to the server.
  client.print(postData);

  delay(1000);

  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("Closing connection!");
}


texts: ADXL345 I2C setup not returning anything

texts:
My hookup is like this:

GND - GND  VCC - 5V  CS - 5V  SDO - GND  SDA - A4  SCL - A5

Here is the code:

#include <Wire.h>
#include <ADXL345.h>

ADXL345 accelerometer;

void setup(void)
{
  Serial.begin(9600);

  // Initialize ADXL345
  Serial.println("Initialize ADXL345");

  if (!accelerometer.begin())
  {
    Serial.println("Could not find a valid ADXL345 sensor, check wiring!");
    delay(500);
  }
  if (accelerometer.begin())
  {

  // Values for Free Fall detection
  accelerometer.setFreeFallThreshold(0.35); // Recommended 0.3 - 0.6 g
  accelerometer.setFreeFallDuration(0.1);  // Recommended 0.1 s

  // Select INT 1 for get activities
  accelerometer.useInterrupt(ADXL345_INT1);

  // Check settings
  checkSetup();
  }
}

void checkSetup()
{
  Serial.print("Free Fall Threshold = "); Serial.println(accelerometer.getFreeFallThreshold());
  Serial.print("Free Fall Duration = "); Serial.println(accelerometer.getFreeFallDuration());
}

void loop(void)
{
  delay(50);

  // Read values for activities
  Vector norm = accelerometer.readNormalize();

  // Read activities
  Activites activ = accelerometer.readActivites();

  if (activ.isFreeFall)
  {
    Serial.println("Free Fall Detected!");
  }
}

It comes from this Github link: https://github.com/jarzebski/Arduino-ADXL345/blob/master/ADXL345_free_fall/ADXL345_free_fall.ino

Initially, it would return "Could not find a valid ADXL345 sensor, check wiring!" in serial monitor. After messing with some wiring and changing to SPI
and back to I2C, it only returns "Initialize ADXL345".

I've added the second if() statement because it wouldn't say anything other than "Initialize ADXL345" even with the first if() statement, or with the first if() followed by an else. It should print the Free Fall Threshold and Duration but it hasn't. I have to leave and won't be back until tomorrow, so when I get back I'll try removing the checkSetup() command and maybe put something else in it's place to verify it's working. I feel like the answer is staring me in the face.

EDIT: Okay so after I finally got up from my computer for once, a thought popped into my mind and I figured the reason why checkSetup() isn't returning either string is because it's declared after setup() calls checkSetup()? Am I right? I feel like this would be the case in other languages.


texts:
I have a function that needs to return 3 int values. I currently use an array declared in the global scope and I ask the function to write into them. Is there a way to make a function return an array?

Here is what I want to do:

int function()
{

int array[3];

array[0] = 19;  //these are just random numbers

array[1] = 7;

array[2] = 69;

return array[]; //is this possible??

}


texts: MCU Type ATmega16U2 not avaliable in Eclipse AVR Plugin

texts:
I am following this guide. Now I want to create the Create the "ArduinoCore library". But when I am creating a new project, I can not select ATmega16U2 as MCU type.

But my Arduino Due R3-E and UNO SMD R3 both use ATmega16U2.

What shall I do O_o???


texts: Can I port a project built on Arduino Uno to a standalone ATmega328 using the exact same code?

texts: I'm building an IoT power usage monitor in which the data is logged using a RTC and an SD card module and a web app hosted on an ESP8266 gives access to this data. My question is can I use the exact same code (with libraries like "ESP8266.h") on a standalone ATmega programmed using Arduino as ISP?


texts: Difference between Arduino.cc and Arduino.org

texts: Recently I have noticed that there are two arduino sites, arduino.cc and arduino.org.  They both have the Arduino logo and both sell what seems to be official Arduino boards. Also, arduino.org came out with the Arduino Zero board first. What is the deal here? Has Arduino partnered with another site? Any ideas appreciated.


texts:
How can i send numbers like 300 or 1024 ?

I'm using the recommendation of the atmel's manual.

void SpiTransmitir(unsigned char data)
{
   SPDR = data;
   while(!(SPSR & (1<<SPIF)));//{Serial.println("While");}
}

I imagined that one bit shift could be the solution, but it still fails.


texts: How to make VOLTE/LTE or LTE calls using Arduino?

texts:
I want to make VOLTE/LTE calls using Arduino. I searched everywhere in Google. At last I found a website LTE Cellular Shield for Arduino with Voice!.

But I cannot find SIM7500 Shield in online shops. So U want to use SIM7000. But I can't find code for it. Can you share any?


texts:
A few days ago I encountered memory problems (SRAM shortage) on my Arduino. I've read a lot and fixed the problem, now I have around 900 bytes free in SRAM. However, I still have difficulties understanding and using progmem.

The user is allowed to create up to 10 programs (a program in my case is just some object storing the user's preferences). As I don't want to run out of SRAM, I planned to store them in PROGMEM.

Consider the following class:

#define MAX_PROGRAMS 10
#define MAX_PREFS 10

class Program
{
  public:
    Program(String name, Preference* prefs[]); // ctor

    String getName();
    static byte getNoOfPrograms();
    static Program* getProgram(byte idx);

  private:
    const String _name;
    static int _programCtr;

    Preference* _preferences[MAX_PREFS];
    static Program* _programs[MAX_PROGRAMS];
};

One notices that a program can store up to 10 preferences, hence, if the user decides to make 10 programs, each with 10 different preferences, we will definitely run out of SRAM.

Therefore, can I store instances of the above Program class in PROGMEM if I define them as below?

const Program* const pgm PROGMEM = new Program(F("Test"), ...);
// ...
delete pgm;

I presume this is possible since the whole object is const and could never be changed. I actually tried this and had no compiler errors, however, I was stumbled by the fact that the above two lines of code use 22 bytes of SRAM, when I expected it not to use any.

In my case, would it be better not to store the whole object in progmem but only its constant fields, and do the same for all constants in Preference ? (i.e. change const String _name to const char name[] PROGMEM; etc.)


texts:
I have this SD-card module. I have formatted the SD with this tool. My problem is that the Arduino Uno can't initialize the SD. I tried with this script:

// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 7;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
}

void loop(void) {
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("Doesn't work properly");
  } else{
    Serial.println("works properly");
  }
  delay(2000);
}

And the result:

Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
works properly
works properly
works properly
works properly
works properly
works properly
Doesn't work properly
Doesn't work properly
Doesn't work properly
works properly
works properly
works properly
Doesn't work properly

The "works properly" happens, usually, when I move the module slightly. Is there a way to repair the module?

OS: Windows 10


texts:
I'm using a Yún shield from Dragino with an Arduino Uno, but the default wifi password for the shield (which should be "dragino") isn't working.

I tried the wifi reset (holding down the reset button for 5 seconds) and a factory reset (holding down the reset button for 30 seconds) but the password still seems to be incorrect.

Is there any way I can reset the password?


texts: Increment in switch statement not working

texts:
No matter how I rearrange this, the increment compare always returns false....

I have even taken it out of the if, and put it in its own if:

int buttonFSM(button *ptrButton)
{
    int i;
    i = digitalRead(ptrButton->pin);
    switch(ptrButton->buttonState)
    {
    case SW_UP:
        if(i==0 && ++ptrButton->debounceTics == DBNC_TICS) //swtich went down
        {
            ptrButton->buttonState = SW_DOWN;
            ptrButton->debounceTics = 0;
            return SW_TRANS_UD;
        }
        ptrButton->debounceTics = 0;
        return SW_UP;
    case SW_DOWN:
        if(i==1 && ++ptrButton->debounceTics == DBNC_TICS) //switch is back up
        {
            ptrButton->buttonState = SW_UP;
            ptrButton->debounceTics = 0;
            return SW_TRANS_DU;
        }
        ptrButton->debounceTics = 0;
        return SW_DOWN;
    }
}


texts: How to subtract the current analog value from previous one

texts: I pretty new to the Arduino. I am working on project that find the power by reading your


texts: Arduino communication to Raspberry Pi using HC-05

texts:
I'm using two HC-05 modules on two Arduino UNO boards. One of my modules connected successfully to a raspberry pi port. However the other doesn't want to connect, but sometimes it does and then randomly disconnects. When I did manage to connect both modules to port on the pi I had code written to send data to the pi and display it in the terminal but only one Arduino data would show up on the pi terminal even though both were sending data. Is there an easier way to connect the modules? I've been using the bluetooth manager tool on the pi

void setup() {
 Serial.begin(9600);
 pinMode(8, INPUT); // first sensor input
 pinMode(7, INPUT); // second sensor input
 pinMode(6, INPUT); // third sensor input
 pinMode(5, INPUT); // fourth sensor input

}

void loop()
{

    int sensordata_1 = digitalRead(8); // read status and store it into variable
     {
          if(sensordata_1 == LOW)        //  CAGE 1
          {
            Serial.println("Arduino 1 s1: 1");  //
          }
          else
          {
            Serial.println("Arduino 1 s1: 0");
          }
          delay(200);

    }
}

void setup() {
 Serial.begin(9600);
 pinMode(8, INPUT); // first sensor input
 pinMode(7, INPUT); // second sensor input
 pinMode(6, INPUT); // third sensor input
 pinMode(5, INPUT); // fourth sensor input

}

void loop()
{

    int sensordata_1 = digitalRead(8); // read status and store it into variable
     {
          if(sensordata_1 == LOW)        //  CAGE 1
          {
            Serial.println("Arduino 2 s1: 1");  //
          }
          else
          {
            Serial.println("Arduino 2 s1: 0");
          }
          delay(200);

    }
}

import serial
import time

port = serial.Serial("/dev/rfcomm2", baudrate=9600)
port_2 = serial.Serial("
port.flush() # This wil flush any input and output buffer, so it will
#avoid receiving or sending bad data

while True:

    if(port.in_waiting > 0):
        data = port.readline().decode('utf-8').rstrip() # decode will translate
        #the data from unicode to byte
        print(data)


texts: Light multiple RGB Led Strips from same 3 RGB PWM outputs

texts:
I need to control about 6 RGB Led Strips from an Arduino Board. The problem is that i need 3 PWM outputs for each led strip, but each will have probably the same colors. I was wondering if i could put two strips receiving a signal from the same PWM output, then i would have to use half the PWM outputs but send the same signal for each pair of strips.
The scheme i found is this one:

And what i want is something like this:

Is this possible? What should i modify to make it work?
Thanks in advance.


texts:
I am using an Arduino Uno to communicate over SPI to 3 cascaded TLC5917 chips corresponding to the Red, Green and Blue rows of an RGB LED Matrix.
I am using direct output IO from the Arduino to power the columns.

Now I intend to use multiplexing to avoid drawing too much current at once, although it could still potentially be quite alot (3 x 8 x 20ma).

I have managed to display a full white screen using multiplexing with quite a high brightness, however this should not be possible to my knowledge.

Looking at the data sheet I found that at both at 3V and 5V the Output Voltage is rated at Vdd - 0.4 for Voh (Voltage High Level Output).
This means that at 5V the minimum output voltage should be 4.6V and at 3V it should be 2.6V.

Disabling multiplexing and simply writing to the registers and columns, and then measuring the voltage shows 2.5V, 2.8V and 1.8V for different colors.
This contradicts the data sheet.

The circuit contains no resistors except from GND to REXT using a 680Ohm Resistor.
The Arduino is powered over USB.

(http://www.ti.com/lit/ds/symlink/tlc5917.pdf)

Why is the Voltage so low, should it not be higher given the data sheet?
Am i reading the correct attribute?
How can my Arduino manage to drive so many LEDs (albeit through LED Drivers)?

What can I do to make this circuit more electronically safe and stable?


texts:
So, first of all I just want to point out this code is from: Reading Rotary Encoders and is not mine.

I have a magnetic shaft encoder mounted on a regular DC motor, my problem is that I cannot receive the exact angle of the motor. The encoder outputs +1 each 90 degrees (I then multiply by 90). And is there any relationship between valx, valy, valz and the angle?

#define encoder0PinA 2
#define encoder0PinB 3
int rounds= 0;
volatile unsigned int encoder0Pos = 0;
unsigned int tmp_Pos = 1;
unsigned int valx;
unsigned int valy;
unsigned int valz;

boolean A_set;
boolean B_set;

int enA = 9;
int in1 = 10;
int in2 = 11;

void setup() {

  pinMode(encoder0PinA, INPUT);
  pinMode(encoder0PinB, INPUT);
  // encoder pin on interrupt 0 (pin 2)
  attachInterrupt(0, doEncoderA, CHANGE);

  // encoder pin on interrupt 1 (pin 3)
  attachInterrupt(1, doEncoderB, CHANGE);
  Serial.begin( 9600 );

  pinMode(enA, OUTPUT);

  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(enA, 225);
  Serial.begin (9600);
}

void loop(){
//Check each second for change in position

  if (tmp_Pos != encoder0Pos) {
    Serial.print("Index:"); Serial.print(encoder0Pos * 90,DEC);
    Serial.println();
    Serial.print("valx:");Serial.print(valx,DEC);
    Serial.println();
    Serial.print("valy:");Serial.print(valy,DEC);
    Serial.println();
    Serial.print("valz:");Serial.print(valz,DEC);
    Serial.println();
    tmp_Pos = encoder0Pos;
  }
}

// Interrupt on A changing state
void doEncoderA(){

  // Low to High transition?
  if (digitalRead(encoder0PinA) == HIGH) {
    A_set = true;
    if (!B_set) {
      encoder0Pos = encoder0Pos + 1;
      valx=analogRead(0);
      valy=analogRead(1);
      valz=analogRead(2);
    }
  }

  // High-to-low transition?
  if (digitalRead(encoder0PinA) == LOW) {
    A_set = false;
  }
}

// Interrupt on B changing state
void doEncoderB(){

  // Low-to-high transition?
  if (digitalRead(encoder0PinB) == HIGH) {
    B_set = true;
    if (!A_set) {
      encoder0Pos = encoder0Pos - 1;
    }
  }

  // High-to-low transition?
  if (digitalRead(encoder0PinB) == LOW) {
    B_set = false;
  }
}


texts: My Ultrasonic sensor is only showing 4cm range?

texts:
I am using an ultrasonic sensor SR04 with Arduino Uno and a sample program which I got from the library. However, my output reading is only 4 cm even when there is no object in front of it. I even used another sample program which had the same output. Is the problem in sensor or library?

#define TRIGGER_PIN  12
#define ECHO_PIN     11
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  Serial.begin(115200);
}

void loop() {
  delay(50);
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm());
  Serial.println("cm");
}


texts:
I'm working on a demo program for which I want to use minimal resources: all I need is one LED and one pushbutton.

I'd very much like to use on-board resources. The user LED (PB27) is fine (I'd have liked one more, but there it is).

I read in the datasheet that the ERASE button can be used as an input (PC0) provided that I clear the SYSIO12 bit in the System I/O Configuration Register CCFG_SYSIO.

I find that if I do this I can push the ERASE button without erasing flash (!), but PC0 always reads as 0 (even if I enable pullup; ought to be already enabled, you'd think).

I should say that PC1 works just fine.

Has anyone else got ERASE => PC0 to work? is there documentation I've missed? (in ASF, some of the other boards in sam/applications/getting_started/ disable the ERASE button, but not this one).


texts: Using an Arduino for learning embedded C programming

texts:
I'm a computer systems engineering student and was planning to buy an Arduino to learn embedded C programming. After researching I found mention that an Arduino may not be a good choice for a beginner that wants to learn about programming embedded systems using C.

I'm not sure if that is true, can an Arduino be programmed in C without using C++ and the other included class libraries? I'd prefer to learn how to program things at a fairly low level and not rely on libraries that hide details of the underlying hardware. Can the Arduino be used as a general AVR / microcontroller development platform to learn embedded C programming?


texts: connecting SIM900A GSM/GPRS module Arduino Mega

texts: i have bought following SIM900A GSM/GPRS module. I need to connect it with Arduino Mega. Can anyone answer me which pin i need to connect to Arduino??


texts:
im planing to make my very own arduino design based on the Arduino PRO mini. I picked this board instead of the UNO mostly because it's way more simpler compared with the UNO since the USD-to-Serial part is missing.
As many of you know the MINI uses the 328P-AU which is the SMD version of the 328P however since the AU version is too small for me i would like to use the PU (UNO's chip) instead. From the datasheets the only difference is a small change in the pins position. And the one million dollar question is: Is there any difference on those 2 chips? If i try to use the same design just with the PU model is it gonna work?


texts:
I'm trying to get set up to develop for the Adafruit Trinket on a Mac running the OS X El Capitan beta (10.11.2 beta) with Xcode and embedXcode. I've got the Arduino IDE downloaded from arduino.cc installed as /Applications/ArduinoCC.app. I'm able to build and run the Blink example using the Arduino IDE and Xcode appears to also work (it knows about the Trinket, and claims to successfully load the code) but it does not blink. The red LED on pin 1 just continues to pulse at about 10 Hz as if it was waiting to for code to be loaded.

Any ideas what could be going on or how I can troubleshoot further?

Updates:

I've made the changes to avrdude.conf suggested by the folks at Adafruit to accommodate the erase timing requirements of the Trinket.
I got a response on the Adafruit forum that suggested going back to 1.6.5 as many people have been reporting problems with 1.6.6 breaking things. However, I can program the board using 1.6.6.


texts:
I needed a magnetometer with a high Output Data Rate (ODR). This is because I wanted to measure AC magnetic fields of around 20-80 Hz. So I decided to go with the MMC3416xPJ prototyping board which has an ODR of 800 Hz (https://au.mouser.com/new/memsic/memsic-mmc3416xpj-sensors/). I have never written an I2C interface for a sensor myself so I probably messed up. The datasheet for my sensor can be found here. I can get the product ID from the sensor correctly so that means the wiring is correct and some of the code is correct. But when I print out the measurements, they give me overflow values instead of the Earth's magnetic field. BTW I am developing this on Arduino board. Any help would be appreciated.
My code can be seen below -

Magnetometer.h

#ifndef MAGNETOMETER_H
#define MAGNETOMETER_H

#include "General.h"
#include <Wire.h>

#define MAGNETOMETER_I2C_ADDRESS 0x30
#define X_OUT_LOW 0x00
#define X_OUT_HIGH 0x01
#define Y_OUT_LOW 0x02
#define Y_OUT_HIGH 0x03
#define Z_OUT_LOW 0x04
#define Z_OUT_HIGH 0x05
#define STATUS 0x06
#define INTERNAL_CONTROL_0 0x07
#define INTERNAL_CONTROL_1 0x08
#define RO 0x1b
#define R1 0x1c
#define R2 0x1d
#define R3 0x1e
#define R4 0x1f
#define PRODUCT_ID 0x20

class Magnetometer
{
  public:
    Magnetometer();
    void Setup();
    void Test();
  private:
    void TestConnnection();
    void ReadRawData();
};

#endif

Magnetometer.cpp

#include "Magnetometer.h"

Magnetometer::Magnetometer()
{

}

void Magnetometer::Setup()
{
    Wire.begin(SDA, SCL);
    TestConnnection();

    Wire.beginTransmission(MAGNETOMETER_I2C_ADDRESS);
    Wire.write(INTERNAL_CONTROL_1);
    Wire.write(0x00);
    Wire.endTransmission();

    Serial.println("Magnetometer Setup");
}

void Magnetometer::Test()
{
    ReadRawData();
    Serial.println("Magnetometer Test");
    delay(1000);
}

void Magnetometer::ReadRawData()
{
    int16_t RawMx, RawMy, RawMz;
    byte status = -1;

    // 1-3
    Wire.beginTransmission(MAGNETOMETER_I2C_ADDRESS);
    Wire.write(INTERNAL_CONTROL_0);
    Wire.write(0x01);
    Wire.endTransmission();

    // 4-7
    Wire.beginTransmission(MAGNETOMETER_I2C_ADDRESS);
    Wire.write(STATUS);
    Wire.requestFrom(MAGNETOMETER_I2C_ADDRESS, 1);
    status = Wire.read();
    Serial.print("status = "); Serial.println(status);
    while ((status%2) != 1)
    {
        status = Wire.read();
        Serial.println("Data not ready");
    }
    Serial.println("Data ready");
    Wire.endTransmission();

    // 8-17
    Wire.beginTransmission(MAGNETOMETER_I2C_ADDRESS);
    Wire.write(X_OUT_LOW);
    Wire.endTransmission();
    Wire.requestFrom(MAGNETOMETER_I2C_ADDRESS, 6);
    RawMx = Wire.read();
    RawMx |= Wire.read()<<8;
    RawMy = Wire.read();
    RawMy |= Wire.read()<<8;
    RawMz = Wire.read();
    RawMz |= Wire.read()<<8;

    Serial.print("RawMx: "); Serial.print(RawMx);
    Serial.print(" RawMy: "); Serial.print(RawMy);
    Serial.print(" RawMz: "); Serial.println(RawMz);

    float scaleFactor = 2048;
    float convertToMircoTelsa = 100;
    float Mx, My, Mz;

    Mx = (float) RawMx / scaleFactor * convertToMircoTelsa;
    My = (float) RawMy / scaleFactor * convertToMircoTelsa;
    Mz = (float) RawMz / scaleFactor * convertToMircoTelsa;

    Serial.print("Mx: "); Serial.print(Mx);
    Serial.print(" My: "); Serial.print(My);
    Serial.print(" Mz: "); Serial.println(Mz);

    // Serial.print("Wire.ava = "); Serial.println(Wire.available());
}

void Magnetometer::TestConnnection()
{
    byte id = -1;
    while (id != 6)
    {
        Wire.beginTransmission(MAGNETOMETER_I2C_ADDRESS);
        Wire.write(PRODUCT_ID);
        Wire.requestFrom(MAGNETOMETER_I2C_ADDRESS, 1);
        id = Wire.read();
        Wire.endTransmission();

        if (id != -1)
        {
            Serial.println("Cannot connect to Magnetometer");
        }
    }
    Serial.println("Magnetometer TestConnnection Success");
}

If you guys suggest me any other magnetometers that have a high ODR (at least above 300 Hz), it would be really appreciated.


texts: Arduino Mega 2560 SoftwareSerial Not Working

texts:
We have an xBee Pro S2C that is using this library (https://github.com/andrewrapp/xbee-arduino) very well on a Software Serial connection to ports 2 and 3 on an Arduino Uno. However, when we take the same setup and try it on a Arduino Mega 2560 using any of the ports specified here:

*

https://www.arduino.cc/en/Reference/SoftwareSerial

  Not all pins on the Mega and Mega 2560 support change interrupts, so
  only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51,
  52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14
  (68), A15 (69).

*

We cannot get this setup to work on the Arduino Mega 2560. We did not try every combination of these ports but tried most of them and it continues to fail. We can get successful packets on an Uno on pins 2 and 3.

Code is as follows:

#include "Arduino.h"
#include "laser_essentials.h"
#include "XBee.h"
#include <SoftwareSerial.h>
#define IS_STAR 1
#if IS_STAR

#define rxPin 10 //input
#define txPin 11 //output
#else
#define rxPin 2 //input
#define txPin 3 //output
#endif
#include "SoftReset.h"

///setup xbee object

XBee xbee = XBee();
SoftwareSerial xBeeSerial = SoftwareSerial(rxPin, txPin);

//Setting up class & contructors

Laser::Laser () {

        pinMode(rxPin, INPUT);
        pinMode(txPin, OUTPUT);
        xBeeSerial.begin(9600);
        xbee.setSerial(xBeeSerial);
        Serial.begin(9600);

Any thoughts as to why this might not work on a Arduino Mega?


texts:
I made a wireless keyboard, but I just need 4 button for my project: left control, left shift, F1, F2.
The problem: When I hold button - it acts like many key presses and releases, but I need, that when I press & hold button - it also acts like I press & hold it.
Could you please help me?
Here is source code:
Transfer_e5.ino:  https://www.paste.org/108039
Receiver_e5.ino:  https://www.paste.org/108040
Or 1 rar package:
https://easyupload.io/o3c5sp
Thank you
Or I can put them just here, if you wish.
Receiver:
#include <Keyboard.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(8,7); // (ce,cs)
RF24Network network(radio);

const uint16_t this_node = 00;
const uint16_t other_node = 03;

unsigned int laser_state=0;
const unsigned long my_interval = 500;
unsigned long last_sent;
unsigned int income=0;

void setup(void)
{
  Serial.begin(115200);
  pinMode(9,INPUT_PULLUP);

  SPI.begin();
  radio.begin();
  network.begin(90,this_node);

  pinMode(4,OUTPUT);
  digitalWrite(4,LOW);
}

void loop(void){
  digitalWrite(4,LOW);
  network.update();

  if ( network.available() ) {
    RF24NetworkHeader header;
    network.read(header,&income,sizeof(income));

    if(income==10){
      Serial.println("f1");
      Keyboard.press(KEY_F1);
      income=0;
    }

    if(income==11){
      Serial.println("f2");
      Keyboard.press(KEY_F2);
      income=0;
    }

    if(income==12){
      Serial.println("ctrl");
      Keyboard.press(KEY_LEFT_CTRL);
      income=0;
    }

    if(income==13){
      Serial.println("shift");
      Keyboard.press(KEY_LEFT_SHIFT);
      income=0;
    }

    Keyboard.releaseAll();
  }

  unsigned long now = millis();

  if ( now - last_sent >= my_interval  )
  {
//    Serial.print("pin ");
//    Serial.println(digitalRead(9));
    last_sent = now;
    laser_state = digitalRead(9);

    RF24NetworkHeader header(other_node);
    bool ok = network.write(header,&laser_state,sizeof(laser_state));
  }
}

Transfer
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(8,7);
RF24Network network(radio);

const uint16_t this_node = 03;
const uint16_t other_node = 00;

unsigned int laser_state=0;
const unsigned long interval = 5;
unsigned long last_sent;

unsigned int b1=1;
unsigned int b2=1;
unsigned int b3=1;
unsigned int b4=1;

unsigned int d1=10;
unsigned int d2=11;
unsigned int d3=12;
unsigned int d4=13;

//TR1
int btn1 = 3;
int btn2 = 4;
int btn3 = 5;
int btn4 = 6;

void setup(void)
{
//  Serial.begin(9600);
  pinMode(btn1,INPUT_PULLUP);
  pinMode(btn2,INPUT_PULLUP);
  pinMode(btn3,INPUT_PULLUP);
  pinMode(btn4,INPUT_PULLUP);

  SPI.begin();
  radio.begin();
  network.begin(90,this_node);
}

void loop(void){
  network.update();

  unsigned long now = millis();

  if ( now - last_sent >= interval  )
  {
    last_sent = now;

    b1 = digitalRead(btn1);
    b2 = digitalRead(btn2);
    b3 = digitalRead(btn3);
    b4 = digitalRead(btn4);

    if(b1==0){
//      Serial.println("F1");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d1,sizeof(d1));
    }

    if(b2==0){
//      Serial.println("F2");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d2,sizeof(d2));
    }

     if(b3==0){
//      Serial.println("Ctrl");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d3,sizeof(d3));
    }

    if(b4==0){
//      Serial.println("Shift");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d4,sizeof(d4));
    }
  }
}


texts:
I am new and lost. I have been searching the internet about how to transfer data of multiple sensors from one Arduino to another using I2C but no luck. All the codes and tutorials online focus on multiple slaves with one sensor.
The attached Fritzing is not my project, but my project involves 22 pressure sensors and I need to log their readings in Excel using plx, so the picture is just for demonstrating the idea.
The main idea is to transfer the sensors' data from the slave to the master over I2C.
I just need an answer if this doable or not plz


texts:
I'm trying to read a microSD block. But I don't know why it doesn't work.

I do:

CS_UP;
for(uint8_t i = 0; i <14; i++){ /* Send 74+ clocks */
    spi_tranceiver(0xff);
}
_delay_ms(1); /* Wait 1 ms */

//CS_UP;

/* Initizalize microSD */
put_string("Go to idle state\n");
while (Reset_Card() != 0x01) // Go to idle state
    ;

put_string("Send IF COND\n");
while (Send_CMD8() != 0x01) // SEND IF COND
    ;

put_string("Send ACMD41 and CMD55\n");
for (int i = 0; i<100; i++)
    while (Send_CMD55() && Send_ACMD41())
        ;

setBlockLen(); // Set block read in 512 bytes
CS_DOWN;
put_string("\nConfigure finished correctly\n");

And then I just call:

readSingleBlock(0x00, &buf)

readSingleBlock is defined as follows:

uint8_t readSingleBlock(uint32_t block_address, unsigned char *buf)
{
    int i;

    block_address = block_address << 9;

    CS_UP;
    while (0x00 != sdsc_command(READ_SINGLE_BLOCK, block_address))
        ;

    while (0xfe != spi_rx ())
        ;

    for (i = 0; i < 512; i ++ ){
        //buf [ i ] = spi_rx();
        put_int(spi_rx());
        put_string("\n");
    }
    spi_rx();
    spi_rx();
    CS_DOWN;

    //for (i = 0; i<512; i++) put_int(buf[i]);

The problem is that the printout is:

0 0 0 ..(zeros).. 128 255 255 255 12 255 255 255 0 8 0 0 0 72 59 ..(zeros).. 85 170

Did somebody encounter this problem?

Do you have some suggestions?


texts: How to power Nodemcu using 12 volt AC to DC adapter?

texts: I am trying to make a small project using Nodemcu. My project is WiFi controlled LED, 2 LED's will blink at the same time. I have successfully uploaded the code and it works fine using USB connection. But I want to power the Nodemcu using 12 volts 1.5 amps AC to DC adapter. I have checked it in web search but I have not found an understanding circuit. please help me out guys.


texts:
I use for a project an Arduino Yun with Node.JS + socket.io to provide interactivity between a smartphone, driving through a webpage different devices.

I would like to enable this service for several smartphones at the same time. However I would like to work in the very same conditions that a (well configured) hotspot does:

I want to ensure that no user can see the other users on the network,
I want to have a limited number of connections on the Yun at the same time,
I want to force the different users when connected to the Wi-Fi to be routed to a captive portal on the first connection.

Does anyone know first if it is possible with an Arduino Yun (maybe some actions must be performed on a NodeJS virtual server as point 2). If yes, do you have a tutorial or any clues (do I have to use LuCi)?

Last question, in the same topic, I would like to use a fast granted access using NFC tag emulation to provide Wi-Fi credentials. Has anyone tried this with Arduino Yun and a shield?


texts: What requirements should components have to work with Arduino (UNO in particular)

texts:
I am fairly new to the whole concept of Arduino and electronic engineering in general.

Recently I bought myself an Arduino UNO and I'm wondering what "non off the shelf" components will work when I hook them up with the UNO. I have a lot  of old electronic stuff laying around containing pushbuttons, sliders, faders, knobs etc. wich if possible, I'd like to take apart to connect them to the UNO for some fun fuzzin' around.

Many thanks in advance!

PS: this is my fist post ever on stackexchange so excuse me if the question is placed incorrectly or the tags are weird. Please DO correct me where I'm wrong.


texts: read state from button to check if clicked

texts:
I"m kinda new here and new to the arduino framework.

I want to build a "menu" using LCD 20*4, so I want to detect "button clicked" event.

I've connected button to pin 8 and to ground, like this(please ignore the other wiring):

int leftButton = 8;

void setup() {
  pinMode(leftButton, INPUT);
  digitalWrite(leftButton, HIGH);
  Serial.begin(9600);

}
bool leftButtonClicked(){
  return digitalRead(leftButton);
}
void loop(){
  delay(20);
  Serial.println(digitalRead(leftButton));
}

I am receiveing on the serial 1 while the button is not clicked, and when its clicked I receive 0.

What is the problem? Thank you guys.


texts: Can burn bootloader but not sketches... thoroughly mystified!

texts: I have a custom board designed to be essentially identical to the Arduino Micro (Atmega32u4). I can burn the bootloader (Caterina) and it burns just fine, including the fade-then-slow LED signal that indicates a successful bootloader burn. However, it does not turn up under USB. What am I doing wrong?


texts: How to call an interrupt when any one of the 12 defined digital inputs go high?

texts:
I'm using an Arduino Mega 2560 board. I need to sense 12 digital pins (pins 36-47) coming from another board continuously and display power when they are low.

When any of the 12 pins go HIGH, an interrupt must be created. In the ISR part, I'll be making one new digital pin (PIN 35) go HIGH (this is initialized as low in setup function).

To reset from interrupt, I need to press the "#" key in the keypad. This should make PIN 35 go low again and program should function normally again.

This is my code without using Interrupt.

#include "LiquidCrystal.h"
#include <Keypad.h>

// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);
 const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34};     //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
float fwd_voltage = 0.0,rev_voltage = 0.0;
float fpower,rpower;
int sensorValue=0;

void setup() {
  int i;
  for (i=36;i<48;i++) {
    pinMode(i,INPUT);
  }
  pinMode (35, OUTPUT);
  digitalWrite(35,LOW);
}

void reset () {
  while(1) {
    lcd.begin(16,2);
    lcd.setCursor(0,0);
    lcd.print("press # to reset");
    char key = keypad.getKey();
    if (key=='#') {
      digitalWrite(35, LOW);
      break;
    }
  }
}

void process(int pin, char* text) {
  if (digitalRead(pin) == HIGH && digitalRead(35)==LOW) {
    // Use HIGH instead of 1
    lcd.print(text);
    digitalWrite(35, HIGH);
    reset ();
  } else {
    int analog_value = analogRead(A0);//reading forward voltage
    int analog_valuer = analogRead(A1);//reading reverse voltage
    fwd_voltage = (analog_value * 5.0) / 1024.0;
    rev_voltage = (analog_valuer * 5.0) / 1024.0;
    fpower =  ((fwd_voltage)*(fwd_voltage)*10000);
    rpower = ((rev_voltage)*(rev_voltage)*10000);
    lcd.setCursor(0,1);
    lcd.print("REV= ");
    lcd.print(rpower);
    lcd.print("W");
    delay(500);
    lcd.setCursor(0, 0);
    lcd.print("FWD= ");
    lcd.print(fpower);
    lcd.print("W");
    delay(500);
  }
}

void loop() {
  lcd.begin(16,2);
  // set cursor position to start of first line on the LCD
  lcd.setCursor(0,0);
  process(36, "vswr");
  process(37, "thermal");
  process(38, "overdrive");
  process(39, "A1-B1 fault");
  process(40, "A1-B2 fault");
  process(41, "A1-B3 fault");
  process(42, "A1-B4 fault");
  process(43, "A2-B1 fault");
  process(44, "A2-B2 fault");
  process(45, "A2-B3 fault");
  process(46, "A2-B4 fault");
  process(47, "driver fault");
}

How do I modify the program to add an interrupt so that my board works faster and efficiently? BTW I'm new to programming so there might be some mistakes in the program and also I didn't write the program small and efficient.

The interrupt service routine should consist of this part of the above program:

lcd.print(text);
digitalWrite(35, HIGH);
reset ();

My interrupt should detect this part of the program.

if (digitalRead(pin) == HIGH && digitalRead(35)==LOW)


texts:
I am planning on making a simple stopwatch with:

A display
One or two additional buttons to start the stopwatch and stop the stopwatch and
maybe reset it.

The problem is that it has to be as small as possible.
With all those different Arduino boards out there, I don't know which one I should buy (mini, micro, nano, ...).

I am not sure how many pins I need for the LCD since I have read that in fact not all pins are mandatory for the LCD. I have done something earlier with an LCD and I found the pot meter for the LCD contrast level a bit of waste of space. Could I just replace it with a certain resistor or something?

How many pins in the end would I need and which board would be fitting for this little project?


texts: Arduino Disconnects after router password changes

texts: I am working with arduino Uno R3 connected with EPS8266(http://www.amazon.in/ESP8266-Serial-Wireless-Transceiver-Module/dp/B00O34AGSU?tag=googinhydr18418-21&tag=googinkenshoo-21&ascsubtag=858e5035-7713-403a-942e-487a0fe24800). After router password is changed, it should be re programmed with new password. Is there any another way not to do so repeatedly. I managed 2 SSID for router which one have always unique password. But I think this is not a solution. Is there any technique or idea that says only for particular mac address, the SSID will be opened.


texts: Serial read multiple digits and always reading 10 at the end?

texts:
So I'm trying to make a program that allows you to enter a number in decimal and it displays it in binary, and it's going fairly well after some initial struggles (for some reason it read integers as 48 more than they are (5 read as 53)) but there's something I still don't understand, and I'm scared that it may be a hardware issue.

For some reason, I can't display two-digit numbers. For example, if I input 12, it displays 1, and THEN it displays 2. Also, to make things worse, it ALWAYS outputs 10 after I input ANY number. For example, if I input 5, it displays 5, and then ALWAYS 10.

    void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int number;
  if (Serial.available() > 0) {

    number = Serial.read();
    Serial.print("Number to display: ");
    Serial.println(number);

    if (number <= 15){
      int LEDPin = 2;
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
        for (int n = 0; n <= 4; n++){
          int binval = bitRead(number, n);
          Serial.println(binval);
          digitalWrite(LEDPin, binval);
          LEDPin++;
      }
    }
    else{
    Serial.println("Number must be less than 16!");
    }

    delay(1000);
  }
}

EDIT: And of course, after asking the question I re-ran the code and its AGAIN showing ints as 48 bigger than they are (5 as 53).

At this point, I'm extremely confused. Am I doing something wrong? Is this a hardware issue? What can I do?


texts: Control Current / Connecting a Relay - Simple question

texts:
I'm trying to control the input of something that needs a 3v coin cell.  How would I output the same voltage, or how would I use a relay to control the current.  I basically want to be able to turn something on and off that needs a 3v coin cell, so I'm just wanting to be able to toggle the power by connecting/disconnecting the battery.  I'm very new to electronics, so could you please give a simple schematic or code if it's code-wise, this is for a science fair project.  Thank you!

I'm attempting to power an Estimote Bluetooth Beacon.  I cannot find a datasheet on it, so I'm not sure what current it requires, just that it requires a 3v coin cell battery.

I'm using an Arduino Uno powered by a 9v battery.

The coin cell is a CR2477 (datasheet: http://lib.store.yahoo.net/lib/theshorelinemarket/SONY-CR2477.pdf)


texts: Where in datasheet is the warning about unreliability of reading PINxn?

texts:
I use atmega32u4 (but believe it applies to all models). Here is the datasheet.

Consider the following C program (I use AVR-GCC 5.4.0):

#include <avr/io.h>
int main(void)
{
  PORTB |= 1 << PB5; /* pullup */
  DDRB |= 1 << PB0; /* LED */
  if (!(PINB & 1 << PB5))
    PORTB |= 1 << PB0; /* turn on LED */
  while (1) ;
}

There are two situations:

connect a 10cm wire to PB5 pin (the other end of the wire is in the air): the result is that sometimes after poweron the led is on, sometimes the led is not on.
do not connect anything to PB5 pin: the result is that after poweron led is never on.

I have a standard setup. Nothing tricky. If it does not work reliably, this gotcha MUST be documented in datasheet. This setup is supposed to deal with a stupid button. But sometimes it detects a keypress while there is no keypress.

The question is: where in datasheet there is a warning about this gotcha?
And did somebody come across such case, or I'm the first in the world?

EDIT See also this question.


texts:
I am trying to build a Smarthome system with NodeMCU.
NodeMCU would wire up with relays.
How many replays can one NodeMCU control?


texts:
I was trying to build a system that when the user pushes the button, the servo rotates 45 degrees and than returns back to zero. This system is going to be duplicated as there will be two servos and pushbuttons.

Here's my code:

#include <Servo.h>
Servo solservo;  // create servo object to control a servo
Servo sagservo;
// twelve servo objects can be created on most boards

int possol = 0;    // variable to store the servo position
int possag = 0;
int degsol=0;
int degsag=0;

int ledPin = 13; // choose the pin for the LED
int solPin = 7;   // Pushbutton
int sagPin = 8;     // variable for reading the pin status
int valsag = 0;
int valsol = 0;

void setup() {
  solservo.attach(9);  // attaches the servo on pin 9 to the servo object
  sagservo.attach(10);
  pinMode(solPin, INPUT);
  pinMode(sagPin, INPUT);
  pinMode(ledPin, OUTPUT);

}

void loop() {
  digitalWrite(ledPin, HIGH);    //Arka İsik
  valsag = digitalRead(sagPin);  // read input value
  valsol = digitalRead(solPin);
//Sag Servo

  if (valsag == HIGH) {
    sagservo.write(45);              // tell servo to go to position in variable 'pos'
    delay(100);                       // waits 15ms for the servo to reach the position
    sagservo.write(-45);

  }
//Sol Servo
  if (valsol == HIGH){
    solservo.write(45);
    delay(15);
    solservo.write(0);
  }

}

There'll probably be lots of small errors in this code, like unnecessary ints and such, but when I upload this program and push the button, it just rotates 45 deg, and doesn't come back. Is there a way that I can solve it?

Thanks in advance


texts: Arduino Uno with SD, Cardinfo sketch how to list only visible files

texts:
There are two files (that can be seen on my computer) on my sd card, 6.bmp and example.txt (the latter written from my arduino). I have them connected to my arduino via LCSTUDIO breakout board (which surprisingly caused me no trouble at all).

When I run the example "cardinfo" sketch, the files it lists includes those two files along with tons of others, which I assume are just invisible from a personal computer.

How would I list only the files that can be seen from my computer (i.e. aren't inside any directory, but are just plain in the SD card)?

Using arduino UNO


texts: How long does my digital pulse need to be for it to be read?

texts:
I have the following really simple code. On every iteration it'll read the first pin, and if it's high - do some serial IO. Then do the same with the second pin. Nice and simple, works during my tests.

My concern is that (in production), the digital pulse I'm receiving (and trying to mimic during testing) would be too quick for the arduino to read. So, for example, the race condition could be:

First pin is low Read first pin - result is low.
First pin is now high Read second pin - result is low.
Fist pin now low again Read first pin - result is low again (missed the 'high')

How much of an 'edge case' is this? Am I worrying about something that's likely to be a non-issue here? In production, each single pulse would represent a significant amount of product (I multiply it elsewhere) - so even skipping one could throw my data off.

boolean count1High = false;
boolean count2High = false;
int count1 = 7;
int count2 = 8;
int a = 1;
void setup() {
  pinMode(count1, INPUT);
  pinMode(count2, INPUT);
  Serial.begin(9600);
}

void loop()
{
  if (digitalRead(count1) == HIGH)
  {
    if (!count1High)
    {
      count1High = true;
      a++;
      Serial.println(a);
    }
  }
  else
  {
    count1High = false;
  }

  if (digitalRead(count2) == HIGH)
  {
    if (!count2High)
    {
      count2High = true;
      a++;
      Serial.println(a);
    }
  }
  else
  {
    count2High = false;
  }
}

EDIT:

I know best approach here might be to attach an interrupt but I've been advised to avoid serial IO from within interrupts, I don't see an alternative here.


texts: i2c code hanging - tried all connections

texts:
I'm trying to connect a TCA9548a breakout to my nano (also tried using an uno), but it can't recognise it - using the i2c scanner it just hangs on 'scanning...'

I've tried everything suggested in similar posts - checking connections, adding/not adding pullups (this nano I think already has them) and checking other i2c devices using same setup (which work fine). If I connect another i2c device, without the TCA, and have the i2c scanner working well and finding it, then connect SCL from the TCA (whether or not SDA is also connected) the scanner hangs.

When I was checking connections with the tca connected, it did work just once, finding it. Haven't been able to repeat that though since, I can't remember exactly what I was doing at the time.

Any help please?

Thanks in advance

i2c scanner:

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(115200);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(1000);           // wait 5 seconds for next scan
}

tca9548a scanner:

#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

#define TCAADDR 0x74

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}

// standard Arduino setup()
void setup()
{
    while (!Serial);
    delay(1000);

    Wire.begin();

    Serial.begin(115200);
    Serial.println("\nTCAScanner ready!");

    for (uint8_t t=0; t<8; t++) {
      Serial.println("selecting");
      tcaselect(t);
      Serial.println("selected");
      Serial.print("TCA Port #"); Serial.println(t);

      for (uint8_t addr = 0; addr<=127; addr++) {
        if (addr == TCAADDR) continue;

        uint8_t data;
        if (! twi_writeTo(addr, &data, 0, 1, 1)) {
           Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
        }
      }
    }
    Serial.println("\ndone");
}

void loop()
{
}


texts: Using an ultrasonic sensor to act as a potentiometer for a Servo?

texts:
I would just like to start off by saying that I am new to Arduino so my code and approach to the wanted outcome are probably not the best. Anyway, I had the idea of using an ultrasonic sensor and my hand to act as a potentiometer to control the position of a servo. So, I wired everything up and wrote the code but the Servo just jitters around and doesn't move the way I wanted it to. The serial readings are fine, it is just that the servo isn't responding the way I hoped. Here is the code

#include <Servo\Servo.h>
#define echoPin 7
#define trigPin 8

int maximumRange = 400;
int minimumRange = 0;
int angle;
long duration, distance;
Servo myServo;

void setup()
{
    Serial.begin(9600);
    pinMode(echoPin, INPUT);
    pinMode(trigPin, OUTPUT);
    myServo.attach(9);
}

void loop()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);

    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);

    distance = duration / 58.2;

    angle = map(distance, minimumRange, maximumRange, 0, 179);
    Serial.print("Distance = ");
    Serial.print(distance);
    Serial.print(" Angle = ");
    Serial.println(angle);
    myServo.write(angle);
    delay(50);
}

If anyone can help, it would be appreciated if you could post what is wrong with my code and how to fix it.

Note: I'm using Visual Studio instead of the Arduino IDE, so that is why it says #include <Servo\Servo.h> at the top.


texts: Correct way of having loop end when required?

texts:
I'm brand new to Arduinos. I'm currently trying to modify a script from here which at the moment, simply turns an LED on or off depending on which HTTP GET request it receives. However, I want to modify this to have the LED modulate on/off when presented with the On HTTP GET request and then simply turn off all together when presented with the Off HTTP GET request. However, I have two conflicting methods that I have found about how to achieve this; the first is:

int value = LOW;
    if (request.indexOf("/LED=ON") != -1)  {
      value = HIGH;
      do
      {
      digitalWrite(ledPin, HIGH);
      delay(3000);
      digitalWrite(ledPin, LOW);
      delay(5000);
      value = HIGH;
      } while (value = HIGH);
    }
    if (request.indexOf("/LED=OFF") != -1)  {
      digitalWrite(ledPin, LOW);
      value = LOW;
    }

Wheareas the other is:

  int value = LOW;
    if (request.indexOf("/LED=ON") != -1)  {
      value = HIGH;
      void loop() {
      digitalWrite(ledPin, HIGH);
      delay(3000);
      digitalWrite(ledPin, LOW);
      delay(5000);
      value = HIGH;
      }
    }
    if (request.indexOf("/LED=OFF") != -1)  {
      digitalWrite(ledPin, LOW);
      value = LOW;
    }

As you can see, the first uses do...while and the second uses loop(). I have a feeling that the first of the two scripts would be more suitable as it should cut out as soon as value is set to LOW (i.e. when requested to turn off)

However, I would really appreciate it if someone could look through the two scripts and tell me which of the two is the correct way to achieve this sort of cut off when the HTTP GET Off is requested (if either for them even is the correct way to do this!).

Thank you in advance for your help,

Kind regards,
Tom


texts: Phase and frequency correct PWM mode Arduino Mega 2560

texts:
I wrote a code to generate 1kHz Phase and frequency correct PWM signal from Arduino mega 2560 using timer 4. When I try the code with fast PWM mode it works perfectly. But phase correct mode didn't provide the expected outcome. What is wrong with my code?

unsigned int b=7999;
void setup() {
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);

TCCR4A=0;
TCCR4B=0;
//Timer 1 1kHz mode 8: phase and frequency correct pwm oc1a non inverting

TCCR4A=(1<<COM4A1)|(0<<COM4A0)|(0<<WGM41) ;//| (0<<WGM40)
TCCR4B=(1<<WGM43)|(0<<WGM42);//
ICR4=b;
OCR4A=int(b*1/5);
TCCR4B|=(1<<CS10);
TIMSK4 |=(1<<OCIE4A);
}

void loop() {
  }

ISR(TIMER_COMPA_vect){

  }

The output of the code for different duty cycles are as below
Duty cycle:0.2 (OCR4A=b/5)

Duty cycle:0.2 (OCR4A=b/2)


texts: Hardware logic gates for a simple demo with LEDs

texts:
I need some logic gates for a simple demo like this one. I will use a regular breadboard and an Arduino UNO as a 5 V and GND supply.

I found these ICs from Texas Instruments SN74LSxxN (NOT, AND, OR, NAND, NOR, XOR). For my demo I only need two inputs (well obviously only one on NOT) and one output on each chip. I want to connect the output to a LED via resistor to demonstrate that for example 1 XOR 1 equals 0 (LED off), or NOT 0 equals 1 (LED on):

My LSs seem to work as expected without an LED connected:

int value;

void setup() {
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 Serial.begin(1200);
}

void loop() {
 digitalWrite(10, LOW);
 digitalWrite(11, LOW);
 value = digitalRead(5);
 Serial.println(value);
}

…but it would be great to make an LED demo too.

These ICs are probably a better choice in my case?

SN74ACT04N (NOT)
SN74ACT08N (AND)
SN74ACT32N (OR)
SN74ACT00N (NAND)
CD74ACT02 (NOR)
SN74ACT86N (XOR)

For everyone who isn't happy with Arduino as power supply here an alternative circuit with the same question - which IC family should I use?

Update: Well, probably I should better use something like LogicBlocks for my demo.
There is no NOR, XOR or NAND in this set, but it should be much easier to handle.


texts: Basic WiFly server returning unexpected output within web client

texts:
Currently trying to implement a lightweight webserver using the WiFly shield and an Arduino UNO, this is the code I have so far:

#include <SPI.h>
#include <WiFly.h>
WiFlyServer server(80);

/* Function defs */
void cmd(void)  { SpiSerial.print("$$$"); }
void dhcp(void) { SpiSerial.println("SET IP DHCP 0"); }
void pass(void) { SpiSerial.println("SET WLAN PHRASE 22222222"); }
void ssid(void) { SpiSerial.println("JOIN BTHOMEHUB"); }
void port(void) { SpiSerial.println("SET IP LOCAL 80"); }
void ip(void)   { SpiSerial.println("SET IP ADDRESS 192.168.1.123"); }
void tcp(void)  { SpiSerial.println("SET IP PROTOCOL 2"); }
void boot(void) { SpiSerial.println("REBOOT"); }

/* Pointer to a handler function */
typedef void (*Handler)(void);
Handler table[8] = { cmd, dhcp, pass, ssid, port, ip, tcp, boot };

void setup() {
  server.begin();
  Serial.begin(9600);
  SpiSerial.begin();

  for(short x = 0; x < 7; x++) {
    table[x]();
    delay(100);
  }
}

void loop() {
  WiFlyClient client = server.available();

  if(client){
    while(client.connected()) {
      if(client.available()) {
        client.println("
Hi

This is text.
");
      }
    }
    delay(100);
    client.flush();
    client.stop();
  }
}

This compiles well, but when hitting 192.168.1.123 in my web browser I get an ever-increasing output like:

*HELLO*<
<
<
<
<
<
<
<
<
<
<
< (cont.)

Definitely not the expected html. I have been playing with this code for hours now and this is the most positive output I can get. If I do a Serial.write(client.read()) within if(client.available()) { I am able to print all the request information to the serial monitor, it just seems I am perhaps sending the data in an incorrect format? Any suggestions? Cheers

Edit

I have updated the codebase to include the http headers,

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("");
client.println("<!DOCTYPE html>");
client.println("
Hi.....

now I get I different (similar) output, seems like it is printing the first character of each new line

*HELLO*H
C
C

<
<
H
C
C


texts: Any way to use F macro with a passed variable?

texts:
I want to know if it's possible to use the F() macro on text that is being passed to a function.

This is an example function:

void displayMenu(const char * txt, byte &var) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(txt);
  lcd.setCursor(0, 1);
  lcd.print(var);
}

This is how I'm calling the function:

displayMenu("Backlight:", backlight);

If I didn't separate the repeating code into a separate function, I would've been able to write it out like this:

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Backlight: "));
lcd.setCursor(0, 1);
lcd.print(var);

If I try to do:

displayMenu(F("Backlight"), backlight);

it doesn't work. Also if I try to do this in the function:

lcd.print(F(txt));

that also doesn't work.

I'm just wondering if such a thing is possible.


texts: avrdude: stk500_recv(): programmer is not responding Arduino LCD_I2C Upload problem ( port not found and ...)

texts:
i have problem to upload the LCD I2c Example program to Arduino UNo. the code are shown below:
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}

void loop()
{
}

the schematic is like the below photo:

but i get this error:
Sketch uses 3382 bytes (10%) of program storage space. Maximum is 32256 bytes.
Global variables use 327 bytes (15%) of dynamic memory, leaving 1721 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Thank.


texts: Recognition of the signal duration from the sensor

texts:
Good afternoon!
I create a human movement alarm.
I am signaling atmega328. I receive a signal from the sensor and if there is a signal, then using the "tone" I generate a sound.

I am using a motion sensor. I want that if one movement was noticed for a short time, then turn on a short melody, and if the movement continues longer than a certain time, then play a long melody.
I wrote the code to play a short melody. How can you track that the input from the sensor is at a high logical level for a long time and play a long melody in this case?
unsigned long timing; // Variable to store the starting point
int T = 15; // Signal playback time!
int S0 = PIND0; // With Doppler Probe

int S1 = PIND1; // Food
int S2 = PIND2; // Audio

void setup ()
{

  // Port control via registers:
  DDRD = B00000110; // Set the output pin (the first and second pins of register D as output pins, the rest (0.3-7) are set as input pins)
  // 76543210
  pinMode (PIND0, INPUT);
  pinMode (PIND1, OUTPUT); // Power for the audio amplifier
  pinMode (PIND2, OUTPUT); // Audio
}
void loop ()
{
  if (digitalRead (PIND0))
  {
    sendSignal ();
  }

  if (digitalRead (PIND0) == 0)
  {
    digitalWrite (PIND1, LOW); // Food
    digitalWrite (PIND2, LOW); // Sound
  }
}

void sendSignal ()
{
  digitalWrite (PIND1, HIGH); // Food
  for (int n = 0; n <4; n ++)
  {
    for (int i = 4800; i <5800; i ++)
    {
      tone (PIND2, i, 10); // tone (port, frequency in Hz, duration in ms) 600 - 6 sec.
    }
  }
}

And yes, if my code can be optimized, tell me how!


texts: Flashing a ATmega328 that came from an Arduino to not use an external oscillator

texts:
I have a ATmega328p chip from a kit that was supposed to be an Arduino compatible thing. I decided to go beyond Arduino and try to program the chip directly. I setup an UNO as an Arduino ISP, more or less like the image here, but added some LEDs to pins 8, 9 and 10 for feedback.

This image has this caption.

  Because no external clock source is connected, the ATmega must be configured to use its internal clock.

I think this chip was flashed with whatever tells it to use an external oscillator. And I do not have an external oscillator.

So how can I tell the chip to again use an internal oscillator when using an UNO as my programmer?

» avrdude -p m328p -c avrisp -b 19200 -P /dev/cu.usbmodem1d11121

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

I assume a device id of zero means the chip is not responding with data? because it's core is not cycling?

Do I need an oscillator installed just so I can wake it it up and tell it to not use an oscillator?


texts: AMIS30543 | Data-Sheet understanding Status register

texts:
I was reading the data Sheet of AMIS-30543 stepper motor driver and I was not able to understand how to combine the result of the Micro step position status register MSP[8:0]. I know that its a 9 bit value . Help me understand how to get the value.
In the data sheet it is given like

in SR3 -> MSP[8:2], and in SR4 -> MSP[6:0]. How I am I suppose to get the 9 bit out of these.

In the library I have seen that , (sr3<<2) | (sr4 & 3)  . I don't understand why they are doing and & here.
Please explain . also If there was no library how am I suppose to know how to combine these registers from the dataSheet .
Link to DataSheet


texts: What options do I have to get 5v on my current project?

texts:
I'm very new to arduino and have started work on my first project, a simple little web server. I'm using a NodeMCU with an sd card module and screen. The issue is that in order to power my sd card module, I need to input 5V which the MCU doesn't provide.

In order to work around this I'm simply using an arduino nano as a power supply to pass into the vin input on the mcu.

What options do I have to exclude the need for the nano? Is there a simple module I can buy that acts as a power supply for 5v?

Any help would be great, thanks!


texts: Possible to store variables directly in EEPROM?

texts:
Is it possible to store a variable directly in EEPROM and retrieve it without needing to use a library?

I'm building a project that can change the colour of an RGB LED and I want to store the colour in a non-volatile memory space, but I was wondering if I could avoid using one of the EEPROM libraries and have a global variable stored in nonvolatile memory, but still accessed directly, without needing to call a function.


texts:
Convert text array/buffer to integer and string.

hi! i'm sending text to an arduino and the output of that library is a
uint8_t array.

Atm the text send is a number between "0" and "1023"

void something(uint8_t * text){
 analogWrite(13,text);// does not work
}
/*
toInt() also not
int() not
atoi() not
invalid conversion from 'uint8_t* {aka unasigned char*}' to 'const char*'
*/

i need to convert it to an  integer or better to a uint16_t.

As i plan to send custom commands in near future it would also be good to know how to convert that array to a string, that i then split/manipulate/parse.. whatever.

i looked in various posts but i couldn't get it to work on that simple example above. i'm new to c++

if it's needed the length is also aviable inside the function.


texts:
Functionality

I have written this code below for a buggy to continue moving forward until there is an obstacle which is <= 25cm both motors should stop.

Result

both motors stop when there is an obstacle which is <=25cm but the motors happen not to stop immediately when it comes across the obstacle please do find my code below is there something wrong with my code and how can I make it much better.

Code

#define PING_PIN  12  // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor.
#define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

//initializing left DC Motor
const int in_1 = 2; // initializing the IN1 to Pin 2
const int in_2 = 3; //initializing the IN2 to Pin 3
const int EnA = 4;  //initializing pin 4 as pwm

////initializing Right DC Motor
const int in_3 =5;  // initializing the IN3 to Pin 5
const int in_4 = 6; // initializing the IN4 to Pin 6
const int EnB = 7;  //initializing pin 7 as pwm

// initialzing Ultrasonic sesor (Front view)
const int trigPin = 8;
const int echoPin = 9;

//For providing logic to L298 IC to choose the direction of the DC motor
void setup()
{
    /// initialize serial communication:
    Serial.begin(9600);
    pinMode(EnA,OUTPUT);   //we have to set PWM pin as output
    pinMode(in_1,OUTPUT);  //Logic pins are also set as output
    pinMode(in_2,OUTPUT);
    pinMode(EnB,OUTPUT);   //we have to set PWM pin as output
    pinMode(in_3,OUTPUT);  //Logic pins are also set as output
    pinMode(in_4,OUTPUT);

    //--------------------------------------------------------------
    // Reading the signal from the sensor: a HIGH pulse
    //-----------------------------------------------------------------
    pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
    pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
    //pinMode(trigPin2, OUTPUT);// set the trig pin to output (Send sound waves)
    //pinMode(echoPin2, INPUT);// set the echo pin to input (recieve sound waves)
}

void loop()
{
    int duration, Distance; // start the scan
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2); // delays are required for a succesful sensor operation.
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); //this delay is required as well!
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);

    //---------------------------------------
    // convert the time into a distance
    //---------------------------------------
    Distance = (duration/2)/29.1;
    Serial.print(Distance);
    Serial.print("cm");
    Serial.println();
    delay(1000);
    if (Distance <= 25)
    {
        //Stopping Right and Left Motors
        digitalWrite(in_1,HIGH);
        digitalWrite(in_2,HIGH);
        digitalWrite(in_3,HIGH);
        digitalWrite(in_4,HIGH);
    }
    else {
        //Moving both Motors in a Foward motion - IN_1 = LOW , IN_2 = HIGH, IN_3 = LOW , IN_4 = HIGH
        digitalWrite(in_1,HIGH);
        digitalWrite(in_2,LOW);
        analogWrite(EnA,200); // Enablling the Right motor @ speed of 200
        digitalWrite(in_3,HIGH);
        digitalWrite(in_4,LOW);
        analogWrite(EnB,200);// Enablling the Left motor @ speed of 200
    }
}


texts: How does the build process in Arduino IDE work for ESP8266

texts: How does the build process for esp8266 work in arduino IDE. Arduino ide uses avr-gcc to compile programs For atmel micro controllers. Does it uses same for compiling programs for esp8266?


texts:
I'm trying to build a tiny project. After I program the board, to power the dev board - how can I power it to run the code?

Question:

I was curious as to how I would be able to power the ATtiny85 USB Mini Dev Board by using a 90mAh 3.7V LiPo battery which is connected to a TP4056 5V micro USB Lipo battery charger? The power is regulated to 5V by a  3v to 5v 1a USB Charger DC-DC Converter feeding the 5V pin on the ATtiny85.
If now, how else can I power the ATtiny85 USB Mini Dev Board with a rechargeable battery?

New Circuit

Old Circuit

Final Circuit


texts: inconsistent digital output on simple code

texts:
so im new on arduino coding, and i made this code, where i input from serial monitor and then use it as a command for digital write. the problem is, sometimes the code work perfectly but then when i input 4, both D3 ad D4 is high and that also happens in D5 and D6. but its inconsistent, and i also print the 'out' value and also which digital pin is high to make it easier.
byte b;
int out;
int D3 = 3;int D4 = 4;int D5 = 5;int D6 = 6;int D7 = 7;int D8 = 8;
void setup() {
  Serial.begin(9600);
  pinMode(out, OUTPUT);
  digitalWrite(D3, LOW);digitalWrite(D4, LOW);digitalWrite(D5, LOW);digitalWrite(D6, LOW);digitalWrite(D7, LOW);digitalWrite(D8, LOW);

}

void loop() {
  while (Serial.available() == 0) {}
  b = Serial.read() - 48;
  out = b;
  Serial.print("\n Out is ");
  Serial.println(out);
  digitalWrite(out, HIGH);
  delay(600);
 if (digitalRead(D3) == HIGH)
{
   Serial.print("D3 HIGH");
}
 if (digitalRead(D4) == HIGH)
{
   Serial.print("D4 HIGH");}
 if (digitalRead(D5) == HIGH)
{
   Serial.print("D5 HIGH");
}
 if (digitalRead(D6) == HIGH)
{
   Serial.print("D6 HIGH");
   }
 if (digitalRead(D7) == HIGH)
{
   Serial.print("D7 HIGH");
}
 if (digitalRead(D8) == HIGH)
{
   Serial.print("D8 HIGH");
   }
  digitalWrite(out, LOW);
  delay(1000);

}

does anyone know why this happens? or can anyone recommend another method to do what im tryinng to do? thank you guys!!!


texts: Ethernet shield/WebServer problem: 'server is at 0.0.0.0'. Any suggestions how to debug it?

texts: Ethernet shield problem. When running the WebServer example sketch, the Serial Monitor shows that server is at 0.0.0.0. Any suggestions how to debug it?


texts:
Is it safe to measure current like this as long as measured voltage drop don't exceed 5V? I'm asking this because in almost all current sense circuits they used an opamp in their design.

Do I need a resistor between shunt resistor and ADC? Is there any noticeable current flowing to Arduino ADC that can damage it?

simulate this circuit – Schematic created using CircuitLab


texts:
The Keyboard API allows the Arduino boards such as the Micro or Leonardo to emit USB signals mimicking a physical keyboard. However, the signal seems to transmit key strokes and not characters which means that machines with different region settings interpret the USB signal differently. For example, a y will be interpreted as z in a German OS since the keyboard layout has these keys swapped.

Is there any way to output a signal that will result in the correct character being transmitted regardless of the OS settings without any modifications to the machine the Arduino is attached to?


texts: A good water flow meter to monitor home usage with Arduino

texts:
I'm searching for a good water flow meter to add to my home controller project with Arduino. I have been searching in several pages and I only found some devices that work for low flow.  I need to control the water usage in my home and I thought to add a flow meter at the point where the water enters my home, and view the data with Arduino.

Do you have experience with any flow meter with good quality?


texts: What do the TinyGPS++ output parameters mean?

texts:
TinyGPS++ give many output parameters. Where can I find explanation what do all output parameters mean? I don't understand what is the meaning of the following parameters:

  Course Speed Card  Distance Course Car

UPD

2365 is distance to London

wnw is the direction to London: https://en.wikipedia.org/wiki/Points_of_the_compass#Compass_point_names

0.00 - Vertical speed?

0.06 - Horizontal speed?

294.06 - ???


texts:
I started a project where I wanted to send sensor data from one arduino to another and let this 2nd Arduino send the data to a tablet to visualize sensordata like speed, temperature etc.

I wanted to send this in intervalls so UDP would be my way to go. I used the sketches which were provided from the Arduino software which worked well for a while. But after relocating to a new place it doesn't seem to work and I do not know why - I readjusted IP's, Ports and resetted my router.

This is my UDPWrite

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 178);
IPAddress IP_Remote(192, 168, 1, 177);
IPAddress Port_Remote(8887);

unsigned int localPort = 8887;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP

EthernetUDP Udp;

void setup() {

  // start the Ethernet and UDP:
  Serial.begin(9600);
  Ethernet.begin(mac,ip);

  Udp.begin(localPort);

  Serial.println(Ethernet.localIP());

}

void loop() {

  DHT.read11(dht_apin);

  Udp.beginPacket(IP_Remote, Port_Remote);
    Udp.write("hello");
    Udp.write("Current humidity");
    Udp.endPacket();

         Serial.println("Test");

    delay(2000);//Wait 2 seconds before accessing sensor again.

}

This is my UDPRead

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8887;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

void setup() {
  // start the Ethernet and UDP:

  Serial.begin(9600);
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  Serial.print(Ethernet.localIP());
}

void loop() {

  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
      Serial.println("Test");
Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print("Test");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);
}
}

This is what Wirehsark shows:

eceived.

The Arduinos are connected to my Switch Port5 and Port6 which are mirrored to Port8 to which I am connected via Notebook.

After a few tests, I do not seem to get into my

int packetSize = Udp.parsePacket();

if(packetSize) {

statement for a reason I cannot yet grasp. Udp.parsePacket should receive the UDP package from 192.168.1.178

I can Ping the .178 but not the .177.
I changed cables, ports, IPs, Switch and even the Arduinos. So I would think that the problem is code based.

Thank you very much for your help.


texts: Is this assignment valid or needs casting?

texts:
I have this assignment and while i don't get any error not even warning from the compiler.

uint16_t Buffer[40000];

for (int n=0; n<40000 ; n++){
Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n);
}

The Buffer is an unsigned short but as you can see inside there are float values inside.

The program does not work as expected.

Also i have another case where i am not sure if i need casting as this time, the final value is a float value.

int intVal;
float floatVal;

floatVal = intVal - intVal*Buffer[intVal];

Is this valid? Does it need casting? Or there is not reason to declare floatVal as float?


texts: Multiple readings from one change on a light sensor with interrupts

texts:
I was trying to make a code which did something every time a light dependent resistor was covered up by using interrupts so I could be running a different code at the same time.
This was my finalised code:

#define LIGHT 2

void setup() {
    Serial.begin(9600);
    pinMode(LIGHT, INPUT);
    attachInterrupt(digitalPinToInterrupt(LIGHT), fall, FALLING);
}

void loop() {
    Serial.print("Hello");
    Serial.println();
    delay(1000);
}

void fall(){
    Serial.print("Light Covered!");
    Serial.println();
}

I have tested my ldr circuit (5V into the ldr with a 10k pulldown resistor) and it reliably sits over the digital read boundary so I don't need to use analog read. It also seems to have no bounce as if I read it by outputting a message every time it reads it as high and then waiting until it goes low it only reads once every time I cover it and uncover it. However for some reason the code above which uses interrupts seems to print light covered 3-7 times every time I cover it. I am quite new to arduinos and C although I have used python for a while so sorry if it is a silly noob mistake.


texts: How to keep a pin LOW for a small amount of time after pushing a button and while device is booting?

texts:
Context

I keep the board in deepsleep mode and want to wake it with different buttons. I need to know which button has been pushed on boot. The board is immediately put back in deepsleep mode afterward.

I've been able to reset the board and pull a pin LOW at the same time. (see circuit below). The reset pin is momentarily pulled low so it reset the board effectively.

I'm not an electronic engineer, just a hobbyist, so any other method to do something are always welcome.

Problem

With the actual code/circuit, I need to hold the button until the device boot up so it can detect button was pushed but I would like to be able to just push the button quickly instead of having to hold it.

Question

How to add some sort of delay that will "hold" the SW-D5 button until the board boot?

Or anything that keep my D5 pin LOW for a short amount of time after the button has been pushed?

I think something in the range of 500 to 1000 milliseconds would be enough.

My actual circuit

simulate this circuit – Schematic created using CircuitLab

My code

#include <Spi.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>

int buttonPin = D5;

void setup() {
  // Read pin value as soon as possible after boot
  pinMode(buttonPin, INPUT_PULLUP);
  int buttonValueAtBoot = digitalRead(buttonPin);

  pinMode(BUILTIN_LED, OUTPUT);
  Serial.begin(115200);
  Serial.println();

  if (buttonValueAtBoot == LOW) {
    Serial.println("D5 was pressed");

    // Do something useful here like making an HTTP request.
    digitalWrite(BUILTIN_LED, LOW);
  }

  // Avoid problem when the button is being hold
  while (digitalRead(buttonPin) == LOW) {
    // wait before going to deepsleep
    // or the capacitor will be drained
    delay(1);
  }

  Serial.println("going to sleep");
  ESP.deepSleep(0);
}

void loop() {
}


texts: Arduino board is turning off when I connect to +5V

texts:
I am trying to set up an LCD screen without using a resistor or a potentiometer for an Arduino project. This is the LCD I am using: Basic 20x4 Character LCD.

But when I connect to +5V on the Arduino board, my Arduino board turns off. This is how I have the LCD connected to the Arduino on a breadboard.

Connections:

LCD RS pin to digital pin 12

LCD Enable pin to digital pin 11

Data:

• LCD D4 pin to digital pin 5

• LCD D5 pin to digital pin 4

• LCD D6 pin to digital pin 3

• LCD D7 pin to digital pin 2

LCD R/W pin to ground

LCD VSS pin to ground

LCD Cathode pin to ground

LCD Anode pin to digital pin 9

LCD VCC pin to 5V

Code:

// include the library code:
include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  analogWrite(6,20);
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}


texts: Arduino Nano IoT 33 Char Array size constraints

texts: I would like to save data that I am receiving from API calls in a char array. The problem is the data is around 80KB however my Arduino IoT 33 has 32KB of memory. It will save data in a char array that 25000 bytes however when I go to 30000 or above the Arduino freezes. When I copy-paste the entire data to a char array without specifying the size it works fine, however, when receiving data over API in chunks of 10KB it won't save the entire 80KB. Is there a way to go around this? A response will be appreciated.


texts:
I have a weird problem  , as I.m trying to connect to esp8266 01 with Arduino Uno when i try sending commands from the serial it doesn't work but if i send it in a function in the setup phase it works

#include <SoftwareSerial.h>

SoftwareSerial esp8266(2, 3);

void setup()
{
Serial.begin(9600);
esp8266.begin(9600);
delay(1000);
//sendData("AT", 1000);
//sendData("AT+CWMODE=1", 1000);
}

void loop() {
// put your main code here, to run repeatedly:
if(esp8266.available()) // check if the esp is sending a message
  {
      while(esp8266.available())
      {
          // The esp has data so display its output to the serial window
          char c = esp8266.read(); // read the next character.
          Serial.write(c);
      }
  }
  if(Serial.available())
  {
    delay(1000);
    String command="";
    while(Serial.available()) // read the command character by character
    {
        command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

void sendData(String command, const int timeout) {
 String response = "";
 esp8266.println(command);
 long int time = millis();
 while ((time + timeout) > millis())
   while (esp8266.available()) {
     char c  = esp8266.read();
     response += c;
    }
 Serial.println(response);
}


texts:
how my coding works = 1 rfid card detect on first rfid reader and 2 rfid card detect on second rfid reader after that servo go to 90
my second rfid not detect
this is my coding
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
Servo  myservo;
int pos = 0;
int angle = 0;
int angle11 = 0;

#define RST_PIN2           8          // Configurable, see typical pin layout above
#define SS_PIN           9          // Configurable, see typical pin layout above
#define SS_PIN2          10          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN2 );   // Create MFRC522 instance.
MFRC522 mfrc522_2(SS_PIN2, RST_PIN2);   // Create MFRC522 instance.

void setup()
{
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin();        // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card
  mfrc522_2.PCD_Init(); // Init MFRC522 card
  Serial.println("Approximate your card to the reader...");
  Serial.println();
   myservo.attach(5);

}
void loop()
 {

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

}

 // Select one of the cards

if ( ! mfrc522.PICC_ReadCardSerial()) {

return;

}

// Dump debug info about the card; PICC_HaltA() is automatically called

mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

  delay(1000);
  // Look for new cards

  if ( ! mfrc522_2.PICC_IsNewCardPresent()) {

    return;

  }
  // Select one of the cards

  if ( ! mfrc522_2.PICC_ReadCardSerial()) {

    return;

    mfrc522_2.PICC_DumpToSerial(&(mfrc522.uid));

  }

  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "09 99 55 B2") //change here the UID of the card/cards that you want to give access
 {
String content= "1";
  byte letter;
  for (byte ii = 0; ii < mfrc522_2.uid.size; ii++)
  {
     Serial.print(mfrc522_2.uid.uidByte[ii] < 0x10 ? " 0" : "1 ");
     Serial.print(mfrc522_2.uid.uidByte[ii], HEX);
     content.concat(String (mfrc522_2.uid.uidByte[ii] < 0x10 ? " 0" : "1 "));
     content.concat(String (mfrc522_2.uid.uidByte[ii], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "09 99 55 B3") //change here the UID of the card/cards that you want to give access

      myservo.write(angle); delay(3000);
   for(angle = 0; angle > 90; angle11)
    myservo.write(angle11);
    delay(3000);

    myservo.write(angle11); delay(3000);
   for(angle = 90; angle11 > 0; angle)
    myservo.write(angle);
    delay(3000);
    }

 else
 {
    Serial.println(" Access denied");
    delay(3000);

    }
  }


texts: generating signal of 3 phase UPS PWM by SVM

texts: Is there a realization code for 3-phase UPS inverter by Arduino?  I need implementation for SVM by voltage and current feedback.


texts: problem using GSM shield and GPS shield in one Arduino UNO R3

texts:
i try to program use the GSM shield Arduino with Arduino UNO i did it successfully but after that i try to use GPS shield but when i add the #include  for the program i got the error

#include <GSM.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h> // when i add that one i got the output eroor
// PIN Number for the SIM
#define PINNUMBER ""

i got this error out put

Arduino: 1.6.6 (Mac OS X), Board: "Arduino/Genuino Uno"

libraries/SoftwareSerial/SoftwareSerial.cpp.o: In function `__vector_3':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:227: multiple definition of `__vector_3'
libraries/GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:499: first defined here
libraries/SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::read()':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: multiple definition of `__vector_4'
libraries/GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:487: first defined here
libraries/SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::read()':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: multiple definition of `__vector_5'
libraries/GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:487: first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.


texts:
I had installed the old release (1.0.5) but for some reasons arduino stops working and I upgraded to new version 1.8.2, all works fine but I would like to use the bredboard 8Mhz version in the new release, but the boards system is not compatible with new version. The boards.txt is this:

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

How to build it to be compatible with news version? Thank you


texts: Wire.endTransmission() hangs, but only, if wire.begin(); is called with an address (MKR WiFi 1010)

texts:
This code runs without issues, scoped and seen from serial output:

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();
  Wire.onReceive(receiveEvent);

  while (!Serial);
}

void loop()
{
  Serial.println("1");
  Wire.beginTransmission(8);
  Serial.println("2");
  Wire.write(0x1);
  Serial.println("3");
  delay(100);
  Wire.endTransmission();
  delay(100);
  Serial.println("4");
  delay(500);
}

void receiveEvent(int howmany)
{
  delay(100);
}

This one hangs on Wire.endtransmission():

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin(10);
  Wire.onReceive(receiveEvent);

  while (!Serial);
}

void loop()
{
  Serial.println("1");
  Wire.beginTransmission(8);
  Serial.println("2");
  Wire.write(0x1);
  Serial.println("3");
  delay(100);
  Wire.endTransmission();
  delay(100);
  Serial.println("4");
  delay(500);
}

void receiveEvent(int howmany)
{
  delay(100);
}

The problem starts as soon as I assign an address in Wire.begin(). As I understand, a slave is also allowed to send data and temporarily becoming a master when addressing another device.


texts: Float to int conversion not working right in method using varargs

texts:
I am trying to convert a floating point number to an integer, but it seems like the conversion is not working properly.
I am using the math library to calculate the power of 10 based on the number of varargs, where the first argument is the number of arguments followed by the varargs.
int charsToIntValue(int argc, ...) {
  int multiplier = (int) pow(10, argc - 1);
  va_list argp;
  va_start(argp, argc);
  Serial.println(multiplier);
  ...
  va_end(argp);
}

For some reason, multiplier is always stored as 1 less than the actual result.
e.g. If charsToIntValue(4, 1, 2, 3, 4) is executed, the multiplier is stored as 999 rather than 1000. However, when it is printed as a float, it does show 1000.00. And whenever I change it to a constant ((int) pow(10, 3)) it works fine, returning 1000.
I've tired storing the value of argc into a local variable but that didn't seem to change anything.
Full project is here for context: https://github.com/Pyrodron/charger-destination-board
File in question is charger-destination-board.ino; lines 32 to 51


texts:
So I'm reading the Platform specification and doing some programming and I'm getting the error:

Error missing FQBN

So what does FQBN mean?


texts: Physical dimensions(size) of the new MKR1000 board?

texts: Anybody here knows the physical dimensions(size) of the new Aduino MKR1000 board?


texts: Problems with ACS758 Hall Effect Current Sensors - Calibration and no Signal

texts:
I purchased 3 ACS758 Hall Effect Current Sensors datasheet on ebay. A 50,100 and 200A, all three are bi-directional. They look like this.

With no current the 50A outputs 477 on the analogue input (2.33v), the 100A outputs 509 (2.48v) and the 200A outputs 512 (2.50v). At no current they should all be at exactly mid range i.e. 512 (2.50v). The datasheet says they're factory calibrated as such. I've tested them one after the other, both with 5v from the Audrino and with a separate 5v supply. As I've tested one after the other it's not likely to be stray magnetism or VCC.

I've then put them in a circuit drawing about 9amps. Accounting for the offset of zero amps the 50A and 100A measured the increased voltage correctly. The 200A doesn't change.

Is there any other tests I can do to see if I'm doing something dumb or are they all damaged?


texts:
I'm using Arduino Uno Wifi. I made my Arduino to get connected with my local network based on http://www.arduino.org/learning/getting-started/getting-started-with-arduino-uno-wifi

Now I would like to disable it and work with USB serial communication to upload sketches. But now I'm unable to upload sketches even if I select the serial port. I'm getting an AVRDUDE : seropen() Access is disabled error. I could perfectly do uploading if I select the networked port of the same Arduino.

Can I know why ?


texts: Can I connect this LED Matrix to a ESP8266 Huzzah directly?

texts:
This tutorial for the 16x32 LED Matrix makes it sound like you have to use an Arduino Uno or Mega, but the tutorial was also written a few years ago.  I have a Huzzah ESP8266 (my project is about displaying information from the internet on the LED matrix) but I can't seem to get the  library to work with the Huzzah.

I am wondering if it would be possible to somehow hook up the LED matrix directly to the Huzzah. Can anyone make suggestions on this front?

Or do I have to basically make the Uno a slave to the Huzzah ESP8266? Need to figure out how to do that.

Thank you.


texts: Method to iterate over the bits in a byte sent over serial

texts:
In my current project which integrates Arduino/avr IC with Raspberry-Pi, and each communicating via serial, I'm looking to send a byte of data to the Arduino from the RPi, which then would be iterated over, bit by bit.

Each bit represents a setting. If a bit is 0, then the Arduino would turn that respective device off, if a bit is 1, then Arduino would turn that respective device on. For example, a byte such as: 01100110, would mean the Arduino would have to turn four devices off, and four devices on.

I'm looking for information on how to take a byte over serial, and iterate over that byte bit by bit, and have the Arduino make decisions based on the value of each bit.

Excuse my post for lacking much technical detail, I'm refraining from using terms that are still very vague to me.

Regards.