texts: Data Loss over Serial Communication thru GSM SIM9000A Modem

texts:
I have an Arduino Megs 2560 board and using Serial 2 for communication with SIM9000A GSM Modem. I send over a HTTP get request by using appropriate AT command strings.

The GSM modem TX/RX pins are crossed with Arduino's Serial 2 port while the GSM modem card which also has DB9 pins is connected to a Hyper terminal - to see what it is receiving / rendering.

My issue is when I have to read after I get a response for my HTTP Get request.

Below is my code:

int Read(String message)
{
      char temp = '\0';
      int i=0;
      numbytes = 0;
      message= "";
      int endCnt = 0;
      debug_println("Reading Data!");
      Serial2.println("AT+HTTPREAD");
      delay(200);
      while(endCnt < 4) {
      while((Serial2.available())>0) {
          temp = Serial2.read();
          Serial.print(temp);
          switch(temp) {
            case '\r' : endCnt = 1; break;
            case '\n' : if(endCnt == 1) endCnt = 2; else endCnt = 0; break;
            case 'O'  : if(endCnt == 2) endCnt = 3; else endCnt = 0; break;
            case 'K'  : if(endCnt == 3) endCnt = 4; else endCnt = 0; break;
            default   : endCnt = 0; break;
          }
          if(endCnt == 4) break;

        }
     }
     debug_println("Read Data Ret: ");
     return i;
}

Note the Terminal shows me correctly when a HTTPREAD command is passed to GSM modem:

+HTTPACTION: 0,200,286

+HTTPREAD: 286

{"first_name":"dddddddddddddd","last_name":"dddddddddddddddd","start_date":"2000-12-31","chargeamt":"09.80","status":"ok","id":"68"}

<!-- Hosting24 Analytics Code -->

<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

<!-- End Of Analytics Code -->

OK

But Serial port printing shows me :

Reading Data!

+HTTPREAD: 286
{"first_name":"dddddddddddddd","last_name":"ds Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

OK

So after reading 45-46 th character at Serial2 port I am loosing data. I have tried all ways but unable to understand why my data at serial port is lost / overwritten?

Please let me know how can I resolve this?

====UPDATE====

After struggling a lot I was able to resolve the issue.

The code "delay(200);" after Serial2.println("AT+HTTPREAD"); was causing the issue. When I reduced the time I got the response as required.


texts: Can removing lines of code destroy a motor driver and make it catch fire?

texts:
I am making a pid line follower robot. So I was tinkering with code to optimize my line follower when i removed two lines of code unknowingly. As soon as I uploaded my code and started the line follower, 4 mosfets on my motor driver smoked and burst into blue flames. Bought a new one and same outcome. Interestingly, The ones corresponding to the left motor alone had this outcome as I removed " return Motorspeed1" and " return MotorSpeed2" from the function corresponding to the left motor. Heres the code :

signed int MotorSpeed = 70;
int MotorSpeed1, MotorSpeed2;
int MotorFunc(signed int a, signed int b){
   if(a >= -10 && a < 0)
   {
      b = -b;
      digitalWrite(_brk_m1, LOW);
      digitalWrite(_brk_m1, LOW);
      digitalWrite(_dir_m1, HIGH);
      digitalWrite(_dir_m2, LOW);
      MotorSpeed1 = MotorSpeed + b;
      MotorSpeed2 = MotorSpeed + b;
      MotorSpeed1 = constrain(MotorSpeed1, 0, 255);
      MotorSpeed2 = constrain(MotorSpeed2, 0, 255);
      analogWrite(_pwm_m1, MotorSpeed1);
      analogWrite(_pwm_m1, MotorSpeed2);
      return MotorSpeed1;
      return MotorSpeed2;
   }
   if (a < 10 && a > 0)
   {
      digitalWrite(_brk_m1, LOW);
      digitalWrite(_brk_m2, LOW);
      digitalWrite(_dir_m1, LOW);
      digitalWrite(_dir_m2, HIGH);
      MotorSpeed1 = MotorSpeed+ b;
      MotorSpeed2= MotorSpeed+ b;
      MotorSpeed1 = constrain( MotorSpeed1, 0, 255);
      MotorSpeed2= constrain( MotorSpeed2, 0, 255);
      analogWrite( _pwm_m1,  MotorSpeed1);
      analogWrite( _pwm_m2, MotorSpeed2);
      return MotorSpeed1;
      return MotorSpeed2;
   }

   else
   {
      digitalWrite(_brk_m1, LOW);
      digitalWrite(_brk_m2, LOW);
      digitalWrite(_dir_m1, HIGH);
      digitalWrite(_dir_m2, HIGH);
      MotorSpeed1 = MotorSpeed+ b;
      MotorSpeed2 = MotorSpeed - b;
      MotorSpeed1 = constrain(MotorSpeed1, 0, 255);
      MotorSpeed1 = constrain(MotorSpeed2, 0, 255);
      analogWrite( _pwm_m1, MotorSpeed1);
      analogWrite( _pwm_m2, MotorSpeed2);
      return MotorSpeed1;
      return MotorSpeed2;
   }

}

And i called this function in the code using :

    MotorFunc(a,b)

This code ran just fine, But when i removed the return functions from the first if condition, I destroyed 2 motordrivers,
Is this possible?
Edit:
I am updating the whole code:

The main code tab :

     int _dir_m1 = 2;
     int _pwm_m1 = 3;
     int _brk_m1 = 4;
     int _brk_m2 = 5;
     int _pwm_m2 = 6;
     int _dir_m2 = 7;

     int sen1 = A4;
     int sen2 = A3;
     int sen3 = A2;
     int sen4 = A1;
     int sen5 = A0;
     signed int Error = 0;

     int Kp = 20;
     int Ki = 0;
     int Kd = 0;

     void setup() {
     pinMode(_dir_m1, OUTPUT);
     pinMode(_pwm_m1, OUTPUT);
     pinMode(_brk_m1, OUTPUT);
     pinMode(_dir_m2, OUTPUT);
     pinMode(_pwm_m2, OUTPUT);
     pinMode(_brk_m2, OUTPUT);

     pinMode(sen1, INPUT);
     pinMode(sen2, INPUT);
     pinMode(sen3, INPUT);
     pinMode(sen4, INPUT);
     pinMode(sen5, INPUT);

     }

     void loop(){

     signed int a = Sensors();
     signed int b = PID(a);
     MotorFunc(a,b);
       }

And pretty much it. I am leaving out PID as Its not required along with error selection.

The setup is -
Arduino mega connected to 5 ir sensors
12v 9ah battery
500rpm 12v motors johnsons
and the motor driver 20 amp 20v-30v

Motor driver link with specs


texts:
I'm trying to store four items to EEPROM.  I can do one item no problem, I just don't know how to make the jump to multiple items.

My code:

#include <EEPROM.h>
char sgrpID[31] = "acpilot's arduino";
char addrID[51] = "123 any street rd";
char zpcdID[11] = "12345";
char gwayID[31] = "what a cool toy!";

void setup()
{
  Serial.begin(9600);
  for (int i = 0; i < 6; i++) {
    EEPROM.write(i, sgrpID[i]);
    EEPROM.write(i, addrID[i]);
    EEPROM.write(i, zpcdID[i]);
    EEPROM.write(i, gwayID[i]);
  }
}

void loop() {
  Serial.println(sgrpID);
  Serial.println(addrID);
  Serial.println(zpcdID);
  Serial.println(gwayID);
  delay(99999);
}

I want to be able to call on these in a sketch and post them to a db along with dynamic data of some flavor (TBD).

Am  on the right path?  Any help, corrections, or general guidance is appreciated.  I've moved beyond the "novice" stage of basic Arduino programming but an completely new to EEPROM.  If in doubt, SLOWER AND LOUDER is by far the best way to communicate key EEPROM concepts to me.

I have reviewed the Arduino EEPROM library but I was reading Greek.  I keep reading it and I'm sure at somepoint I'll recognize a pattrn and start to "get it."


texts: Digital pin output voltage fall down when driving a relay

texts:
I'm trying to trigger 8 different 5V relays using arduino atmega 2560. the relays (70Ohm coil) are powered by an external 5V source, and im trying to trigger them through a driving stage which contains for each relay a npn transistor (2N3904) and 1kOhms resistor directly connected to digital pin of the arduino.
the relays in my application are supposed to be drived 2 by 2 not all of them at once.
My problem is that i dont succeed triggering the relay with digital pins of my arduino, once i connect it to the resistor the voltage of the digital pins falls down from 5V to 0.4V or less. The transistor needs only 7mA to be triggered, the output current of the atmega2560 pins is 20mA max.
i tried with an external 5V source, it triggers correctly showing 10mA maximum of current through the driving stage.
Thank you in advance for your help.
Best regards.


texts: Problem with Reading Multiple Analog Values From ESP8266 NodeMCU

texts:
I am using ESP8266 nodemcu with ADS1115, but values are totally wrong. Why this happened?

Is there any solution to extends the Node MCU 8266 pins with accurate sensor values ?


texts:
I am working on an Arduino Uno Project of a car with two motors. The motor driver board is an L9110 H-Bridge. Here is how everything is connected:

And here is the code I am trying to run:

//Define all the pins for the motors
#define motorPinA1 3  //A pin right motor
#define motorPinB1 5  //B pin right motor
#define motorPinA2 6 //A pin left motor
#define motorPinB2 9 //B pin left motor

//Movement functions
void stopCar();
void frwrd(int motorSpdRight, int motorSpdLeft);
void back(int motorSpdRight, int motorSpdLeft);

//Global Variables
int motorSpeedRight = 0;  //The speed of the right motor
int motorSpeedLeft = 0;   //The speed of the left motor

void setup() {
  //Movement
  pinMode(motorPinA1, OUTPUT);
  pinMode(motorPinB1, OUTPUT);
  pinMode(motorPinA2, OUTPUT);
  pinMode(motorPinB2, OUTPUT);

  //Serial Monitor for debugging
  Serial.begin(9600);

  motorSpeedLeft = 100;
  motorSpeedRight = 100;

  frwrd(100, 100);
  delay(2000);
  stopCar();
  delay(1000);

  back(100, 100);
  delay(2000);
  stopCar();
  delay(1000);
}

void loop() {

  Serial.print("Forward");
  Serial.print("\n");

  frwrd(motorSpeedRight, motorSpeedLeft);
  delay(2000);
  stopCar();
  delay(1000);

  back(motorSpeedRight, motorSpeedLeft);
  delay(2000);
  stopCar();
  delay(1000);

}

// functions we need to make the code run
void stopCar(){
    Serial.print("Stoping Car\n");
    // Put motor 1 in halt
    analogWrite(motorPinA1, 0);
    analogWrite(motorPinB1, 0);

    // Put motor 2 in halt
    analogWrite(motorPinA2, 0);
    analogWrite(motorPinB2, 0);
}

// For the farward direction A pins will be high
void frwrd(int motorSpdRight, int motorSpdLeft){
    // Put motor 1 (Right) in forward motion with speed = motor_spd
    analogWrite(motorPinA1, motorSpdRight);
    analogWrite(motorPinB1, 0);

    // Put motor 2 (Left) in forward motion with speed = motor_spd
    analogWrite(motorPinA2, motorSpdLeft);
    analogWrite(motorPinB2, 0);

    /*
    // Put motor 1 (Right) in forward motion
    digitalWrite(motorPinA1, HIGH);
    digitalWrite(motorPinB1, LOW);

    // Put motor 2 (Left) in forward motion
    digitalWrite(motorPinA2, HIGH);
    analogWrite(motorPinB2, LOW);
    */
}

// For the backward direction B pins will be high
void back(int motorSpdRight, int motorSpdLeft){
    // Put motor 1 (Right) in backward motion with speed = motor_spd
    analogWrite(motorPinA1, 0);
    analogWrite(motorPinB1, motorSpdRight);

    // Put motor 2 (Left) in backward motion with speed = motor_spd
    analogWrite(motorPinA2, 0);
    analogWrite(motorPinB2, motorSpdLeft);

    /*
    // Put motor 1 (Right) in backward motion
    digitalWrite(motorPinA1, LOW);
    digitalWrite(motorPinB1, HIGH);

    // Put motor 2 (Left) in backward motion
    digitalWrite(motorPinA2, LOW);
    digitalWrite(motorPinB2, HIGH);
    */
}

Pins 3, 5, 6 and 9 are PWM so I can alalogWrite() to them and control the speed of the motors. Code uploads fine but although both motors move forward normally motor 1 (on pins 3, 5) doesn't move backward. The strange thing is that if I use digitalWrite (the commented code in the two functions) instead everything works normally but the motors move in full speed so it's not usable for my project. I have tested all the pins in other projects and everything worked fine so I know my board is not faulty.

I have also taken some measurements with a multimeter while the code was running. In the forward motion, both pairs of pins measured 1.95V. In the backward motion, the problematic pins measured 0V.

Any help would be appreciated!!


texts: Difference in bootloader of ATmega with 16MHz external crystal and 8MHz external crystal

texts:
I have used your bootloader for ATmega2560-16AU with 16MHz external crystal and it works like a wonder.

In my new project I have a 3V power supply. Therefore, I am planning to use a low frequency external crystal in order to operate the ATmega at a low frequency so that the voltage will be able to go as low as possible.

However, I have a number of issues/questions:

I uploaded the bootloader using an 8MHz external crystal and it went successfully but I am not able to upload a sketch.
Can I run an ATmega2560-16AU with an 8MHz crystal and will it work at 3V, without any risk?
As I do not have an ATmega2560-8AU right now, I am not able to test this. Will your bootloader work with Atmega2560-8AU and an external 8MHz crystal or, before burning bootloader, do I need to make any changes?

Sorry to ask you such a long query, but I have really spent lots of time looking at this and finally today I made a post everywhere.


texts: measure very small ( negative and positve ) Voltage with Arduino

texts:
How can I measure Voltage in Range -100mv to +100mv with Arduino ,
Is that an Arduino-shield can do that ?


texts: How to let Stepper motor spin constantly?

texts:
When i run the code on the Arduino the Stepper only does a small turn every cycle. How can i make that constantly turning?
 #include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
//Servo Teil
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(105);
  // initialize the serial port:
  Serial.begin(9600);
  //Servo
    myservo.attach(3);  // attaches the servo on pin 9 to the servo object
    //Servo

}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  //Servo
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  //Servo

}


texts: Why I cannot connect directly Arduino UNO and Xbee S2?

texts:
I'm connecting Arduino UNO to Xbee S2 Zigbee module directly, and X-CTU cannot find Xbee module via arduino. i'm not using shield, it finds with non-arduino board connecter, but not by arduino UNO board.

i checked all parameters like baud rate, etc.., wirings, and it seems no problem at all, but it keeps msg like 'reset your radio module' and even i swtiched pin 5 and GND, it doesn't works.

what i have to do?


texts: SPI or A0/A1: what is the best solution for pin allocation on an Arduino shield?

texts:
When you design an Arduino shield you want to make it compatible with a maximum number of shields that may be stacked with it on an Arduino (UNO). Considering the following two possible tradeoffs, which one would you consider the best:

Option A: A shield that uses pins A0 and A1, where no other stacked shield can use those pins.
Option B: A shield that uses SPI, where other stacked shields can only use pins 11, 12 and 13 in SPI mode.

Note: I'm asking this question for a project I'm designing called Omzlo one. It's an Arduino compatible board with builtin CAN bus networking. I'm hesitating between two prototype designs.


texts:
I am using the RFID module to read mifare NFC chips and the library has only methods to send the data to the serial monitor. I need them to be saved to an SD card file. I have been adding custom methods to the library files to return strings that I then write to the SD card but this is a pain; there must be a quicker way to simply pipe all the data automatically but I do not know how to do this in cpp.

Here is an example of the function to dump to serial, that needs to be piped to the file on the SD card.

void MFRC522::PICC_DumpDetailsToSerial(Uid *uid) {
    Serial.print(F("Card UID:"));
    for (byte i = 0; i < uid->size; i++) {
        if(uid->uidByte[i] < 0x10)
            Serial.print(F(" 0"));
        else
            Serial.print(F(" "));
        Serial.print(uid->uidByte[i], HEX);
    }
    Serial.println();

    // SAK
    Serial.print(F("Card SAK: "));
    if(uid->sak < 0x10)
        Serial.print(F("0"));
    Serial.println(uid->sak, HEX);

    // (suggested) PICC type
    PICC_Type piccType = PICC_GetType(uid->sak);
    Serial.print(F("PICC type: "));
    Serial.println(PICC_GetTypeName(piccType));
}

Thanks!


texts: Arduino Due Digital Inputs without Response

texts:
On two of my Arduino Due, when connecting the pin 3.3V to any digital inputs (37,36,35,34), no serial message nor LED_BUILTIN is thrown as output, only the Test message.

Digital Pins are set as INPUT by default. Blink works.

I have never connected any other thing on those pins, even 5V.

What I am missing?

void setup() {
    Serial.begin(115200);
    while(!Serial);
    pinMode(LED_BUILTIN,OUTPUT);
    Serial.print("Test");
}

void loop() {
    if (digitalRead(37))
        Serial.print("37");
    if (digitalRead(36))
        Serial.print("36");
    if (digitalRead(35))
        Serial.print("35");
    if (digitalRead(34))
        Serial.print("34");
    digitalWrite(LED_BUILTIN,digitalRead(37));
}


texts:
Does anyone know what the actual baud rate that the CDC Based virtual serial port on the Leonardo runs at is? Serial::being() for the CDC version is just empty, so it's not setting a baud rate anywhere.

Basically, I'm debating between using the 32u4 or the 328p with an FTDI chip and trying to figure out if the 32u4 will be slower... since it uses a virtual COM port I'm assuming it is, but I'd be happy if I was wrong :)


texts: Arduino nano 33 ble vs ble sense. Power consumption, etc

texts:
After working with an Arduino Uno at work, I am looking to buy myself a board for some projects/experiments at home. The nano size seems like a great option, especially the one without soldered headers, as it is very flexible and easy to fit in projects with limited space. More specifically, I am interested in nano 33 ble and nano 33 ble sense.
My question is, apart from price does anyone know of any other disadvantages the sense board might have on comparison to the 33 ble?
Does it consume more power if the sensors are not used in a projects (just from being integrated in the board’s circuit)?
Also, does the light intensity sensor work like an LDR (photoresistor)? E.g. will I be able to do things like turn on LEDs automatically when it is dark, based on the sensor’s readings?


texts: I have five pushbuttons that refer to a specific pin number. I need an efficient code to set the variable for the pin with state 1. What can I use?

texts:
There are 5 push buttons each which correspond to a certain pin let us use 1 to 5 for an example. I want to set a variable, ActiveButton which will be set equal to the the only pin in the one state.
We make use of the concept that there can only be one active push button which means the pin of that would have a state of 1 and the rest would be 0. The long method for this would be to use if else and digitalRead(pin) == 1 for everything but that would be so long on code. I've considered using do while or while loops to stop until it reaches the push button with a state of 1, but I was wondering if there was a more efficient code. I was also thinking if there was something that made use of an array?
Though the idea of like having a simple array return the index which results to a corresponding value, like lets say Array[3] ==1 among all the indices from 0 to 4 feels easy to conceptualize, I believe this can be really taxing on the code and might not be able to be done in a short way.
I've also thought of possibly using switch case, where the variable would be the high state and the case values would be the digitalRead for each pin? But that would be wrong probably because I'm not sure but you can't set the switch variable to be a constant. It would be something like
switch (1)
case digitalRead(1):
case digitalRead(2):


texts: Is it possible to setup a CAN-BUS Arduino Shield to communicate with SocketCAN for UNIX?

texts: I have an Arduino + SparkFun CAN shield, and I was hoping to set it up to work with candump on an Ubuntu system. Is this doable, or is candump made specifically for raspberry Pi's?


texts: Connecting multiple HC-05 Modules to a single computer system

texts:
For my Final Year Project, I would like to connect 5 HC-05 modules to my computer system and send data simultaneously from all 5 modules to the computer system
is this possible?


texts: How to control MKR1000 from outside your local network

texts:
I want to send an HTTP command to MKR1000 from outside my local network.

So far, all the googled resources point to getting the local IP (example 192.168.0.10) of MKR1000 and sending a command like http://192.168.0.10/H to it and then parse it.

How do I send a command to MKR1000 from outside its local network?

I should clarify that I want this to be a consumer product and can't have the end-user fiddling with their routers for port forwarding etc.


texts: Connect multiple modules to arduino micro

texts:
I have an Arduino Micro and I want to connect an LCD and Bluetooth module to it. The problem I face is that there are not enough power pins for them both.

I understand that I probably need some external power supply for them, but I have no idea how to do this properly.


texts: MD5 hash for Arduino Uno [-Wshift-count-overflow]?

texts:
I tried to test out this MD5 library (https://github.com/tzikis/ArduinoMD5 ) as a hash function on arduino uno.

What I have done is that I placed the MD5.cpp and MD5.h to the folder below:
C:\Program Files (x86)\Arduino\libraries\MD5

And launched arduino IDE 1.8.9 to test the example provided (https://github.com/tzikis/ArduinoMD5/blob/master/examples/MD5_Hash/MD5_Hash.ino):

#include <MD5.h>
/*
This is en example of how to use my MD5 library. It provides two
easy-to-use methods, one for generating the MD5 hash, and the second
one to generate the hex encoding of the hash, which is frequently used.
*/
void setup()
{
  //initialize serial
  Serial.begin(9600);
  //give it a second
  delay(1000);
  //generate the MD5 hash for our string
  unsigned char* hash=MD5::make_hash("hello world");
  //generate the digest (hex encoding) of our hash
  char *md5str = MD5::make_digest(hash, 16);
  free(hash);
  //print it on our serial monitor
  Serial.println(md5str);
  //Give the Memory back to the System if you run the md5 Hash generation in a loop
  free(md5str);
}

void loop()
{
}

However when run verify and compile, it works but got the warnings below:

...\sketch_may02a_MD5_test.ino.ino: In function 'void setup()':

sketch_may02a_MD5_test.ino.ino:15:51:
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   unsigned char* hash=MD5::make_hash("hello world");

                                                   ^

C:\Program Files (x86)\Arduino\libraries\MD5\MD5.cpp:
In static member function 'static void MD5::MD5Update(void*, const void*, size_t)':

C:\Program Files (x86)\Arduino\libraries\MD5\MD5.cpp:207:21:
warning: right shift count >= width of type [-Wshift-count-overflow]

  ctx->hi += size >> 29;

                     ^

I know little of c++, can anyone help to fix this? Thanks a lot!!


texts:
I am looking for (reasonably easy to use and well tested) alternatives to the Wire library. Wire works very well, but: I only need the Arduino to act as I2C master and the Wire library seems to be a real waste of resources:

My goal is to send out data en bloc (e.g. 32 or 64 bytes). This data is already sitting in an array in SRAM. Now when you use the Wire library, you call the TwoWire::write function which copies your data into a 2nd buffer. Afterwards, Wire makes use of the TWI library where twi_writeTo copies the data again into a 3rd buffer. That's a bit clunky, isn't it?

I have seen the DSSCircuits / I2C-Master-Library but I am not sure how mature it is because there hasn't been any commit after the initial commit which is 3 years old now.


texts: Loop being restarted before it finishes?

texts:
I have a Loop process that does various I/O and delay operations and also logs to the serial port so that we can review the activity.

We what I think is the loop being interrupted. Normally the serial activity would go like:

Do A
Do B
Do C
Done
Do A
Do B
Do C
Done
Do A
Do B
Do C
Done
...
...

But sometimes we see it go like:

Do A
Do B
Do A
Do B
Do C
Done
Do A
Do A
Do B
Do C
Done
...
...

The Arduino does not reset/reboot as we have a serial output in Setup and we don't see it in the serial port logs.

Any idea of what could cause this ?

Any hints appreciated.

EDIT Here is an actual part of code:

send_log("11:00pm - Start Winterfell sequence");
digitalWrite(LOGISTIC_TANK_FLOWER, LOW); /// open early flower tank
digitalWrite(AGITATION_PUMPS, LOW);           // turn on agitation pumps
digitalWrite(LOGISTIC_TANK_H20, HIGH);        /// close h20 tank
delay(1000);
digitalWrite(LOGISTIC_WINTERFELL, LOW); /// open solenoids to winterfell
digitalWrite(LOGISTIC_WINTERFELL_A, LOW);
send_log("Start feeding quadrant A");
delay(10000);
digitalWrite(LOGISTIC_WINTERFELL_A, HIGH); /// feed quadrant b
digitalWrite(LOGISTIC_WINTERFELL_B, LOW);
send_log("Done feeding quadrant A");
send_log("Start feeding quadrant B");
delay(10000);
digitalWrite(LOGISTIC_WINTERFELL, HIGH); /// close solenoids to winterfell
digitalWrite(LOGISTIC_WINTERFELL_B, HIGH);
send_log("Done feeding quadrant B");
delay(1000);
digitalWrite(LOGISTIC_TANK_FLOWER, HIGH); /// close solenoid from early flower tank
digitalWrite(LOGISTIC_TANK_H20, LOW); //// open h20 tank
digitalWrite(LOGISTIC_WASTE, LOW); /// open purge line to clean pump manifold
send_log("Start purge");
delay(5000);
digitalWrite(LOGISTIC_WASTE, HIGH);  /// close waste line
digitalWrite(AGITATION_PUMPS, HIGH); // turn off agitation pumps
send_log("Done purge, sleeping");
delay(60000);  // Sleep 60s so that we don't hit 23h00 again right away

And the corresponding double log on the serial monitor:

D, [2018-01-16T21:34:00.777784 #16658] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: START|0|0|]
D, [2018-01-16T22:59:59.001241 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: 11:00pm - Start Winterfell sequence|23|0|]
D, [2018-01-16T23:00:00.000999 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Start feeding quadrant A|23|0|]
D, [2018-01-16T23:00:10.375210 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Done feeding quadrant A|23|0|]
D, [2018-01-16T23:00:11.040758 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Start feeding quadrant B|23|0|]
D, [2018-01-16T23:00:33.471231 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: 11:00pm - Start Winterfell sequence|23|0|]
D, [2018-01-16T23:00:34.470338 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Start feeding quadrant A|23|0|]
D, [2018-01-16T23:00:44.468602 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Done feeding quadrant A|23|0|]
D, [2018-01-16T23:00:44.969697 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Start feeding quadrant B|23|0|]
D, [2018-01-16T23:00:54.637124 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Done feeding quadrant B|23|0|]
D, [2018-01-16T23:00:55.519573 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Start purge|23|0|]
D, [2018-01-16T23:01:00.637667 #17110] DEBUG -- : port: [ttyACM3] invalid response: [7|v0.0.1.rc4|Irrigation|debug_log: Done purge, sleeping|23|0|]

As you see it restarts the sequence even before it finishes it.


texts: Infra Red sketch "not declared in this scope"

texts:
I'm pretty new at Arduino and I'm trying to upload a sketch with IR sensor to control LED-s.
I copy the code from internet,download library,I put my infrared codes for TV remote where I want and it says:"not declared in this scope"

Code and error:

#include <IRremote.h>

const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int redPin = 6;
const int greenPin = 9;

void setup(){
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop(){
    if (irrecv.decode(&results)){

        switch(results.value){
          case E0E036C9: //Keypad button "5"
          digitalWrite(redPin, HIGH);
          delay(2000);
          digitalWrite(redPin, LOW);
          }

        switch(results.value){
          case E0E028D7: //Keypad button "2"
          digitalWrite(greenPin, HIGH);
          delay(2000);
          digitalWrite(greenPin, LOW);
          }

        irrecv.resume();
    }
}

Error:

C:\Users\Kandzija\Desktop\saneta\saneta.ino: In function 'void loop()':
saneta:21: error: 'E0E036C9' was not declared in this scope
           case E0E036C9: //Keypad button "5"
                ^
saneta:28: error: 'E0E028D7' was not declared in this scope
           case E0E028D7: //Keypad button "2"
                ^
exit status 1
'E0E036C9' was not declared in this scope

Can you help me guys pls?
Thank You!


texts: Power LED Matrix With LiPo Battery & ESP32

texts:
I want to power an ESP32 with a 3.7V LiPo battery. There's a LED matrix of 64 WS2812 LEDs attached to the ESP32. I learned that I need a buck boost converter to power the microcontroller as it needs a 5V power input. The boost converter delivers that when there is no matrix attached. However if the matrix is attached it only receives about 2.7V. Turning the potentiometer on the boost converter changes nothing in this case. What is the reason for this? I am sorry if this question seems basic to you. I am an beginner with electronics.
Here is a rather hideous scetch of the connections. I hope this is okay:

This is the buck converter I used: https://www.amazon.de/gp/product/B079H3YD8V/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1


texts: Problems with serial communication from Arduino to Bluetooth HC-05

texts:
I just purchased some HC-05 Bluetooth devices and I have followed the directions to put the devices in AT command mode by holding EN HIGH when the HC-05 powers up.  When I do this the HC-05 goes into the "slow blink" to indicate it is in command mode.  However, when I send it "AT" I get odd characters in the response.

Note that when I type "AT" I get exactly 4 characters back.  They are just not the "OK" characters I expect.  I also verified that the Arduino IDE serial console is sending both NL and CR characters.

BTW, here is the Mel Patrick HC-05 authored setup program I am running:

https://raw.githubusercontent.com/dmccreary/coderdojo-robots/master/src/bluetooth-remote/hc-05-setup/hc-05-setup.ino

It has been suggested that the data from the HC-05 is only going up to 3.3v and that might be the cause of the problem, since the Arduino is looking for a 0-5 volt signal.

I also note that when I remove the TDX line from the HC-05 that no responses come back.  So I suspect that it is getting the "AT" fine through the RTX from the Arduino to the HC-05.  It is just some problem in the return data format.

Is there a simple transistor circuit I can hookup to shift the levels back to 0 to 5 volts from the 0 to 3.3 volts?

I am also using an Arduino Nano if that makes any difference.

Thanks - Dan


texts:
I'm trying to control an led attached to my arduino via key presses on my laptop.When i hold down a key, the led should light up, and when i release the key, the led should turn off.

While my code works ATM, i am wondering why my code will not work if i replace the numbers in my code with text/strings.

Processing code(Working)

import processing.serial.*;
Serial myPort;

void setup(){
  println("The available ports are: ");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
  myPort.buffer(8);
  size(500, 500);
}

void draw(){
  if(keyPressed){
    if(key == 'r' || key == 'R'){
      myPort.write(1);
      println("red");
    }

  }

}

void keyReleased(){
  myPort.write(2);println("released");
}

Arduino Code(Working)

int red = 7;

void setup(){
  Serial.begin(9600);
  pinMode(red,OUTPUT);
}

void loop(){

}

void serialEvent(){
    int input = Serial.read();
  if(input == 1){
    digitalWrite(red,HIGH);
  }else if(input == 2){
    digitalWrite(red,LOW);
  }
}

Processing Code (Not working)

import processing.serial.*;
Serial myPort;

void setup(){
  println("The available ports are: ");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
  myPort.buffer(8);
  size(500, 500);
}

void draw(){
  if(keyPressed){
    if(key == 'r' || key == 'R'){
      myPort.write("red");
      println("red");
    }

  }

}

void keyReleased(){
  myPort.write("released");
  println("released");
}

Arduino Code(Not working)

int red = 7;

void setup(){
  Serial.begin(9600);
  pinMode(red,OUTPUT);
}

void loop(){

}

void serialEvent(){
    int input = Serial.read();
  if(input == "red"){
    digitalWrite(red,HIGH);
  }else if(input == "released"){
    digitalWrite(red,LOW);
  }
}

From the above example, i get the error ISO C++ forbids comparisons between pointers and integers.After googling the error, it was suggested that i replace the double quotes with single quotes, after which the arduino code is able to compile, but the processing code gives an error "badly formed character constant(expecting quote,got e)".

I then tried changing using double quotes for processing and single quotes for the arduino quote, but predictably, it did not work.

Why does my code work when i pass numbers to the arduino via serial communication, and my code fails when i use text strings?


texts: Controlling DC motor from Android device

texts:
Ref: https://robotics.stackexchange.com/q/8526/11146

I want to build a simple android controlled robot

I will connect android phone<usb>arduino<wire>motor controller<wire>dc motor

I wonder why I have to write two programs (android java & arduino c++)?

How can I directly control the DC motor from android java program without writing arduino code?


texts:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "digitalWriteFast.h"

#define BUTTONPIN 2
#define FDCSPIN 6
#define CIPIN 5
#define SPEAKERPIN 4

float RPM=1000.0;
int PWus=1.5*1000.0;
int FDCSoffset=(1000.0/RPM/60.0/4.0) - (PWus/1000.0);
int CiCnt;
int totalCnt;
int CIState=B01100000;
bool Buttonstate=0;
LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup()
{
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  lcd.clear();
  lcd.print("READY TO TEST"); // Waiting for button press
  pinMode(BUTTONPIN, INPUT);// Setting button as Input
  pinMode(FDCSPIN, OUTPUT); // Fuel Delivery Control Signal
  pinMode(CIPIN, OUTPUT); // Cylinder Identification
  digitalWriteFast(FDCSPIN, LOW);
  digitalWriteFast(CIPIN, LOW);
}

void loop()
{
 Buttonstate=digitalReadFast(BUTTONPIN);
 if(Buttonstate==1)
 {
  delay(5);
  if(Buttonstate==1)
  {
    runInjectorTest();
  }
 }
}
void runInjectorTest()
{
  lcd.print("Test Run");
  playtesttone();

    for(totalCnt=0;totalCnt<8000;totalCnt++)
    {

      PORTD=CIState;
      delayMicroseconds(FDCSoffset);
      PORTD=PORTD^B01000000;
      delayMicroseconds(PWus);
      if(totalCnt%4==0)
      {
        CIState=CIState^B00100000;
      }
    }
  totalCnt=0;
  playfinishtone();
}
void playtesttone()
{
  tone(SPEAKERPIN, 500, 500);
  delay(700);
  tone(SPEAKERPIN, 500, 500);
  delay(700);
  tone(SPEAKERPIN, 500, 500);
  delay(700);
  tone(SPEAKERPIN, 2000, 500);
}
void playfinishtone()
{

  tone(SPEAKERPIN, 2000, 500);
  delay(700);
  tone(SPEAKERPIN, 2000, 500);
  delay(700);
  tone(SPEAKERPIN, 2000, 500);
  delay(700);
  tone(SPEAKERPIN, 500, 500);

}

I am using this code to generate 2 signals, called CI and FDCS. CI stays on until the 5th FDCS pulse. I checked the output which is connected to a driver using the scope and I got this.
The rising edge and falling edge of the longer signal (CI, dark green) are supposed to sync with the rising edge of the FDCS signal (Lime green),but they are inline with the falling edge. Note that the output is inverted (when compared to the code) hence the signal generated by the Arduino pins is according to the code.


texts: Using XBEE from my laptop, I want to assign multiple values in the Arduino

texts:
I'm trying to control motors by Arduino, from my laptop. I'm using MATLAB to send over packets of data, i.e. 'x=100,y=150,z=200' My scheme was to send this packet to Arduino, and have Arduino extract the numerical values from the string, since the positions of the numbers will always be consistent. I found a code from Arduino forum, written by PaulS, but I can't figure out why it wouldn't move into 'if (xbee.available())' portion of the code. The code is attached below:

#include <SoftwareSerial.h>
#define SOP '<'
#define EOP '>'

SoftwareSerial XBee(2, 3); // RX, TX
int test = 0;
bool started = false;
bool ended = false;

char inData[20];
byte index;
char inChar;

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

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    if (XBee.available())
    {
      char inChar = XBee.read();
     }
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       Serial.print(inData);
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       Serial.print(inChar);
       ended = true;
       break;
    }
    else
    {
      if(index < 19)
      {
        inData[index] = inChar;
        Serial.print(inData);
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    Serial.println(inData);
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}


texts: Particle Spark (Arduino) How to flash 2 LED sequences at the same time?

texts:
I can't find any information that relates to my problem. The few things I did find confused me (I'm quite new to this).

I'm trying to flash 2 sequences of 4 lights at the same time. I can get 1 set flashing but I don't know how to run other sequences at the same time. My probably laughable attempt at the code is below:

int led1 = D0;
int led2 = D1;
int led3 = D2;
int led4 = D3;
int led5 = D4;
int led6 = D5;
int led7 = D6;
int led8 = D7;

void setup() {
  setupPart1();
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  setupPart2();
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
}

void loop() {
  loopPart1();
  digitalWrite(led1, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led3, LOW);
  digitalWrite(led4, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led4, LOW);
  loopPart2();
  digitalWrite(led5, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led5, LOW);
  digitalWrite(led6, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led6, LOW);
  digitalWrite(led7, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led7, LOW);
  digitalWrite(led8, HIGH);
  delay(500); // delayed for half a second
  digitalWrite(led8, LOW);
}


texts: Arduino UNO R3 clone acting as Arduino Nano

texts:
I just got a bunch of Arduino Uno R3 (ATmega328P + CH340).In arduino IDE when i'm selecting board as Arduino UNO then i'am getting this error

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM7
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xaf

But, When i'm selecting Arduino Nano it's working fine. How to fix it?


texts: How to do weigh scale zeroing (tare weight)?

texts:
I'm using the sketch below for a weighing scale. The sketch prints out the load-cell voltage just fine. I can't figure out how to let the scale run a couple seconds to stabilize, then use the current voltage reading (nothing on the scale) as the "Zero" voltage. Then subtract that "Zero" voltage from future readings to get the actual voltage for any weight placed on the scale. For example, let's say the nothing on the scale voltage is 0.5 volts. Then a 10 LB weight is added and the voltage goes up to 1.5 volts. So the actual voltage increase from the weight is 1.5 minus 0.5, or 1.0 volts.

#include <ads1262.h>

const float VREF = 2.50;  // Internal reference

ads1262 PC_ADS1262;  // ADC object

void setup() {
  // initialize the  data ready and chip select pins:
  pinMode(ADS1262_DRDY_PIN,  INPUT);   // data ready input line
  pinMode(ADS1262_CS_PIN,    OUTPUT);  // chip enable output line
  pinMode(ADS1262_START_PIN, OUTPUT);  // start
  pinMode(ADS1262_PWDN_PIN,  OUTPUT);  // power down output
  Serial.begin(9600);

  // initialize ADS1292 slave
  PC_ADS1262.ads1262_Init();
  Serial.println("ads1262 Initialised successfully....");
}

void loop() {
  // Nothing to do unless data ready is asserted.
  if (digitalRead(ADS1262_DRDY_PIN) == HIGH) return;

  // Get a reading and convert to voltage.
  uint8_t *buffer = (uint8_t *) PC_ADS1262.ads1262_Read_Data();
  signed long reading = (uint32_t) buffer[1] << 24
                  | (uint32_t) buffer[2] << 16
                  | (uint32_t) buffer[3] <<  8
                  | (uint32_t) buffer[4] <<  0;
  float voltage = VREF / (1UL<<31) * reading;

  // Report a smoothed-out reading.
  Serial.println(voltage, 8);
}


texts: How to pad an ascii number with leading zeros?

texts:
I need to include a 3 digit ascii representation of message length number in the message header, but I am having difficulty trying to pad the number with leading '0' zeros in order to keep the number of 'length' digits needing to be appended always 3 even when the message length is only one or two digits long.

Addendum:
The problem, more specifically, is how to left-pad a char array containing the number representation.
I got as far as defining what and where, but I couldn't figure out how to shift the char[] contents right in order to insert the "0" at msglength[0].  (I tried using strcat, but that didn't work).

char msglength[4]          //(3 digits + nul)
for (int pad=1; pad<=3-strlen(msglength); pad++)
{
    // add a leading zero char to msglength, but that involves
    // somehow shifting all its contents to the right
}


texts: How to pause the analog value according to input signal applied to a particular digital pin?

texts:
I'm working with a digital blood pressure meter using arduino nano. I need to display the pressure reading during inflation and deflation of the cuff instantly. And when an input signal applied to a particular pin during deflation, I need to print the pressure value at that time of input signal, to a display. How to code for this logic. I made the code for showing pressure value during inflation and deflation. But need to pause the value and display constantly the pressure value at the time of input applied to the arduino pin. How this pausing of value can be done?.
Finally I need to print both the systolic and diastolic pressure value constantly as: 120/80 mmHg (systolic/diastolic mmHg)
In this project, the systolic pressure is noted when there is an input at digital pin.

In the case of diastolic pressure, it is noted according to input pulse duration. That is, If the duration of pulse is greater than 50 milli-seconds, print the diastolic pressure as current pressure minus the pressure when pulse duration equal to 50 milli-seconds.

Below is the code I have written for printing the systolic and diastolic pressure instantly.

#include <LiquidCrystal.h>//Don't forget to enter this library

LiquidCrystal lcd(12, 11,  10, 9, 8, 7);

int analogInPin = A1;     // Analog input pin that the pressure sensor output is attached to

int pressure = 0;
int sensorValue = 0;        // value read from the pressure sensor via the amplifier stage

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

void loop() {
lcd.clear();
sensorValue = analogRead(analogInPin);

pressure = sensorValue*(0.9226)-267.7; //Pressure value according to sensor value
  lcd.setCursor(0,1);
  lcd.print("mmHg: ");
  lcd.print(pressure);
  delay(100);

}

I'm using a different method to note systolic as well as diastolic pressure values, like the stethoscope doing the job in conventional measurement method. The dual microphone arrangement will capture the sounds( korotkoff ) of blood flow. This sounds are processed (independent to arduino) by the external analog circuitry which outputs a 5VDC at every noticeable instant of pulse(during blood flow). This signal is then fed to a digital pin of arduino. Here, when the 5V signal reaches at the digial pin first, we note the systolic pressure as the pressure at the instant when the 5V signal is generated first. In the case of diastolic pressure, the generated 5V signal from the circuit is compared with an externally given unit step 5V using comparator. This compared signal output is fed to another digital pin of arduino, where the diastolic pressure is noted according to the input 5V pulse signal duration( Eg: If the duration is greater than  50ms ), the diastolic pressure is the pressure at which the pulse duration which is equal to 50ms).

I'm totally frustrated with remaining parts of code as mentioned.
Thank you in Advance..!!


texts:
I recently created a rfid project with the sensor rfid rc522. I used the instructions mentioned by this site and works perfectly. However, I intend this project to be battery supplied and I want to make the system use as low current as possible using the low power library. Well I need arduino UNO hibernate until an interrupt by the rfid is occured. Any proposals on how am I going to detect an interrupt by the rfid?

(PS) If there is any better battery saving library that can detect interrupts while keeping arduino slept, then feel free to propose it to me.

Thank you in advance.


texts: PCF8583 with Arduino delay of one second?

texts:
I'm trying to interface the RTC chip : PCF8583 with Arduino Uno. I'm using exactly the circuit shown below except instead of the variable capacitor near the crystal oscillator, I've used a 22pF ceramic capacitor.

For the programming side, I've used the Arduino PCF8583 library

The code I'm using is the following :

#include <Wire.h> // necessary, or the application won't build properly
#include <stdio.h>
#include <PCF8583.h>

/*
*  read/write serial interface to PCF8583 RTC via I2C interface
*
*  Arduino analog input 5 - I2C SCL (PCF8583 pin 6)
*  Arduino analog input 4 - I2C SDA (PCF8583 pin 5)
*
*  You can set the type by sending it YYMMddhhmmss;
*  the semicolon on the end tells it you're done...
*
*/

int correct_address = 0;
PCF8583 p (0xA0);
void setup(void){
 Serial.begin(9600);
 Serial.print("booting...");
 Serial.println(" done");
}

void loop(void){
 if(Serial.available() > 0){
   p.year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48)) + 2000;
   p.month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.day = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
   // Use of (byte) type casting and ascii math to achieve result.

   if(Serial.read() == ';'){
     Serial.println("setting date");
     p.set_time();
   }
 }

 p.get_time();
 char time[50];
 sprintf(time, "%02d/%02d/%02d %02d:%02d:%02d",
  p.year, p.month, p.day, p.hour, p.minute, p.second);
 Serial.println(time);
 delay(3000);
}

When setting the time and date, everything went ok, but when getting date/time the result is always HALF the period of the elapsed time, for example if I set the time 10:30 and I check it after 30 MINUTES, I get 10:45 instead of 11:00.

I really don't know if this is a hardware or software issue. If anybody has any idea about this issue, that would be highly appreciable !

Thanks in advance !


texts: DC Motor Speed Measurement using Rotary Encoder

texts:
I have written the following code to measure the speed of a unidirectional DC Motor.I have attempted to measure the time between successive interrupts in order to calculate speed.

boolean check;
boolean start;
unsigned int angle = 5;   //angle moved per encoder tick
unsigned long volatile time1;
unsigned long volatile time_11;
unsigned long interrupt_time;

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  pinMode(21, INPUT);  //Pin#21=interrupt pin, matched to interrupt#2
  attachInterrupt(digitalPinToInterrupt(2), speed, FALLING);
  time1 = 0;
  time_11 = 0;
  interrupt_time = 0;
  check = true;
  start = false;
  time_11 = millis(); //Start Clock
}

void loop() {
  if(time1 == interrupt_time && start) //Both times same , hence bool start.
  {
    if(check)
    {
      Serial.print(millis());  //Time taken to rise to steady speed.
      check = false;
    }
    Serial.println((angle/time1)*1000);   //Display Speed.
  }
  interrupt_time = time1;
  start = false;
  while(!start)
    {}
}

void speed(void) {
  start = true;
  time1 = millis()-time_11;
  time_11 = millis();
}

I want the code to be as efficient as possible.I have around 100 ticks per 360 degrees from my encoder.Is there any chance of "missing" an interrupt?


texts:
I am trying to use #define in Arduino IDE as I used to do in Atmel Studio like:

#define PROGRAM(N) void PROG_##N(void)

However I am getting a stray error because of the hashes, is there a way to implement this better?

Aim: PROGRAM(5){} becomes void PROG_5(void){} and so on.


texts: Module that can both detect Voltage (12V) and Control current

texts:
I need a module for ARDUINO that can both detect Voltage (12V) and Control current between 2 pins (12V), like a relay on another device
I have found relay modules to control pins and another module for 4-channel Voltage detection, but it seems like a lot of components and wiring.
Is there any module that can do both?


texts: Are pins 2 and 3 supposed to be connected?

texts:
I was playing with my arduino ad realized that pins 2 and 3 are somehow connected. When I press a button to for pin 2, it sets both pin 2 and pin 3 to HIGH even though nothing is connected to pin 3. The code I have is set up for pin 2 and mentions nothing about pin 3 but if i change the hardware to plug it into pin 3, it behaves as pin 2 would. None of the other pins do this. Is it supposed to be like this or is something wrong?

int switchState = 0;

const int led1 = 12;
const int led2 = 8;
const int led3 = 3;
const int button = 2;

void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(button, INPUT);
}

void loop() {
  switchState = digitalRead(button);
  if(switchState == HIGH){
    digitalWrite(led3, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led1, HIGH);
    delay(500);
    digitalWrite(led3, LOW);
    digitalWrite(led2, HIGH);
    digitalWrite(led1, LOW);
    delay(500);
  }
  else{
    digitalWrite(led3, HIGH);
    digitalWrite(led2, LOW);
    digitalWrite(led1, LOW);
  }
}


texts: Clocking issues while programming ATMEGA32U4-AU via USB bootloader

texts:
Hi,
I'm designing a custom board with the ATMEGA32U4, with a GPS receiver and LoRa radio and it is powered from a LiPo battery. Since I'll need to make hundreds of this board later on, I'd like to program them over USB. I started out from the Arduino Pro Micro schematic and I use an 8MHz crystal. I'm able to make use of the factory default USB bootloader and upload Arduino sketches using the dfu-programmer in Linux. My first problem was that the blink example didn't really blink at 0.5Hz rate(delay(1000) wasn't 1sec), but much-much slower. No worries, reduce the delay a little bit. However, when I want to communicate with the GPS, the from the transmitted signal, I can see that the baud rate is not correct. I suspect that the clock settings are not correct. I read that these can be changed with the help of fuses, but as far as I know, they cannot be modified using only USB , I need a programmer for that, which I'd like to avoid.
(Correct me if I'm wrong here)
So my question is, how do I set up the MCU correctly, so that it runs from the 8MHz external or 8MHz internal clock using only USB? Is it even possible?


texts: Changing the order of blinking LEDs with the push of a button

texts:
I am new to Arduino and I have written code that makes 3 LEDs blink while the push button is off, so the lights are blinking from left to right (1,0,0)(0,1,0)(0,0,1) and then repeat from left to right.

Now I am trying to modify this code so that whenever the system receives a High from the switch it reverses the order, so it should start blinking from right to left and keep blinking that way until I press the push button and then return to left to right.

I hope my issue is clear. I only know how to use the if & else.

Here is my code:

int switchState;
int switchst = LOW;
int d=LOW;

void setup() {
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(2,INPUT);
}

void loop() {
  switchState = digitalRead(2);
  if (switchState == HIGH) {
    d= ~d;
    if(d==LOW) {
    digitalWrite(3,~switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,switchst);
    delay(200);
    digitalWrite(3,switchst);
    digitalWrite(4,~switchst);
    digitalWrite(5,switchst);
    delay(200);
    digitalWrite(3,switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,~switchst);
    delay(200);
  }  else {
    digitalWrite(3,switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,~switchst);
    delay(200);
    digitalWrite(3,switchst);
    digitalWrite(4,~switchst);
    digitalWrite(5,switchst);
    delay(200);
    digitalWrite(3,~switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,switchst);
    delay(200);
  }
}

The problem with this code is that it doesn't keep blinking if I release the push button.

This is the old code. It only goes from left to right and keeps repeating.

int switchState = 0;
int switchst = LOW;

void setup() {
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(2,INPUT);
}

void loop() {
  switchState = digitalRead(2);
  if (switchState == switchst) {
    digitalWrite(3,~switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,switchst);
    delay(200);
    digitalWrite(3,switchst);
    digitalWrite(4,~switchst);
    digitalWrite(5,switchst);
    delay(200);
    digitalWrite(3,switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,~switchst);
    delay(200);
  } else {
    digitalWrite(3,switchst);
    digitalWrite(4,switchst);
    digitalWrite(5,switchst);
  }
}


texts: Reading sensor with current ouput with Arduino

texts:
I am having diffuclt times with this sensor, so I kndliy ask for your help!
The sensor is named "SPUVA-CS-C3535-A", datasheet here.
The sensor I use (cs3535) has just two pins (+ and -).
From my undesrstanding the ouput is a current corresponding on the UV light exposed to this sensor.
Max value of the current is difficult to understand from the datasheet that also do not have a typical suggested circuit. It seems that a medium value is 200nA, it seems really low!
I have connected (+) of the sensor to 3.3V, (-) of the sensor to A0, and a 220ohm resistor from A0 to Gnd. But readings are always 0.
Any help would be really appreciated! Thanks


texts: Programming 328PB from Arduino IDE using Atmel-ICE to ICSP port

texts:
Updated question.  The original question was based on using 'Upload' from the Arduino IDE, instead of 'Upload Using Programmer' under 'Sketch'.  The problem in getting the Atmel-ICE to work with Arduino IDE appears now to be one of incorrect ICE drivers loaded when I installed Atmel Studio.
Arduino requires libusb-win drivers, which can be checked with Zadig.   Available here: https://zadig.akeo.ie/
This problem was 99% solved (with help) by selecting  and the libusb-win32 driver using Zadig.   I say 99% solved, because my program now loads and runs! , but I do get the red 'X' there as the WCID status.
Apologies if this amendment to the original question is not in the correct context, this is new to me.   Thank You.
Jaco


texts: Controlling 2WD car chassis with PS3 controller

texts:
I'm having trouble with controlling my car with the PS3 joystick, and there hasn't been any example codes out there. I'm using;

PS3USB library from USB_Host_shield_2.0 library
Freetronics H Bridge shield http://www.freetronics.com.au/collections/shields/products/hbridge-dual-channel-h-bridge-motor-driver-shield#.VXMqXUJJmgM

This is my code;

include <PS3USB.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

int motora1 = 4;
int motora2 = 7;
int motoraspeed = 6;
int motorb1 = 3;
int motorb2 = 2;
int motorbspeed = 5;

void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nPS3 USB Library Started"));
  pinMode(motora1, OUTPUT);
  pinMode(motora2, OUTPUT);
  pinMode(motoraspeed, OUTPUT);
  pinMode(motorb1, OUTPUT);
  pinMode(motorb2, OUTPUT);
  pinMode(motorbspeed, OUTPUT);
  delay(5000);
}

void loop() {
  Usb.Task();

  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    //go forward
     if (PS3.getAnalogHat(LeftHatY) == 0) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
         digitalWrite(motora1, HIGH);
          digitalWrite(motora2, LOW);
          digitalWrite(motoraspeed, 255);
        digitalWrite(motorb1, HIGH);
        digitalWrite(motorb2, LOW);
        digitalWrite(motorbspeed, 255);
}

//go backward
if (PS3.getAnalogHat(LeftHatY) == 255) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
           digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 255);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 255);
}

//turn left
if (PS3.getAnalogHat(RightHatX) == 0) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
           digitalWrite(motora1, HIGH);
  digitalWrite(motora2, LOW);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 200);
}

   //turn right
   if (PS3.getAnalogHat(RightHatX) == 255) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
          digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, HIGH);
  digitalWrite(motorb2, LOW);
  digitalWrite(motorbspeed, 200);
}

As of now, when I look at my code in the serial monitor, I get the following;

LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127

The numbers adjust as I'm moving the joystick around but just keeps going even though I'm not moving the joystick around. Any help would be appreciated, thanks


texts:
I'm doing a project for school using Arduino to make a catapult, but I have this error that I didn't have the previous week.

Can anyone see the program and search where is the error?

#include <Servo.h> //libreria necesaria para utilizar el Servo

Servo catac; //motor de giro continuo utilizado

int ledPin = 13; //led conectado a agujero 13
int button = 8; //boton conectado a agujero 8
int estado = 0; //varaible que permite saber el estado del boton

void setup()
{
    pinMode(ledPin,OUTPUT);
    pinMode(button,INPUT);
    catac.attach(12); // servo unido al agujero 12
    catac.write(180); //coloca al servo en 180 grados
}

void loop()
{
    estado = digitalRead(button); //la variable obtiene el estado del boton
    if(estado == LOW)
    {
        digitalWrite(ledPin,HIGH); //prende led
        catac.write(70); //servo levanta a 70 grados la catapulta
        delay(500);
        digitalWrite(ledPin,LOW); //apaga led
        catac.write(180); //servo coloca a la catapulta en posicion original
    }
}

Error:

cataoukta:6: error: stray '\' in program
cataoukta:8: error: stray '\' in program
cataoukta:9: error: stray '\' in program
cataoukta:10: error: stray '\' in program
cataoukta:13: error: stray '\' in program
cataoukta:14: error: stray '\' in program
cataoukta:15: error: stray '\' in program
cataoukta:16: error: stray '\' in program
cataoukta:20: error: stray '\' in program
cataoukta:22: error: stray '\' in program
cataoukta:23: error: stray '\' in program
cataoukta:24: error: stray '\' in program
cataoukta:25: error: stray '\' in program
cataoukta:26: error: stray '\' in program
cataoukta:9: error: expected constructor, destructor, or type conversion before 'void'
cataoukta:6: error: expected initializer before 'u037e'
cataoukta.ino: In function 'void loop()':
cataoukta:20: error: 'estado' was not declared in this scope
cataoukta:20: error: 'button' was not declared in this scope
cataoukta:20: error: expected `;' before 'u037e'


texts:
I'm trying to make the transition from coding in the Arduino language to AVR-C, but I'm having some issues with my microcontrollers.

I don't have an ISP, so I'm using one of my Arduino UNOs with the ArduinoISP sketch. The problem is that when I try to run avrdude it gives me this error:

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

However, when I try to run the command with the sugested -F it uploads the code to the Arduino UNO I'm using as an ISP instead of the ATmega328p on my breadboard.

Does anyone have any idea about whats going on here, or how to fix it?


texts:
I have a 5V (5.3V) switching transformer that goes to a 7805 voltage regulator and powers Arduino, Arduino controls 4 relays using BJTs. those relays getting power directly from the same power source.

Arduino and it's modules + LCD uses ~40ma, each relay consumes 70ma. total current is around 350ma lets say 400ma.

The problem is 5V isn't enough to power Arduino, modules, sensors and relays. LCD gets very dim etc...

it works with 9V but 7805 gets really hot ~70 centigrade while having a heat sink on!

If i remove the 7805 and switching power burns or something bad happens then there's nothing in between to protect the Arduino!

What's the solution for this situation?

EDIT: for anyone who may have the same problem; I solved the problem with using a proper switching power salvaged from an old USB type-C charger and removed the 7805 voltage regulator, there's no heat anymore and it's working perfectly.


texts: Possible to "inline" PROGMEM strings into a structure array initialization?

texts:
I have the following structure:

struct inst_t {
    const char *s1;
    const char *s2;
};

I'd like to initialize a constant array of this structure like this where all the strings are PROGMEM'ed:

const char START[] PROGMEM = "START";
const char ATZ[] PROGMEM = "ATZ";
const char ATE0[] PROGMEM = "ATE0";
const char OK[] PROGMEM = "OK";

static inst_t insts[] = {
    { START,      NULL },
    { ATZ,        OK },
    { ATE0,       OK }
};

You can see there is a lot of duplication here though. Is there anyway way I can inline the PROGMEM strings directly into this array initialization without separately declaring each string as being in PROGMEM?


texts: Knowing if ESP32 wakes up itself or manually

texts:
I have a project where I put an ESP32 to deep sleep for a certain amount of time, eg: 1h
To be able to self-awaken a cable must be connected from GPIO 16 to the reset pin, so basically the ESP pulls down pin 16 and causes itself to reset.
I also need the possibility to manually waken up the ESP, so in parallel to this cable I connect a button to GND, so I can manually reset the ESP and waken it up.
However I need to be able to tell if the ESP has awaken itself because one hour has passed or if it has been manually awaken.
I cannot connect the ESP to a internet time provider to check the time, so my first though wasto connect the button also to an input and read it when the ESP starts.
However the ESP won't start until the button forcing RST low is released and then it's too late to read it and see if it was pressed.
Is there a way that I can tell if the ESP was manually reset or if it woke up by itself?


texts: I am working on a project that needs data to be stored in cloud db so that I can access the data in a mobile application. For database I have considered Firebase. I am following the following link. But when i try to install the libraries i am getting No such file or directory found errors for memory, queue, Firebase.h, vector, functional, utilities (not all but different packages shows different errors). I tried downloading different packages from github. But still had the errors. Where can I find the correct working program? Thanks in advance.


texts:
I am trying to get values for two ping sensors, but am not getting any returns, can someone help me edit my code?

Code

void setup()
{
  Serial.begin(9600);
  pingRange(2);
  pingRange(3);
}

void loop(){
}

  long pingRange (int pingPin)

{
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  return microsecondsToCentimeters(pulseIn(pingPin, HIGH));
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}


texts: multiple relays not triggering correctly

texts:
quick description of the sketch: its a clap on/off relay that turns on only when it's dark.

Cannot seem to get the relays to stay off. What happens is they are off by default then when I do the double clap to turn them on that works, after this I double clap to turn them off and then go off then immediately go on again. I can get a single relay to work perfectly but when I uncomment the rest there seems to be a problem.

I am assuming it has something to do with the delay for the clap sensor, but I am not entirely sure-- I have tried quite a few things to try to resolve it but am really lost as to why this might be happening. ideas?

int soundSensor = A2;
int relay = A0;
int relay2 = A3;
int relay3 = A4;
int relay4 = A5;
int claps = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
boolean clapState = false;
int doubleClap = 0;

//Light sensor
int photocellPin = A1;
int photocellReading;
int LEDbrightness;

//int delayValue = 100;
int photoSensor = 0;

void setup() {
  pinMode(soundSensor, INPUT);
  pinMode(relay, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  /////////////
  // photo sensor
  ////////////////////
  photocellReading = analogRead(photocellPin);
  photocellReading = 1023 - photocellReading;
  LEDbrightness = map(photocellReading, 0, 1023, 0, 255);

  if(photocellReading > 500){
      photoSensor = 0;
  }
  if(photocellReading < 500){
    photoSensor = 1;
  }

  /////////////
  // clap sensor
  /////////////////////
  int sensorState = digitalRead(soundSensor);
  //erial.println(sensorState);
  if (sensorState == 1)
  {
    if (claps == 0)
    {
      detectionSpanInitial = detectionSpan = millis();
      claps++;
    }
    else if (claps > 0 && millis()-detectionSpan >= 50)
    {
      detectionSpan = millis();
      claps++;
    }
  }

  if (millis()-detectionSpanInitial >= 500)
  {
    if (claps == 2)
    {
      if (doubleClap == 0)
        {
          doubleClap = 1;
        }
        else if (doubleClap == 1)
        {
          doubleClap = 0;
        }
    }
    claps = 0;
  }

  if(doubleClap == 1 && photoSensor == 0){
    digitalWrite(relay, LOW);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, LOW);
    Serial.println("off");

  }
  else{
    digitalWrite(relay, HIGH);
    digitalWrite(relay2, HIGH);
    digitalWrite(relay3, HIGH);
    digitalWrite(relay4, HIGH);
    Serial.println("on");
  };

}


texts: What pin is the external interrupt #0 for an arduino micro?

texts: I'm putting an MPU6050 on an arduino Micro but the interrupt is different than the arduino uno. The external interrupt #0 pin on an arduino uno is pin 2 but its not pin 2 on an arduino micro. So I'm trying to figure out what pin it is on an arduino micro


texts:
so I'm making an animated LED brake light using arduino nano, similar to this: https://www.youtube.com/watch?v=d5Ohzg3JKq0&ab_channel=IMEEMADE
I have 18 channels, with differet amount of series LEDs and resistor. All LED + are wired together, intended for 14.5V input, with individual resistor after the last LED cathode:
14.5V -> + LED - -> R -> GND
I have some channels with 1 LED, 2 LED and 4 LED, all tuned with different resistors so that each channel "pulls" ~20mA at 14.5V. 12V works fine as well just ever so slightly dimmer. On a power supply, I can ground any channel without cross talk, or ground all and all LEDs light up evenly (from what my eyes can tell).
I had originally planned on providing 5V input to the arduino using a buck converter and sinking each channel to a digital output pin (D2-D19 or D2-D13 + A0-A5). I ended up providing 12V to Vin and 12V to the LEDs as well as the arduino did not work at all as expected with 14.5V to the LEDs and 12V to the Vin.
My problem is that with this setup, no matter what I do in code, when the arduino is connected to Vin and ground, some LEDs are always lit dimly (D2-D13 oddly). They do indeed get brighter when pinMode is set to OUTPUT and digitalWrite({pin}, LOW) is called. But writing HIGH or setting pinMode to INPUT doesn't turn them off, just leaves them dim. I've tried adjusting Vin between 7-12V, setting the regulator to 5V and connecting directly to 5V. No change in behavior. Only thing that gets the LEDs to stop lighting dimly is lowering input voltage to the LEDs themselves. But then I don't have enough to drive the 4 series LED channels...
I know this can work because in the video I linked, there are 4 series LEDs driven in the same manner (though red, I'm using white), but not much is explained with the use of the arduino.
What am I doing wrong or how can I make this work? I need at least 12V to the LED board to ensure the 4 series channels light up properly. I've already maxed out the digital channels on the arduino nano from what I've read, so I can't use one as input (instead of Vin or 5V) if that matters or split the 4 series into 2 channels, etc...
Thanks in advance!


texts: How to calibrate an inclined MPU 6050 on Arduino?

texts:
I'm trying to use the MPU 6050 sensor (gyroscope + accelerometer) with my Arduino UNO to get some data when walking, running and making some other moves while carrying it. The problem is that my welding makes the sensor stay inclined. The first photo is from the sensor and the second from the 3-D visualization using the Processing IDE:

Is there a way to calibrate the sensor to "act as if it were straight" based on its reads when inclined on the breadboard (as shown in the photo)? I am still a beginner with Arduino, so sorry if this is a silly question/problem.


texts: I was wondering if it is possible to send commands through the OBD-II on my car via an Arduino Uno Rev 3 with a CAN-BUS Shield from SEEDStudio. I am just going for basic functions i.e. lock control, window control, lights nothing really outside of those basic functions. My shield is currently in the mail and I was hoping anyone could shed light as to if this is even possible. My car model is a 2004 Mini Cooper S. Thanks.


texts:
I'm working with the Arduino Due ans I used the following code:

// period of pulse accumulation and serial output, milliseconds
#define MainPeriod 100
long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

void setup()
{
  Serial.begin(19200);
  attachInterrupt(6, myinthandler, RISING);
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= MainPeriod)
  {
    previousMillis = currentMillis;
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);
    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(currentMillis);
    Serial.print(" "); // separator!
    Serial.print(Freq);
    Serial.print(" ");
    Serial.print(_pulsecount);
    Serial.print(" ");
    Serial.println(_duration);
  }
}

void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

to measure the frequency.

I can measure frequencies higher than 1.5kHz accurately, but I can't seem to measure lower frequencies.

How can I measure lower frequencies, say 400Hz and above?

Thanks.


texts: Cannot program Mega2560 using Atmel Studio 6.2 and avrdude

texts:
So I will admit that I am a noob to Arduino. I have some experience programming microcontrollers, and that was back in the day (about 4 years ago - such as the Freescale 68HC12) so up until this point I thought I was experienced enough to get this Arduino Mega2560 rocking with AVR C using Atmel Studio and avrdude by lunch...

Wrong.

I believe I'm getting held up at what's possible...

What I want to accomplish: Write and compile a program in AVR C within Atmel studio. Use the hex file that was built and download that to the Mega. (Keep in mind I was planning on using USB and Arduino as my programmer between PC and ATMega2560 as per this gentleman's example... https://balau82.wordpress.com/2011/03/29/programming-arduino-uno-in-pure-c/ -- however, I was not using his code and he was compiling using avr-gcc...)

Question: Is this possible?

Using avrdude when attempting to write the file I get this message... (and my blinking LED goes dark for a few seconds before returning to normal operation)

When I searched the internet for this issue it was never related to avrdude, but rather a communications issue. I've verified my bootloader is still ok (uploaded other sketches with no issues).

It's certain that I am missing something minor, but this is my first day using Arduino so go easy on me!

Thanks


texts: Arduino MotorShield code running but not motors

texts:
I have a motor shield V2 on my Arduino, i compile the codes just fine and i'm trying to just run the example dc motor test. The code compiles the serial is printing out the "tick tock ...." but the motors are not running. They ran once before on my mac though.

Using a 9v battery to power a basic Dc motor.

I'm using the right ports on pc. Same exact port for motor as the code tells. I'm not sure where i am wrong. TYIA


texts: How can I get a unique address for all my Arduino boards while in RS485?

texts:
My attempt is to know how to identify the board I'll be sending parameters to in a serial connection like rs485.  I'm asking because I will have about 11 or so mcu's as "Rx slaves" while my pc is the Master "Tx". I want to know how my code block is being sent to a specific board will be received by just that board and not all the other boards connected to that Rx port COM?

If I send 'LT2|LP3|LM5|LR4|LI6' and I want that to be for one specific Arduino, I don't want all the other 10 arduinos to take those parameters in this serial Rx line.

@Federico Fissore you mentioned in another post "Some boards, when connected to a computer, publish their serial number. My Arduino Uno R3 says"

[16818.451423] usb 3-2: SerialNumber: 85235353137351E02242

how and where can i find this info?


texts: Connecting an Arduino to a servo with an external power supply

texts:
I have purchased an MG995 servo (4.8-7.2V operating voltage, 170MA no load operating current draw) and will power this using a 5V, 2A mains plug pack. Do I need a breadboard to connect this with my Arduino (which will itself be powered through its usb port)? Or is it possible to connect the servo with the Arduino directly?

If it's possible to connect it directly, which pins should I be using on the Arduino? Will it look something like this:

except the red wire (and black wire?) connects to the external power supply?

Any answers (or links to relevant tutorials which have all three of these components) would be welcome. Thanks!


texts: Rc switch library display received values only one times using serial monitor

texts:
I use Rc switch library to transmit and receive data. It works fine.
The part that sends the data is as follows :
#include <Arduino.h>
#include <RCSwitch.h>

RCSwitch transmitter = RCSwitch();

void setup()
{
    Serial.begin(9600);
    transmitter.enableTransmit(10);
}

void loop()
{
    /* Send data in binary */

    // Go right
    transmitter.send("010101010101010100000011");
    delay(1000);

    // Go left
    transmitter.send("010101010101010100001100");
    delay(1000);
}

And the receiving part is like this:
#include <RCSwitch.h>

RCSwitch receiver = RCSwitch();
int rightLED = 4;
int leftLED = 7;
unsigned long receivedValue;
unsigned long goRight = 5592323;
unsigned long goLeft = 5592332;

void setup()
{
    Serial.begin(9600);
    receiver.enableReceive(0); // Receiver on interrupt 0
    pinMode(rightLED, OUTPUT);
    pinMode(leftLED, OUTPUT);
}

void moveRight()
{
    Serial.println("I'm going right");
}

void moveLeft()
{
    Serial.println("I'm going left");
}

void loop()
{
    if (receiver.available())
    {
        receivedValue = receiver.getReceivedValue();
        if (receivedValue == goRight)
        {
            moveRight();
        }
        if (receivedValue == goLeft)
        {
            moveLeft();
        }
        receiver.resetAvailable();
    }
}

The problem is, when I open a serial monitor and look the output of the received values moveRight and moveLeft functions are called multiple times.
I'm going right
I'm going right
I'm going right
I'm going right
I'm going left
I'm going left
I'm going left
I'm going left
I'm going right
I'm going right
I'm going right
I'm going right

What kind of change should I do in the receiver part so that moveRight and moveLeft functions are called only once.
I'm going right
I'm going left
I'm going right


texts:
I am trying to write a program to control 4 motors through the Serial port. I planned on achieving this by sending the motors' speed and direction instructions as a string, which is then converted into numerical values that represent speed and direction. Unfortunately, the conversion process is not working and my motors will not spin.

int motorGroup1_Direction = 13;
int motorGroup1_Speed = 12;

int motorGroup2_Direction = 11;
int motorGroup2_Speed = 10;

int motorGroup3_Direction = 9;
int motorGroup3_Speed = 8;

int motorGroup4_Direction = 7;
int motorGroup4_Speed = 6;

String command; //First digit is for direction, the next 3 digits are for speed. A space acts a delimiter, repeat for the
//For the next three motors
char hold;
char letter;
char send[8];

void setup() {
  Serial.begin(9600);
  pinMode(motorGroup1_Direction, OUTPUT);

  pinMode(motorGroup1_Speed, OUTPUT);

  pinMode(motorGroup2_Direction, OUTPUT);
  pinMode(motorGroup2_Speed, OUTPUT);

  pinMode(motorGroup3_Direction, OUTPUT);
  pinMode(motorGroup3_Speed, OUTPUT);

  pinMode(motorGroup4_Direction, OUTPUT);
  pinMode(motorGroup4_Speed, OUTPUT);
}

void loop() {
  int trackParse = 0;
  int trackString = 0;

  while (Serial.available() > 0) {
    hold = Serial.read();

    if (hold == ' ') {

      send[trackParse] = (char)command.toInt();
      Serial.write(send[trackParse]);
      trackParse++;
      delay(2);
    }
    else {
      command[trackString] = hold;
      trackString++;
      delay(2);
    }
  }

  digitalWrite(motorGroup1_Direction, send[0]);
  Serial.println(send[0]);

  analogWrite(motorGroup1_Speed, send[1]);
  Serial.println(send[1]);

  digitalWrite(motorGroup2_Direction, send[2]);
  Serial.println(send[2]);

  analogWrite(motorGroup2_Speed, send[3]);
  Serial.println(send[3]);

  digitalWrite(motorGroup3_Direction, send[4]);
  Serial.println(send[4]);

  analogWrite(motorGroup3_Speed, send[5]);
  Serial.println(send[5]);

  digitalWrite(motorGroup4_Direction, send[6]);
  Serial.println(send[6]);

  analogWrite(motorGroup4_Speed, send[7]);
  Serial.println(send[7]);

}


texts: Recursive list of files on SD card with indexing

texts:
I'm trying to create a way to make a recursive list of the long name of files from an SD card with an index so that I call the file I'd like. Right now, I'm having trouble getting the files to list (!CFile.open() is always returning true regardless of the number of files on the card)

#include<SPI.h>
#include "SdFat.h"
#include "FreeStack.h"

// SD card chip select pin.
const uint8_t SD_CS_PIN = 10;

SdFat sd;
SdFile file;
SdFile dirFile;

// Number of files found.
uint16_t numberOfFiles = 0;

// Position of file's directory entry.
uint16_t dirIndex[300];
//**Is there a way I make an array without allocating the size here?
//------------------------------------------------------------------------------
void setup()
{
  Serial.begin(38400);
  while (!Serial) {}

  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.
  if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50)))
  {
    sd.initErrorHalt();
  }
  if (dirFile.open("/", O_READ))
  {
  Serial.print("Reading: ");
  Serial.println();
  printDirectory(&dirFile, 0);
  }
}
void printDirectory (SdFile* CFile, int numTabs)
{
  while (file.openNext(CFile, O_READ))
  {
    if (file.isHidden()||file.)
    {
      //file hidden, skip
    }
    else
    {
      for (uint8_t i = 0; i < numTabs; i++)
      {
        Serial.print('\t');
      }
      if (file.isSubDir())
      {
        file.printName(&Serial);
        Serial.println();
        printDirectory(&file, numTabs++);
      }
      else
      {
        // Save dirIndex of file in directory.
        dirIndex[numberOfFiles] = file.dirIndex();
        // Print the file number and name.
        Serial.print(numberOfFiles++);
        Serial.write(' ');
        file.printName(&Serial);
        Serial.println();
      }
    }
  file.close();
  }

If someone could help me catch what I've got wrong, I'd like to get a second opinion.

Edit: Updated Code

Edit 2: I'm now getting the first level, but the second level is not printing I think I may be doing something wrong with pointers?


texts: How to pause Arduino for 1 millisecond through MATLAB?

texts:
I have been able to connect MATLAB to my Uno with this line of code: a = arduino('COM4'); through this package: Matlab support package for Arduino.

Right now, MATLAB is my main script that will synchronize all the components [like the Arduino].

I am able to send pulses to my stepper-motor just by using:

void loop() {
    digitalWrite(2, HIGH);
    delay(1);
    digitalWrite(2, LOW);
    delay(1);
}

This works fine, and will make the motor move about once every 2 milliseconds. My problem is that I cannot find a way to produce this same delay through MATLAB's interface. I do know that MATLAB has a pause() function, but when I set up a loop in MATLAB like this:

a = arduino('COM4');
for m = 1:400
    a.digitalWrite(2, 1);
    pause(0.001);
    a.digitalWrite(2, 0);
    pause(0.001);
end

Each step takes WAY longer - about 200 milliseconds each.

What are other options for creating the pause between digital High / Low being sent to the Arduino? It would be nice if I could control the outcome from Matlab, through Arduino.


texts: How to send multi variable information over serial?

texts: I would like to send information between my Arduino and my computer. Is there a way to send multiple variables from one Arduino? If so, how would I go about separating the variables?


texts: Sending Multiple Information from BNO055 IMU to BridgeClient on Yun

texts:
I have an Arduino Yun which is interfaces via I2C to a Adafruit BNO055 breakout board.

My Aim is to use Python Flask in conjunction with BridgeServer and BridgeClient to obtain the Sensor Information from the ATmega32u4 microcontroller to the Microprocessor and use HTML5 Server Side Event (SSE) to display live sensor information on Network interfaces.

I would like to show the Euler angles and Linear Acceleration values:

heading
pitch
roll
linear_accerlation_x
linear_acceleration_y
linear_acceleration_z

An Example of similar concept can be obtained from Smart Measuring Cup by Adafruit. However, in the code sketch the user sends only one value :

BridgeClient client;
....
client.println(volume, 5);

And at the Python Flask end the code opens up a socket and uses makefile() method to read value

def yunserver_sse():
    try:
        # Connect to YunServer instance that's listening on localhost.
        soc = socket.create_connection(('localhost', 5678))
        socfile = soc.makefile()
        while True:
            # Get data from server.
            line = socfile.readline()
            # Stop if the server closed the connection.
            if not line:
                raise StopIteration
            # Send the data to the web page in the server sent event format.
            yield 'data: {0}\n\n'.format(line)
            # Sleep so the CPU isn't consumed by this thread.
            time.sleep(0)
    except socket.error:
        # Error connecting to socket. Raise StopIteration to quit.
raise StopIteration

Instead of sending just one measured parameter how can I send all above mentioned 6 at the same time?

note

I tried using ArduinoJson library but I find it difficult to parse the JSON on the Python Flask end as readline() expects a \n at the end of the string.


texts: Is it possible to connect two Ethernet shields to arduino? And if yes, how can I distinguish them in the code?


texts:
The arduino IDE can't seem to find the wire.h file when i'm using the new liquid crystal library. Does anyone know how to solve this? here is the code i'm using and the error message:

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/ /*-----( Declare objects )-----*/ // set the LCD address to 0x27 for a 16 chars 2 line display // A FEW use address 0x3F // Set the pins on the I2C chip used for LCD connections: //                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Variables )-----*/ //NONE

void setup()   /*----( SETUP: RUNS ONCE )----*/ {   Serial.begin(9600);  // Used to type in characters

  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight

// ------- Quick 3 blinks of backlight  -------------   for(int i = 0; i< 3; i++)   {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);   }   lcd.backlight(); // finish with backlight on

//-------- Write characters on the display ------------------ // NOTE: Cursor Position: (CHAR, LINE) start at 0     lcd.setCursor(0,0); //Start at character 4 on line 0   lcd.print("Hello, world!");   delay(1000);   lcd.setCursor(0,1);   lcd.print("HI!YourDuino.com");   delay(8000);

// Wait and then tell user they can start the Serial Monitor and type in characters to // Display. (Set Serial Monitor option to "No Line Ending")   lcd.clear();   lcd.setCursor(0,0); //Start at character 0 on line 0   lcd.print("Use Serial Mon");   lcd.setCursor(0,1);   lcd.print("Type to display");

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/ {   {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }   }

}/* --(end main loop )-- */

Here is the compiler output

  Arduino: 1.6.7 (Windows 10), Board: "Arduino Nano, ATmega328"

  C:\Users\martin\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp:35:26:
  fatal error: ../Wire/Wire.h: No such file or directory

  #include <../Wire/Wire.h>

                      ^

  compilation terminated.

  exit status 1 Error compiling.

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


texts:
I'm trying to connect my ESP32 to this CO2 measurement device. I admit I am clueless about connecting devices with independent power sources to one another.
I connected ground to ground and CLK to PIN2. Just to be on the safe side, I put a resistor between CLK and PIN2.
I started with 4.8KOhm of resistance. ESP's ADC measured 2.1V and it seemed fine. But when I switched to 1K resistor, trying to get closer to the level of "logical 1" (the way I understand it), something unexpected happened. ADC measured 2.65V, which is still beyond 3.3V ESP should be able to handle, and the built-in LED lit up, although nothing in my sketch called for it.
Though the configuration worked stably for some minutes while I was testing it, and no smoke appeared, I am afraid the LED lighting spontaneously might be a sign of an electrical breakdown.
The both devices are sitting on the same USB hub.
Here is the sketch I am using:
#define PIN_CLOCK  2

void setup() {
  pinMode(PIN_CLOCK, INPUT);
  Serial.begin(4800);
}

bool last = 0;

void loop() {
  int x = analogRead(PIN_CLOCK);
  bool val = x > 1500;
  if (last != val)
    Serial.println(x*3.3/4095);
    last = val;
  }

Can someone explain why the LED lights up?
Can someone recommend a good article/video on basic rules about interconnecting such devices?


texts: Detect certain characters and if not a consequence

texts:
How can I program in Arduino Uno a serial.available that will detect some chars that aren't supposed to belong in a list of options, like this:

void lerRespostaUtilizador(){
  if(Serial.available('s' && 'v' && 'r'){
    Serial.println("Podes visualizar: (s)inais de controlo, (v)ariaveis do sistema e conteudo de (r)egistos.")
  }
  switch(Serial.read()){
    case 's': // Mostrar sinais de controlo
      mostrarSinais();
      Serial.println("Podes visualizar ainda: (v)ariaveis do sistema e conteudo de (r)egistos.");
      Serial.println("");
      break;
    case 'v': // Mostrar variáveis do sistema
      mostrarVariaveis();
      Serial.println("Podes visualizar ainda: (s)inais de controlo e conteudo de (r)egistos.");
      Serial.println("");
      break;
    case 'r': // Mostrar conteúdo de registos
      mostrarRegistos();
      Serial.println("Podes visualizar ainda: (s)inais de controlo e (v)ariaveis do sistema.");
      Serial.println("");
      break;
    }
}

What I want is if the user inserts some chars that aren't 's', 'v' or 'r', a message will appear saying what they can insert to obtain certain results.


texts: Is there a better way to combine if statement with an ISR?

texts:
In my sketch when an interrupt gets triggered, a state variable is toggled from high to low and vice versa. Depending upon the variable state I have an if statement in the main loop that will call alarm_On function if state is high and the else part of the conditional statement will call alarm_Off function if the interrupt is triggered a second time. Thus I want this if condition to run only when the interrupt is triggered. In all other circumstances I want to run other code but if it concerns the same components e.g. the leds, the other code doesn't execute. If it's not a common component then it works fine. How can I overcome this "common component" issue?

 // Analog Input devices
# define humiditySensor A5

// Alarm input
# define alarmButton 2 // Pushbutton

// Output Devices
# define redLed 10
# define yellowLed 11
# define greenLed 12
# define waterPump 9 // LED on relay
# define spk 5

// Variables
volatile byte alarm = LOW;

void setup() {
  pinMode (alarmButton, INPUT);
  pinMode (redLed, OUTPUT);
  pinMode (yellowLed, OUTPUT);
  pinMode (greenLed, OUTPUT);
  pinMode (waterPump, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(alarmButton), ISR_Alarm, RISING);
  Serial.begin(9600);
}

void loop() {
  if (alarm == 1) {
    alarm_On();
  } else if (alarm == 0) {
    alarm_Off();
  }
  int humVal = analogRead(humiditySensor);
  Serial.println(humVal);
  if (humVal >= 500) {
    digitalWrite(redLed, HIGH);
  } else {
    digitalWrite(redLed, LOW);
  }
} // void loop

void ISR_Alarm () {
  alarm = !alarm;  // toggle alarm function if pushed more than once
}

void alarm_On() {
  tone (spk, 100);
  digitalWrite(waterPump, HIGH);
  static byte ledState = LOW;
  static unsigned long oldTime = 0;
  if (millis() - oldTime >= 250) { // loop to blink leds in emergency
    oldTime = millis();
    if (ledState == LOW) {
      digitalWrite(redLed, HIGH);
      digitalWrite(yellowLed, HIGH);
      digitalWrite(greenLed, HIGH);
      ledState = HIGH;
    } else {
      digitalWrite(redLed, LOW);
      digitalWrite(yellowLed, LOW);
      digitalWrite(greenLed, LOW);
      ledState = LOW;
    }
  }
} // end of alarm on function

void alarm_Off () {
  noTone (spk);
  digitalWrite(redLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(waterPump, LOW);
} // end of alarm off function

void high_Humidity() {
  digitalWrite(waterPump, HIGH);
}

void low_Humidity() {
  digitalWrite(waterPump, LOW);
}


texts: Why does my Esplora only send serial data when the serial monitor is on?

texts:
I've noticed that when I'm sending serial data to my computer's serial monitor, the tx light only lights up when the serial monitor is open.  When I close the monitor, it seems to stop sending data.  Is this a normal thing?

The reason I ask is because I'm really trying to send data from my esplora to an uno, and I notice that despite (1) having the grounds of both arduinos connected and (2) connecting the esplora's tx pin (reset_lcd) to the uno's rx pin (pin 0) and the esplora's rx pin (dc_lcd) to the uno's tx pin (pin 1), the tx light on the esplora and the rx pin on the uno don't light up at all.

What could be the problem?


texts: Connect ethernet cable wires directly to pins

texts:
Is it possible to uncrimp a RJ45 plug and connect the wires directly to the Arduino pins? I guess I'd have to decrypt the ethernet signal then on my Arduino which might not have enough processing power at command for such a task.

I don't want to do it with an Ethernet shield, so please don't link any in the answers.