texts: AnalogWrite only working for one pin of RGB LED

texts:
I'm working on some code for a Nerf blaster with an LED indicator light. When attempting to use analogWrite to PWM my LED pins, only one pin (blue) behaves as expected and dims down. The other two (red, green) don't light up at all. The LED is confirmed working and the Arduino.cc fade example works fine on each pin individually when testing. Here is the code:

#include <ClickButton.h>
#include <Servo.h>

Servo esc;

ClickButton rev(6, LOW, CLICKBTN_PULLUP);
ClickButton mode(7, LOW, CLICKBTN_PULLUP);
ClickButton trig(8, LOW, CLICKBTN_PULLUP);

int flyPin = 2;
int escPin = 3;
int pushPhasePin = 4;
int pushSpeedPin = 5;
int RED = 9;
int GREEN = 10;
int BLUE = 11;

int m = 1;
int singleShot = 100;

bool shot = false;

void setup() {
  pinMode(flyPin, OUTPUT);
  pinMode(pushPhasePin, OUTPUT);
  digitalWrite(pushPhasePin, HIGH);
  pinMode(pushSpeedPin, OUTPUT);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

  esc.attach(escPin, 1000, 2000);
  esc.write(0);

  digitalWrite(RED, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(GREEN, HIGH);
  delay(500);
  digitalWrite(RED, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(GREEN, LOW);
  delay(500);
  digitalWrite(RED, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(GREEN, HIGH);
  delay(500);
  digitalWrite(RED, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(GREEN, LOW);
  delay(1500);
}

void loop() {
  rev.Update();
  mode.Update();
  trig.Update();

  if (mode.clicks != 0) {
    m++;
    if (m > 3) {
      m = 1;
    }
  }

  if (m == 1) {
    digitalWrite(RED, LOW);
    digitalWrite(BLUE, LOW);
    analogWrite(GREEN, 120);
  }
  else if (m == 2) {
    digitalWrite(RED, LOW);
    analogWrite(BLUE, 120);
    digitalWrite(GREEN, LOW);
  }
  else if (m == 3) {
    analogWrite(RED, 120);
    digitalWrite(BLUE, LOW);
    digitalWrite(GREEN, LOW);
  }

  if (rev.depressed) {
    digitalWrite(flyPin, HIGH);
    esc.write(40);
  }
  else {
    digitalWrite(flyPin, LOW);
    esc.write(0);
  }

  if (trig.depressed) {
    if (m == 1) {
      if (!shot) {
        digitalWrite(pushSpeedPin, HIGH);
      }
      delay(singleShot);
      shot = true;
      digitalWrite(pushSpeedPin, LOW);
    }
    if (m == 2) {
      if (!shot) {
        digitalWrite(pushSpeedPin, HIGH);
      }
      delay(singleShot * 3);
      shot = true;
      digitalWrite(pushSpeedPin, LOW);
    }

    if (m == 3) {
      digitalWrite(pushSpeedPin, HIGH);
    }
  }

  else {
    digitalWrite(pushSpeedPin, LOW);
    shot = false;
  }
}

The relevant portion that is failing is under the "if m == 1,2,3" blocks. Where m [for mode] == 2, the blue light works but the other leds do not light when cycling through the modes. Note the leds are on PWM pins (9,10,11). Thanks for any help!


texts: Arduino/ESP8266 - TCP server, connect to AP, receive connections/data

texts:
We're trying to use an ESP8266/Arduino Uno as a TCP server, which connects to a wireless AP and then receives commands from other devices on the same network. Currently we got the "connect to AP" part working, but when we try to send data to the ESP/Arduino/TCP server, it doesn't work, refusing all connections to it.

Here's the (relevant parts of the) code we currently use:

#include <SoftwareSerial.h>

SoftwareSerial ESPSerial(2, 3);

void setup() {
    Serial.begin(9600);
    ESPSerial.begin(115200);
    sendToWifi("AT", 10, true);
    sendToWifi("AT+CWMODE=1", 10, true);
    sendToWifi("AT+CWJAP=\""+myAp+"\",\""+myApPassword+"\"", 10, true);
    sendToWifi("AT+CIPMUX=1", 10, true);
    sendToWifi("AT+CIPSERVER=1,80", 10, true);
}

void loop() {
    // The code that would receive data from connecting devices are here
}

String sendToWifi(String command, const int timeout, boolean debug) {
    String response = "";
    ESPSerial.println(command);
    long int time = millis();
    while((time+timeout) > millis) {
        while(ESPSerial.available()) {
            char c = ESPSerial.read();
            response+=c;
        }
    }
    if(debug) {
        Serial.println(response);
    }
    return response;
}

I also have code that's supposed to receive/print data received from the other devices on the network but because no other device can even connect to this TCP server, I felt it was irrelevant for the question. If however you think it's important to include said code, let me know and I'll update my question.

All the solutions we've found online either configures the ESP as the AP, uses the WifiClient library, which we can't seem to get working (even if we could though, we'd rather do it through AT commands) or uses the ESP8266 as a stand-alone module.


texts: How to detect if the arduino wire is still connected

texts: I have hall sensors connected to an arduino, because of mechanical movements there is some possibility that the input wire may accidentally slip out of the arduino analogin sockets. Is there any way I can detect if the wire is still connected to hall sensor  ? I don't want to solder the cables yet.


texts:
Hopefully this question is not too off-topic for this board. I need a ready-made programmable hand-held device with an ethernet-connection. Something like an Arduino with batteries and display and some buttons in a box.
This is for my company so a complete ground-up assembly is too expensive and time-consuming in this case. Any hints to companies that produce something like this are welcome. And yes, I tried searching with different search-engines already. :-)
Thanks for your time!


texts: MKR 1010 disconnects COM-port on each upload

texts:
Each time I attempt to upload to the MKR WiFi 1010 board the COM-port gets disconnected, usually at one of the following points:

Either it disconnects just after compiling/verifying. In this case the LED_BUILTIN pulsates slowly, and the USB-cable needs to be reconnected in order to try again. The next attempt usually results in 2..

Or, it disconnects after a successful upload. The next attempt to upload will always result in 1. occurring. When this happens the COM-port is still visible in Windows Device Manager but it can't be found by a Serial Monitor.

Any ideas what could be causing this or what could be done to have it stay connected? With an UNO this doesn't happen.


texts: What's the problem with program , continously beeping buzzer

texts:
I have used PIR motion sensor with arduino Uno r3, alongwith one piezo buzzer. and the program is as

 /*
 * PIR sensor tester
 */

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;
int piezoPin = 11;
// variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);
  pinMode(piezoPin, OUTPUT);
  Serial.begin(9600);
  // declare sensor as input

}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);
    tone(piezoPin,300,160);
    delay(150);

    // turn LED ON
    if (pirState == LOW) {
      // we have just turned on

      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW);
    tone(piezoPin,0,0);
    delay(300);

    // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of

      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

but it supposed to ring buzzer at the time of pir motion sensor getting signal. But buzzer continuously ringing and at the time of pir sensor getting signal, it just ring louder. What is the problem in program``


texts: Can I program a 20MHz Attiny85 with the 8MHz Internal Clock option in the Arduino Software?

texts:
I'm looking at using the ATTiny85 for a project, but have run into a snag. After following the tutorial found at https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide, I've installed the necessary files to be able to program an ATTiny85; however, the options given under "Clock" are 1MHz and 8MHz internal, as well as 8, 10, and 20MHz external.

Normally this wouldn't be a problem, except Digikey has no in-stock 8MHz flavored devices in the package I need (SOIC-8, don't have a reflow setup to use the QFN package).

If I buy the 20MHz version, will I be able to program them with the Arduino IDE set to the "8MHz Internal" clock option?


texts: Parsing the data from an HTTP POST request on a ESP8266 / wemos

texts:
I'm sending an HTTP Post request on my Android App to my Wemos D1 mini pro and want to parse the incoming data (which is a json). My current code just prints out the whole POST request and I need to trim it so I only get the needed data. There are several examples out there but nothing matched my needs or worked at all.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>

const char* ssid = "myssid";
const char* password = "mypassword";
char c;
String readString = String(100);
WiFiServer wifiServer(80);

void setup() {

  Serial.begin(9600);
  delay(1000);

  WiFi.begin(ssid, password);
  WiFi.mode(WIFI_STA);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting..");
  }

  Serial.print("Connected to WiFi. IP:");
  Serial.println(WiFi.localIP());
  wifiServer.begin();

}

//for parsing the actual JSON later
//you can ignore this at this moment because I don't even get the needed string to parse it from JSON
void handleReceivedMessage(String message){

  StaticJsonBuffer<500> JSONBuffer;                     //Memory pool
  JsonObject& parsed = JSONBuffer.parseObject(message); //Parse message

  if (!parsed.success()) {   //Check for errors in parsing

    Serial.println("Parsing failed");
    return;

  }

  const char * name3 = parsed["name"];           //Get name from HTTP
  Serial.println("name3");
}

void loop() {
  WiFiClient client = wifiServer.available();

  if (client) {
  Serial.println("Client connected");

    while (client.connected()) {

      while (client.available()>0) {
        //instream from mobile device

        char c = client.read();
        if (readString.length() < 100) {

         //store characters to string
         readString.concat(c);
         //Serial.print(c);
}
      Serial.print(c);
//if HTTP request has ended
       if (c == '\n') {
          //Serial.println(readString);
          delay(50);
          //handleReceivedMessage(readString);
          readString = "";
          client.stop();
   }
 }}}}


texts:
I am having an Arduino Uno and I want to add a LCD to it. My LCD is a C2042A with I2C shield on it. I tried the LiquidCrystal_I2C library but it doesnt work. I am not getting any errors the LCD is just not showing the text. I just used the example code 'Hello World' from the library. I only changed the adress from 0x27 to 0x63 because I found that with the I2C scanner.

So all in all the LCD is connected right. It shows I2C mode which is also fine and it is find by the I2C Scanner code. Which library do I have to use that it will work? http://www.wentztech.com/filevault/Electronics/Arduino/


texts:
My Arduino Yún is not detecting my previously working SD card. The metal contacts are closed. There is no dmesg output after plugging in the SD. It does not detect a different SD.

Any ideas for what's wrong?


texts: Can i connect in pin of relay module to Analog pins of arduino instead of digital pin?

texts:
Im a complete beginner
Im making a project using relay modules and arduino. but all the digital pins of my arduino are filled.
I wanted to ask if i can use the analog pins to connect my relay module to my arduino? If yes can anyone give me the statements to write high and low using analog.


texts:
I am making a basic 2WD robot using Arduino Uno with motor shield.
I am getting no compile errors - but something in my logic flow is not working as expected.

Expected Operation:

Ping sensor does distance check.
If distance is less than 5cm.
Turn both Channel A & B motors half-speed for 1 second.
Stop motors.
Take new distance reading ping, start again.

What however is happening, is that channel A works as expected, but channel B motor keeps running??
Where is my code / logic mistake?

Later date I will add to else statement to turn one wheel to change direction.

/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v
 GND to arduino GND
 Echo to Arduino pin 7
 Trig to Arduino pin 8
 */

#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED

int maximumRange = 1000; // Maximum range needed
int minimumRange = 1; // Minimum range needed
long duration, distance; // Duration used to calculate distance

void setup() {
  // put your setup code here, to run once:

Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)

  pinMode(12, OUTPUT); /* Motor Channel A RIGHT SIDE*/
  pinMode(9, OUTPUT); /* Motor Channel A */

  pinMode(13, OUTPUT); /* Motor Channel B LEFT SIDE */
  pinMode(8, OUTPUT);

  }

void loop() {

  /* Distance check begins */

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

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

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;

 /* End distance check */

 if (distance >= 5){
 /* Distance great enough to provide room to move */
  Serial.println("Move!");

  digitalWrite(LEDPin, HIGH); /* LED show movement */

  digitalWrite(12, LOW); /*move channel A motor half-speed */
  digitalWrite(9, LOW);
  analogWrite(3, 123);

  digitalWrite(13, HIGH); /*move channel B motor half-speed */
  digitalWrite(8, LOW);
  analogWrite(11, 123);

  delay(1000);

  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
 }

 else {
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(distance);
 digitalWrite(LEDPin, LOW);
 }

 //Delay 50ms before next reading.
 delay(500);

}


texts: What's with the debug error messages, like VMDPE_1|1_VMDPE?

texts:
I'm using visual micro for visual studio, and I understand this kind of thing is caused by conflicting serial data when I try to read and print to the main serial at the same time, right?

Well, I need to read serial data from the main serial on my Mega 2560, and then I need to see it on my LCD screen, which is controlled by the board via SPI. I know I can use those two at the same time because I'm doing it with my transmitting arduino and I can see that it's transmitting correctly.

When I try to view my serial data in the serial port, I get nothing but a stream of these error codes, or whatever they are. They generally look like this: VMDPE_1|1_VMDPE. Usually there are some numbers in there too, like: MDPE_1|2571143_VMDPE. I sort of expected that, since you can't read and write at the same time on one serial. But that would be fine, because my project is not going to be plugged into a PC anyway.

So of course I try to pipe my data directly to the LCD screen so I can plug my recieving arduino into external power and not have to see the error messages, which I thought were coming from the debugger of my compiler. Here's my code:

//on the receiver side

#include <stdint.h>
#include <TFTv2.h>
#include <SPI.h>

char incoming[3];

void setup() {
    Serial.begin(9600);
    //TFT_BL_ON;      // turn on the background light
    //Tft.TFTinit();  // init TFT library
    //Tft.setDisplayDirect(DOWN2UP);
    //TFT_BL_ON;      // turn on the background light
    //Tft.drawString("INCOMING:", 20, 301, 3, RED);
    Serial.println(incoming);

}

void loop() {

    if (Serial.available()) {

        Serial.readBytesUntil(',', incoming, 3 ) ;

        //Tft.fillRectangle(64, 236, 45, 165, BLACK);

        //Tft.drawString(incoming, 65, 235, 4, WHITE);
        Serial.println(incoming);

    }
}

But nope! I get the same error codes on my LCD screen! Even worse, now they seem to have screwed up my zigbee module! I took it off the board, plugged it into my computer, and now the XCTU utility is reading all sorts of messed up values that are total nonsense. Somehow, this seems to have overwritten the zigbee's actual SERIAL NUMBERS!!! What are they now? Take a guess!

Serial number high: E_1|2571092_VMDPE

Serial number low:  MDPE_1|2571143_VMDPE


texts: Has pt.h library been removed from arduino?

texts:
I'm trying to get a program to use protothreading and I've got an error at the include statement for the pt.h library stating that there is no such file or directory. This is how it's written in the program:

#include <pt.h>


texts: Can a connection of HC-05 and Arduino Nano receive audio and display waveform on computer?

texts: Working to receive Music for Bluetooth Speaker via HC-05


texts: I'm having trouble using Serial.readStringUntil() on the DUE

texts:
I'm working with a DUE.
The call Serial.readStringUntil() doesn't work.
This is the error message I get when I compile:
no matching function for call to 'UARTClass::readStringUntil()'
Is it possibly a library issue?
The only library I'm loading:
#include <Arduino.h>
Any assistance would be appreciated!
Here is the original code:
void loop()
{
  String LazCommand;

  if(Serial.available())
    {
        LazCommand = Serial.readStringUntil();
        Serial.print("Command received \n" && LazCommand);
    }

  interrupts();
  delay(1000);
  noInterrupts();
}


texts: Tracking Device Using Arduino UNO, GSM and GPS

texts:
I'm using SIM900A and GY NEO6MV2. I'm supposed to receive device location continuously after sending "Staff" to GSM and will stop receiving the location if I send "Stop" to GSM. This work on Serial monitor but not on my cellphone.

    #include <SoftwareSerial.h>
    #include <TinyGPS.h>

    float flat, flon; // create variable for latitude and longitude object
    int temp=0,i;

    SoftwareSerial mySerial(10, 11); // create gps sensor connection
    TinyGPS gps; // create gps object

    void setup(){
       Serial.begin(9600); // connect serial
       mySerial.begin(9600); // connect gps sensor
       delay(2000);
       Serial.println("AT+CNMI=2,2,0,0,0");
       temp=0;
     }

     void loop()
     {
        while(Serial.available())
        {
           if(Serial.find("Staff"))
           {
              get_gps();
           }
           if(Serial.find("Stop"))
           {
               loop();
            }
         }
      }

     void get_gps() // run over and over
      {
        unsigned long start = millis();

        while (millis() - start < 10000) {
        if (mySerial.available()) {
             char c = mySerial.read();
             if (gps.encode(c)) {
                 gpsdump(gps);;
             }
            }
          }
        }

     void gpsdump(TinyGPS &gps)
     {
         init_sms();
         gps.f_get_position(&flat,&flon);
         Serial.print("Location?\nRight here:\n");
         Serial.print("Google Maps: https://google.com/maps/place//@");
         printFloat(flat, 5); Serial.print(",");
         printFloat(flon, 5); Serial.print('\n');
         Serial.print("Location as metioned above\nTQVM");
         Serial.write(0x1A);
         delay(2000);
       }

      void init_sms()
     {
       Serial.println("AT+CMGF=1");
       delay(400);
       Serial.println("AT+CMGS=\"+60134484868\"");
       delay(400);
     }

    void printFloat(double number, int digits)
    {
     // Handle negative numbers
     if (number < 0.0) {
     Serial.print('-');
     number = -number;
    }

      // Round correctly so that print(1.999, 2) prints as "2.00"
      double rounding = 0.5;
      for (uint8_t i=0; i<digits; ++i)
      rounding /= 10.0;

      number += rounding;

    // Extract the integer part of the number and print it
     unsigned long int_part = (unsigned long)number;
     double remainder = number - (double)int_part;
     Serial.print(int_part);

    // Print the decimal point, but only if there are digits beyond
    if (digits > 0)
    Serial.print(".");

     // Extract digits from the remainder one at a time
     while (digits-- > 0) {
     remainder *= 10.0;
     int toPrint = int(remainder);
     Serial.print(toPrint);
     remainder -= toPrint;
    }
   }


texts: Cannot assign COM port to HC-05 bluetooth device

texts:
I can't set a COM port to my paired BT module. For better understanding I recorded a YouTube video to make sure I show everything.

Hardware:

Arduino Nano knock-off by RobotDyn (atmega168)
Bluetooth module HC-05 (zs-040) which looks like this
Windows 10 Home 64 bit on tablet

I have wired them up like this .

However, before that, I tried to wire it up without the resistors (so I hope I didn't damage anything).

Here is my very simple code which should just echo back what it get.

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

void loop() {
  if(Serial.available())
  {
    Serial.println(Serial.parseInt());
  }
  delay(100);
}


texts: Arduino on breadboard Tension is 4.4V instead of 5 V,looking for some guidance

texts:
I build a circuit that work on breadboard now i try to prototype it,so i start solder it on a prototype board and the arduino is out of sync.So i check the tension and for some reason it's 4.4~4.6 on the Vin pin of Atmega328 so i try to find how to debug.I don't have a lot of theorical knowledge on electronic,but my thougt was as long as everything is plug in parrallel the tension should remain the same ( and i don't have any thing in serie) so for the tension to drop i may have something acting as Resistor, and i try to find how and what.
I use 22AWG 0.7mm wire o create a 5V line and my GND line on each side of the Atmega ( roughly 7 cm on each side),i start to wondering if it was not a bad idea. I have picture of my prototype bellow,but it's messy so not sure it help. My question is how to you proceed to troubleshoot this thing ? What are the step you do to find out where is the problem


texts: Problem with powering ublox NEO-6M GPS module

texts:
Firstly, I'd like to mention that I'm a beginner. This is the first time I've worked with a GPS module. The serial monitor is completely empty when I upload the following code to my circuit:

#include <SoftwareSerial.h>

// The serial connection to the GPS module
SoftwareSerial ss(4, 3);

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

void loop(){
  while (ss.available() > 0){
    // get the byte data from the GPS
    byte gpsData = ss.read();
    Serial.write(gpsData);
  }
}

Things I might've done wrong and some things I'd like to mention:

As you can see, I connected the module to 5V pin of Arduino but the datasheet says:

The reason why I think this might not be the case is that there are multiple projects on the internet that have used a circuit like mine.
I've placed my module on the window edge so that it can get a good line of sight. I'm yet to try it outdoors.
After reading the datasheet, I tried a potential divider using resistors to get 3.3V and the result is still nothing. I later realized that this was probably a really silly thing to do since I created an unstable supply which is not suitable for the module.
For cold-start conditions, how long can it take to lock to a satellite? I've waited several times for half an hour each time only to get no result in the end. Can it take more than that? Should I wait?
What can I use to supply constant 3.3V to the module? Are there any special power supplies for GPS modules?
Is it possible to tell if my module is damaged just by seeing?


texts: SoftwareSerial HC-05, ASCII "T" to turn on LED, doesn't work

texts:
Arduino Uno / HC-05 / ArduinoIDE
App on my phone: "Bluetooth Terminal HC-05"

I want the program to turn on the native 13th pin LED ON, if incoming text is "T" and turn it OFF if incoming text is "F".

Everything else is working fine, but even when I send "T" from my phone, it responds with:

T

Not T

T

And the LED doesn't turn on anyway.

The if condition, for some reason, is returning false even when the variable iSt having value "T" is being compared to the string "T".... Why is this happening and how can I fix it?

I KNOW that when if I use Hardware Serial instead of Software Serial, it will work, but only for one single character. I still want to know why doesn't it work with Software Serial.

Here's the code.

#include<SoftwareSerial.h>
SoftwareSerial bt(9,10); //RX,TX
char iCh; // incoming characters will be in this variable
char junk;
String iSt = ""; // incoming formed string will be in this variable

void setup()
  {
    bt.begin(9600); // start serial comm
    pinMode(13,OUTPUT); // native LED Pin for ArduinoUNO
  }

void loop()
  {
    if(bt.available())
    {
      while(bt.available())
      {
        iCh = (char)bt.read(); // Reading the input
        iSt = iSt + iCh; // Add every incoming character to this string
        delay(10); // Gives the program some time to add longer messages if required
      }
      bt.println(iSt); // print this on the serial monitor via the app on my phone
      if(iSt=="T")
        {
          digitalWrite(13,HIGH); // TURN LED ON
        }
      if(iSt=="F")
        {
          digitalWrite(13,LOW); // TURN LED OFF
        }
      if(iSt!="T")
        {
          bt.println("Not T"); // Print "Not T" on the serial monitor on phone
        }
      bt.println(iSt); // print this on the serial monitor via the app on my phone again
      iSt=""; // empty the string before the loop runs again, to avoid mixing previous and next string
    }
  }


texts: How to burn a bootloader to non-bootloaded(clean crystal) ATMEGA328P-PU with USBASP programmer via Avrdudess?

texts:
I'm trying to burn bootloader to my clean crystals, atmega328p-pu.For this I use the 16MHZ crystal with two ceramic capacitors and USBASP programmer, on Windows 10 Pro. As program for burning I tried: Arduino IDE, AVRDUDESS,AVRDUDEPROG. But when I would to detect my chip(or in IDE try to burn the Chip)., I get this error:
`
avrdude.exe: set SCK frequency to 1500000 Hz
avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
avrdude.exe: error: program enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

avrdude.exe done.  Thank you.

`
From this error I understand that the target(My chips) Wouldn't to start. I checked my connection for 1000 times and I tested mt wires too, they works correctly. And supply 5V comes o chip and it become warm(it means that supply comes and it should start). I have got 5 chips And I tested all of them. I searched internet but nothing.

Please,help me, and say how can I burn them.

Best Regards,
E.M.


texts: How to use void swap with multi-dimensional array to control motor with openCR board

texts:
i am a beginner.
About my problem, there is an "invalid conversion' error in the swap(goal_positionall)

#include <DynamixelWorkbench.h>

#define Device_Name ""
#define BAUDRATE 57600
#define DXL_ID_1  1
#define DXL_ID_2  2
#define DXL_ID_3  3
#define DXL_ID_4  4
#define DXL_ID_5  5
DynamixelWorkbench dxl_wb;

int32_t goal_positionall[3][5] ={{0, 1024, 2048, 3072, 4080},
                                 {0,1000,0,3000,0},
                                 {1000,1000,500,700,2048}};

const uint8_t handler_index = 0;

    void setup()
    {
      Serial.begin(57600);
      while(!Serial);

      const char *log;
      bool result = false;

      uint16_t model_number = 0;
      uint8_t dxl_id[5] = {DXL_ID_1, DXL_ID_2, DXL_ID_3, DXL_ID_4,DXL_ID_5};

      result = dxl_wb.init(Device_Name, BAUDRATE, &log); //To initialize the
motor
      if (result == false)
      {
        Serial.println(log);
        Serial.println("Failed to init");
      }
      else
      {
        Serial.print("Succeeded to init : ");
        Serial.println(BAUDRATE);
      }

      for (int X = 0; X < 5; X++) //To do the actions 5 time
      {
        result = dxl_wb.ping(dxl_id[X], &model_number, &log); //Ping the 5 motors
        if (result == false)
        {
          Serial.println(log);
          Serial.println("Failed to ping");
        }
        else
        {
          Serial.println("Succeeded to ping");
          Serial.print("id : ");
          Serial.print(dxl_id[X]);
          Serial.print(" model_number : ");
          Serial.println(model_number);
        }

        result = dxl_wb.jointMode(dxl_id[X], 0, 0, &log);  //Change joint mode for 5 motors
        if (result == false)
        {
          Serial.println(log);
          Serial.println("Failed to change joint mode");
        }
        else
        {
          Serial.println("Succeed to change joint mode");
        }
      }

      result = dxl_wb.addSyncWriteHandler(dxl_id[0], "Goal_Position", &log); //Add Sync write handler
      if (result == false)
      {
        Serial.println(log);
        Serial.println("Failed to add sync write handler");
      }

    }

    void loop()
    {
      const char *log;
      bool result = false;

      result = dxl_wb.syncWrite(handler_index, &goal_positionall[0][0], &log);
      if (result == false)
      {
        Serial.println(log);
        Serial.println("Failed to sync write position");
      }

      delay(1000);

      swap(goal_positionall);
    }

void swap (  int32_t **array[][5] )
    {
      int32_t tmp = array[0][5];
      array[0][5] = array[1][5];
      array[1][5] = array[2][5];
      array[2][5] = tmp;

    }


texts: Arduino Micro Breadboard USB Not Connecting

texts:
I have been working on getting an Atmega32u4 connected to USB. I lifted the connections from the Arduino Micro schematic for the preliminary schematic shown here. When I connect the chip to USB, the system (Ubuntu 18.04) does not appear to recognize it.
I was able to burn the Caterina-Micro bootloader via my Pololu USB AVR Programmer as well as through ArduinoISP to confirm that everything was uploaded correctly. The following is the output of avrdude using the pololu programmer:

$ avrdude -p m32u4 -P /dev/ttyACM0 -c avrispv2 -U flash:w:Caterina-Micro.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100%
0.00s
avrdude: Device signature = 0x1e9587 (probably m32u4) avrdude: NOTE:
"flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "Caterina-Micro.hex" avrdude:
input file Caterina-Micro.hex auto detected as Intel Hex avrdude:
writing flash (32730 bytes):
Writing | ################################################## | 100%
8.21s
avrdude: 32730 bytes of flash written avrdude: verifying flash memory
against Caterina-Micro.hex: avrdude: load data flash data from input
file Caterina-Micro.hex: avrdude: input file Caterina-Micro.hex auto
detected as Intel Hex avrdude: input file Caterina-Micro.hex contains
32730 bytes avrdude: reading on-chip flash data:
Reading | ################################################## | 100%
6.76s
avrdude: verifying ... avrdude: 32730 bytes of flash verified
avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
avrdude done.  Thank you.

Using a Saleae Logic Analyzer, I sniffed the following USB communications. It seems to me that the atmega is transmitting properly but not receiving any responses but I am not certain.
I confirmed that the USB cable in use was working by plugging it into an Arduino Micro that I have. System was able to identify Arduino Micro, Arduino Uno and pololu AVRisp.
I am hoping that there is an easily assignable cause to the issues that I am experiencing. If any addition information is required, please ask.


texts: How to link a computer processor to an Arduinno on a board?

texts:
I am completely new to Arduinno, so please forgive if the question is stupid.

Here is the problem: I have a project where I want an Arduino (or similar microchip board) to handle some sensors and actuators. But I need very advanced "artificial intelligence" to handle the data provided by those sensors.
There are two major obstacles for placing this intelligence on the Arduinno, according to my researches.

First, the Arduinno is coded in a language similar to C: I could of course find a way to write the intelligence, but it will be a time-consuming task for the developper
Second, I might encounter a problem with memory: I will store heavy matrix of data, do complicated calculation, and this might be too much for an Arduinno
Third, I read on stackexchange that there are some ways to compile Python code on Arduinno boards, such as the Arduinno Mega. So I can code this intelligence in Python (which is an easy task), and compile the resulting code on Arduinno. However, I will reach a caveat: some libraries I will use will be entirely compiled, and this will take too much memory on an Arduinno (such as the second issue I mentionned)

So I have another solution, but I am not sure if it is state-fo-the-art, or even a feasible solution:
I would like to separate two tasks:

Write an Arduinno code to handle the sensors and create numeric data
Write a Python code on my computer and compile it as an executable file on my computer
Then somehow, I "extract" the processor of my comouter (Intel, by the way) and I plug it on the Arduinno board. The Arduinno sends the data to the processor, and the processor runs permanently the Python file and gives back data

So question:

Is it possible overall?
Was it ever made?
What communication links are good for exchanging data between processor and Arduinno microchip: USB, Serial, Ethernet?
How can I handle the input of the processor, so that it collects data from the Arduinno and then uses it in the Python code?


texts: Can I run ESP8266 via Arduino using the PWM pins?

texts:
First question: Since we can control the volts that we can throw via PWM pins on Arduino, can we use it to power the 3.3 V ESP8266?

Second question: Can we also use these PWM pins as software serial pins i.e. they will be sending instructions at 3.3 V?


texts:
I basically would like to ask this same question (in another context / more generically):

https://www.reddit.com/r/arduino/comments/25my2t/lgpl_and_arduino_in_commercial_products/

Stated differently:

What are the legal implications of LGPL licence in commercial products using Arduino boards (and or Arduino software/firmware)?

and about creating my own libraries for Arduino? (less or more permissive licenses cases for a derivative work)

and lastly, I'm also curious about this statically vs linked library conditions of LGPL (and how this would be applicable in this case)

thanks!


texts: Averaging input from multiple input over a fixed amount of time (estimated)

texts:
I am trying to average input values for a number of inputs and have it then store those averages into a string to write to a txt doc on a sd card.

I am using:

// read 6 sensors and append to the string:
for (int analogPin = 0; analogPin < 6; analogPin++) {
  int sensor = analogRead(analogPin);
  dataString += String(sensor);
  if (analogPin < 6) {
    dataString += ",";
  }
}

to read the pins at the moment, but I want to change the analogRead(analogPin) to an average value and then use the averages to create the string.

but when I try to average the data I run into errors, or I get output that is 0 for something that should be higher (3.3V).

I am doing this to stabilize my values a bit better and remove jitter.

Any suggestions?


texts: ESP8266 - Error: unknown opcode or format name 'jmp'

texts:
I bought a nodeMCU 8266 and I'm hoping that it can replace my bulkier UNO+WiFi 101.

I'm getting an error when I compile:
Error: unknown opcode or format name 'jmp'

I'm using it in void SoftReset() function:

void softReset() {
  delay(1000);
  asm volatile ("  jmp 0");
}

This reset works great with my Uno+101 setup but, for whatever reason, doesn't like the ESP8266.  I removed the WiFi101 library and added the ESP8266 WiFi libraries.  That has been the only change.

Can you please help me understand why I'm receiving this error?

EDIT:  I have read this SO answer but the "syntactical sugar" didn't work for me.

I am also perusing various ESP8266 sites but they are not as well managed as SE/SO and answers are tough to find.


texts:
I'm fairly new to Arduino and am trying to use a push button to toggle an LED on and off using a momentary press of the button. This code is lifted straight off the tutorial on the Arduino website but is not working for me. It seems to send the LED on a loop - switching between on and off by itself, and pressing the button pauses the cycle.

Any ideas as to why it is doing that?

int buttonPin = 2;         // the number of the input pin
int ledPin = 13;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);

}

void loop()
{

  reading = digitalRead(buttonPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
if (reading == HIGH  && previous == LOW && millis() - time > debounce) {
  if (state == HIGH)
    state = LOW;
  else
    state = HIGH;
time = millis();
}

else
  if (state == LOW)
    state = LOW;
  else
    state = HIGH;
  digitalWrite(ledPin, state);
 //Serial.println(buttonPin);
  //
 Serial.println(reading);
previous = reading;
}


texts: Problem regarding Arduino & GSM module kit

texts:
I am using the following program to receive messages from a GSM module.

As we start our kit, we received two messages "main door is open" and "store room is open". (Depending upon sensor position)

This program is run properly, but the problem is that it repeats the message after some time. It does not depend on time.

Suppose our store room is closed. I receive this message on my given mobile number, but after some time two "the store room is open" messages are received and after this message immediately the message "received store room is closed". (means it sets sensor to its initial mode i.e. closed) Same problem is happening with this main door.

My kit contains an Arduino UNO board, GSM module SIM800 and two limit switches (one for the main door and second is for the store room)

I keep my both sensor and Arduino board distance over 17 meters by using CAT5e cable.

My code:

const int Main = 7;  // pin define for main door sensor
const int Store = 8; // pin define for store room sensor
const int Main_led =  13;  // indication for main door sensor
const int Store_led =  14;  // indication for store room sensor

void setup() {
  Serial.begin(9600);
  pinMode(Main_led, OUTPUT);
  pinMode(Store_led, OUTPUT);
  pinMode(Main, INPUT);
  pinMode(Store, INPUT);
}

void sendMessage(char *text) {
    Serial.println("OK");
    delay(1000);
    Serial.print("AT+CMGF=1\r\n");
    delay(500);
    Serial.print("AT+CMGS=\"+91-------------");
    Serial.print("\"\r\n");
    delay(5000);
    Serial.print(text);
    Serial.write(0x1A);
    delay(5000);
}

void loop() {
  static int oldState1 = -1;
  static int oldState2 = -1;

  int buttonState1 = digitalRead(Main);
  if (buttonState1 != oldState1) {
    digitalWrite(Main_led, buttonState1);
    if (buttonState1 == HIGH)
      sendMessage("Main Door is closed");
    else
      sendMessage("Main Door is open");
    oldState1 = buttonState1;
  }

  int buttonState2 = digitalRead(Store);
  if (buttonState2 != oldState2) {
    digitalWrite(Store_led, buttonState2 );
    if (buttonState2 == HIGH)
      sendMessage("Store room is closed");
    else
      sendMessage("Store room is open");
    oldState2 = buttonState2;
  }
}


texts:
My Yun has a micro SD card with shared file system using ExpandingYunDiskSpace.

I would like to copy my Yun/SD card data perfectly onto my backup Yun/SD card. Because I have made many changes to the filesystem, just re-running the whole process manually would take a long time.

What methods can I use to transfer my Yun's data onto my other Yun?

My other Yun is brand new (never plugged in), and I have a brand new SD card in there. If I can do a 'bit-perfect' transfer for Yun and Micro SD in one shot that would be ideal.


texts:
I need my sketch to print the name of the original INO file at the beginning of execution (during setup).

Is it possible?  If so, what is the resource which should be used?


texts: analogRead-ing Potentiometer Values in void setup()

texts:
I've run into a problem while coding a speedometer meant for bicycles. The speedometer would require the diameter of the wheel in inches for maximum accuracy, so I'd like to have an adjustable (by potentiometer) numerical prompt appear on two 7 segment LEDs. So, for example, the device would be turned on, it would display "16," the user would turn the potentiometer knob until the 7 segment LED displays "24," then the user would push a button [indicating the beginning of the loop()], and the speedometer would begin measuring and displaying his or her speed.

This would be an easier task to accomplish in the loop section of the code, but, because I only want this series of potentiometer analogReads to occur once, it gets a bit trickier.

Some clarification: Every other component of the speedometer works (such as the 7 segment LEDs via shift register and the actual measurements), so I'm only looking for help with the code for the potentiometer.

Thanks!


texts:
Im about to develop some home automation. It should be possible to connect new sensors to the main computer. Thats a Arduino.

What can be used as a connector for the I2C sensors? It should be customer friendly. So something like RJ11 or USB. What can be used for that?

Is it possible to send data wirelessly from a I2C sensor?

Regards


texts: Code test the duration press of the button

texts:
I wrote code that tracks the duration of a button click. It has bounce protection and frequent clicks. (Freeze)

My code:

bool freeze_time, btn_read, debounce;
unsigned int freeze_timer, btn_timer;

#define BTN 6

void setup() {
  Serial.begin(9600);
  pinMode(BTN, INPUT);
}

void loop() {
  /* Freeze Timer Protection */
  if(freeze_time) {
    if((millis() - freeze_timer) >= 2500) {
      freeze_time = false;
      btn_read = false;
    }
  }
  /* Read Button State */
  if(digitalRead(BTN) == HIGH) {
    if(!btn_read) {
      btn_timer = millis();
      debounce = true;
      btn_read = true;
    }
  }
  /* BTN Read Process */
  if(btn_read) {
    /* Debounce Protection */
    if(debounce) {
      if((millis() - btn_timer) >= 1000) {
        if(digitalRead(BTN) == HIGH) {
          Serial.println("Debounce ok.");
          btn_timer = millis();
          debounce = false;
        } else {
          Serial.println("Debounce fail.");
          freeze_time = true;
          debounce = false;
        }
      }
    }
    /* BTN Read Process */
    else if(!freeze_time) {
      if((millis() - btn_timer) >= 1500) {
        if(digitalRead(BTN) == HIGH) {
          Serial.println("Ok. Button Pressed > 1500ms");
          freeze_timer = millis();
          freeze_time = true;
        } else {
          Serial.println("Ok. Button Pressed < 1500ms");
          freeze_timer = millis();
          freeze_time = true;
        }
      }
    }
  }
}

I checked it on real Arduino UNO and Tinkercad simulator. Initially, everything works well, but if I press the button indefinitely, the system will fail (every time you press the serial port, messages appear as if all flags were lost and the timers did not work. I filmed the behavior:

1) Initially: http://recordit.co/lVlR1z1CUq
2) System is broken: http://recordit.co/lhvzM100DI

What could be the problem and how to make it fault tolerant?


texts: How to properly handle the Arduino String

texts:
I've read that the Arduino String is bad as it causes memory fragmentation, so I try to avoid them mostly. But I still have some occurences where I'm not quite sure if they are ok after all.
The first is in print statements:
I have a function which prints a success or error message to the serial port, like so: Serial.println("Success");. Is this ok or should I (for example) pre define the String using #define SUCCESS "SUCCESS"?
Which leads me to the next case, defines:
I'm using MQTT and have the topics defined like above, e.g. #define TOPIC_COLOR "light/color". Is this fine?
A third one is with ArduinoJSON:
I'm using Strings as keys, like so lights["red"] = redVal;. This call is made at multiple places so I assume the string would be created multiple times? A workaround/improvement I've thought of is using an enum defining the properties and using that as key.
Thanks for all comments, tips and explanations!


texts: Continuous servo rotation with on/ off switch

texts: I am trying to make a ball return catapult. I have a mechanical design already in mind. I need to have a servo rotate constantly. Just one will be enough. I preferably want to do this without an Arduino if possible and just an on-off switch that will make it start and stop. I thought about just using a DC motor but they generally don't have enough torque and have too much speed. Does anyone have an idea for a good circuit?


texts: Is it possible to save different values on address 0 and 1 in EEPROM?

texts:
I want to save different values on address 0 and 1 on eeprom I tried to change it but when I put data on address 0 and also put data on address 1 the address 0 change its value stored into random number and vice versa .. Is it possible to change the value of respective address without affecting others ..

CODE

in the setup
     int eepromSize=EEPROM.length();
      Serial.print("EEPROM found, size=");
      Serial.println(eepromSize);
        // Get the last fade value (as an integer)
      EEPROM.get(0, WATEREQFORN1);
      Serial.print("Last Value N1: ");
      Serial.println(WATEREQFORN1);

      EEPROM.get(1, WATEREQFORN2);
      Serial.print("Last Value N2: ");
      Serial.println(WATEREQFORN2);

The user will input the value that will be save in eeprom i use switch because the user will input like this example .. 100A or 23B

case 'A':
        Serial.print("Case A got ");
        Serial.println(val);
        WATEREQFORN1 = val;

            EEPROM.put(0, WATEREQFORN1);
            Serial.print("DATA SAVE TO EEPROM");

        break;
      case 'B':
        Serial.print("Case B got ");
        Serial.println(val);
         WATEREQFORN2 = val;
         EEPROM.put(1, WATEREQFORN2);
         Serial.print("DATA SAVE TO EEPROM");

        break;

The problem is, when I change/write value into address 0 and after that change/write also into address 1 the value on address 0 also change into different random numbers.


texts: Converting of 32 bit signed hex value to dec

texts:
Using Seed studio CAN shield to read and convert CAN data to dec value.

Example of expected result:

Full CAN message is 70 3B F1 FF 00 00 00 00 , using little endian first 4 bytes gives: FFF13B70 , which should be equal to converted dec value of -0.967824 (using factor of 0.000001).

Here is code to extract the text value I am using.

CAN.readMsgBuf(&len, buf);
unsigned char len = 0;
unsigned char buf[8];
    {
           String reg0 = String (buf[0], HEX);
           String reg1 = String (buf[1], HEX);
           String reg2 = String (buf[2], HEX);
           String reg3 = String (buf[3], HEX);
           Serial.print(reg3);
           Serial.print("\t");
           Serial.print(reg2);
           Serial.print("\t");
           Serial.print(reg1);
           Serial.print("\t");
           Serial.print(reg0);
           Serial.print("\t");
           String regsumm = (reg3 + reg2 + reg1 + reg0);

           Serial.println(regsumm);
        }

As result I got only text string which couldn't be converted into dec. Any other ways how do it?


texts:
I want to create a file and read it form sd card by arduino. I have used sd card module. I have used this following code. In serial monitor it says "SD card is ready to use." But it can't read or write files. I have formatted the card in FAT32 format.

My code is :

#include <SD.h>
#include <SPI.h>

int CS_PIN = 10;

File file;

void setup()
{

  Serial.begin(9600);

  initializeSD();
  createFile("test.txt");
  writeToFile("This is sample text!");
  closeFile();

  openFile("test.txt");
  Serial.println(readLine());
  Serial.println(readLine());
  closeFile();
}
void loop()
{
}

void initializeSD()
{
  Serial.println("Initializing SD card...");
  pinMode(CS_PIN, OUTPUT);

  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
}

int createFile(char filename[])
{
  file = SD.open(filename, FILE_WRITE);

  if (file)
  {
    Serial.println("File created successfully.");
    return 1;
  } else
  {
    Serial.println("Error while creating file.");
    return 0;
  }
}

int writeToFile(char text[])
{
  if (file)
  {
    file.println(text);
    Serial.println("Writing to file: ");
    Serial.println(text);
    return 1;
  } else
  {
    Serial.println("Couldn't write to file");
    return 0;
  }
}

void closeFile()
{
  if (file)
  {
    file.close();
    Serial.println("File closed");
  }
}

int openFile(char filename[])
{
  file = SD.open(filename);
  if (file)
  {
    Serial.println("File opened with success!");
    return 1;
  } else
  {
    Serial.println("Error opening file...");
    return 0;
  }
}

String readLine()
{
  String received = "";
  char ch;
  while (file.available())
  {
    ch = file.read();
    if (ch == '\n')
    {
      return String(received);
    }
    else
    {
      received += ch;
    }
  }
  return "";
}


texts:
I'm using an Uno to control NeoPixels LED strips (60 per metre). These are powered with a 5V DC supply. Now, when using USB to power the Arduino it works lovely. However I want to move the Arduino into a standalone "installation" where I'll only want one power supply.

I've already got a 5V DC supply which outputs about 5.2V. What is the best way to power both the Arduino and the LEDs? I understand the need for at least 7V at the Arduino's voltage regulator input. Would my best bet be to get a 12V supply (or similar) and use a buck converter to power the LEDs? The total current draw could reach 3.6A but will be 400mA for the majority of the time.


texts:
ESP32 has 64 byte SPI FIFO size, but I could not find what is the largest bit size it can receive over SPI?

P.S. I need to interface a sensor, which returns 32 bit response.

EDIT to clarify why I am asking:
I am sending 32 bit request by splitting it into 4 bytes, but do not know how to recieve 32 bit response.
This function is for sending:

uint32_t SendRequest(uint32_t Request)
{
    uint32_t Response;
    digitalWrite(PIN_CSB, LOW);
    SPI.transfer(Request >> 24);
    SPI.transfer(Request >> 16);
    SPI.transfer(Request >> 8);
    Response = SPI.transfer(Request);
    digitalWrite(PIN_CSB, HIGH);
    return (Response);
}

SPI.transfer() returns the respond after data send completely. Can I read the SPI register?

Datasheet of the sensor: https://www.murata.com/~/media/webrenewal/products/sensor/pdf/datasheet/datasheet_scc2230-e02.ashx?la=en

EDIT to update SendRequest() function:

uint32_t SendRequest(uint32_t Request)
{
    uint32_t Response = 0x00;
    digitalWrite(PIN_CSB, LOW);
    // Send the request in 8-bit sections
    SPI.transfer(Request >> 24);
    SPI.transfer(Request >> 16);
    SPI.transfer(Request >> 8);
    SPI.transfer(Request);
    digitalWrite(PIN_CSB, HIGH);
    delay(1);
    // Capture the response in 8-bit sections
    digitalWrite(PIN_CSB, LOW);
    Response = SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    Response = (Response << 8) | SPI.transfer(0x00);
    digitalWrite(PIN_CSB, HIGH);
    delay(1);
    return (Response);
}


texts: Can I get my RGBW Neopixel strip to loop perfectly by adjusting rainbowFade2White function in strandtest?

texts:
I have been working on adjusting the code for the strandtest RGB and strandtest RGBW to get exactly what I want, which in this case is for the LED strip to transition from one color to another nicely (as it already does) and when the loop ends it does not fade in again but instead just continues the color loop with no quick flash between colors or weird transition. The code I have so far is shown below:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 0

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

   rainbowFade2White(3,3,3);
}

void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) {
  float fadeMax = 100.0;
  int fadeVal = 0;
  uint32_t wheelVal;
  int redVal, greenVal, blueVal;

  for(int k = 0 ; k < rainbowLoops ; k ++){

    for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel

      for(int i=0; i< strip.numPixels(); i++) {

        wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255);

        redVal = red(wheelVal) * float(fadeVal/fadeMax);
        greenVal = green(wheelVal) * float(fadeVal/fadeMax);
        blueVal = blue(wheelVal) * float(fadeVal/fadeMax);

        strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) );

      }

      //First loop, fade in!
      if(k == 0 && fadeVal < fadeMax-1) {
          fadeVal++;
      }

      //Last loop, fade out!
//     else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){
//         fadeVal--;
//      }

        strip.show();
        delay(wait);
    }

  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
}

uint8_t red(uint32_t c) {
  return (c >> 8);
}
uint8_t green(uint32_t c) {
  return (c >> 16);
}
uint8_t blue(uint32_t c) {
  return (c);
}

Thanks for the help in advance!


texts: Can send AT+ commands, but can't upload sketch to ESP8266 via Arduino Uno

texts:
Connected a generic ESP8266 to an Arduino Uno.

I can send AT commands fine and generate a normal response, but cannot upload sketches to the ESP8266. I have "Generic ESP8266 Module selected as the board. Tried everything e.g. switching Tx and Rx, connecting GPIO0 and GPIO2 to to Vcc or ground, but to no avail.

Arduino IDE spits this out -

esptool v0.4.5 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
    setting board to ck
    setting baudrate from 115200 to 115200
    setting port from COM1 to COM3
    setting address from 0x00000000 to 0x00000000
    espcomm_upload_file
    stat C:\Users\Michael\AppData\Local\Temp\build7227402767538495982.tmp/wifi_setup.cpp.bin success
    setting serial port timeouts to 1000 ms
opening bootloader
resetting board
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    read 0, requested 1
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
resetting board
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    read 0, requested 1
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
resetting board
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    read 0, requested 1
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2013 bytes of data
    read 0, requested 1
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
warning: espcomm_sync failed
error: espcomm_open failed


texts:
I think my issue is not fully understanding how the millis() function works;

I am wondering the difference between simply creating a variable such as

long fake_millis  ++ ;

vs using millis()?


texts:
Arduino: 1.8.3 (Windows 7), Board: "Arduino/Genuino Uno"
Sketch uses 1094 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM14 -b115200 -D -Uflash:w:C:\Users\Admin\AppData\Local\Temp\arduino_build_360380/FINALROTARO.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         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                    : COM14
         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=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1f

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

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


texts:
I wanted to connect the load cell with hx711 to Arduino to check the presence of load. If there is load on the load cell then an LED can light up and when there is no load the LED will be off. I tried several codes but I'm not getting the result I need. If anyone of you can help with this as this is for my graduation project I will be grateful.

EDIT:

Here is my code, I'm a beginner in Arduino so I don't know much about how it works but this is what I managed to write. PS. the hashtaq before include makes the the text in bold so I excluded it here.

include < HX711_ADC.h >

HX711_ADC scale (2,3); //DT pin2 , SCK pin3
int load1 =0;

void setup() {
   pinMode (3,INPUT); // SCK pin
   pinMode (13,OUTPUT); //LED pin
   Serial.begin(9600); }

void loop() {
   load1= digitalRead(3); // read signal from SCK pin

   if(load1==HIGH) // if there is load on load cell
        {
        digitalWrite(13,HIGH); // turn on the LED
        delay(5000);
   } else {
       digitalWrite(13,LOW); // turn off the LED
       delay(5000);
   }
}


texts: Detecting ground distance through rubber

texts:
I want to put a small Arduino and some sensors inside a tennis ball to measure the ball's height above the ground. It won't be used for tennis, just for fun.

Is there any sensing solution that would allow for the accurate distance detection of the ground through the rubber? Any sort of time-of-flight IR would get absorbed by the rubber that's that thick. I believe sonar would too? My best bet may be using an accelerometer to estimate distance, then determining the height from that.


texts: Newbie needing help with debounce errors in arduino

texts:
So I found a code I would like to use and not sure how to edit the code properly.

#include <Debounce.h>

void matrix(char matrix[7]) {
  int map[10];
  map[0] = 2;
  map[1] = 3;
  map[2] = 4;
  map[3] = 5;
  map[4] = 6;
  map[5] = 7;
  map[6] = 8;
  map[7] = 9;

  int i=0;
  for(i=0;i<=7; i++) {
   if(matrix[i] == 0x30) { // 0x31=1, 0x30=0
      Serial.println(map[i]);
      digitalWrite(map[i],LOW);
   }
   else digitalWrite(map[i],HIGH);
  }
}

void show(int number) {
  switch(number) {
    case 0:
      matrix("11111100");
      break;
    case 1:
      matrix("01100000");
      break;
    case 2:
      matrix("11011010");
      break;
    case 3:
      matrix("11110010");
      break;
    case 4:
      matrix("01100110");
      break;
    case 5:
      matrix("10110110");
      break;
    case 6:
      matrix("10111110");
      break;
    case 7:
      matrix("11100000");
      break;
    case 8:
      matrix("11111110");
      break;
    case 9:
      matrix("11110110");
      break;
    default:
      matrix("00000010");
      break;
  }
}

#define t1 13
#define t2 12

Debounce debouncert1 = Debounce( 20 , t1 );
Debounce debouncert2 = Debounce( 20 , t2 );

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

  // initialize the digital pin as an output:
  pinMode(13, INPUT);
  pinMode(12, INPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}

int setCountPlus(int count){
  if(count == 9){
    count = 1;
  }
  else{
    count++;
    count %= 10;
  }
  return count;
}

int setCountMinus(int count){
  if(count==1){
    count = 9;
  }
  else{
  count--;
  count %= 10;
  }
  return count;
}

void loop()
{
  int i=-1;
  show(i);
  while(1){
    debouncert1.update();
    debouncert2.update();
    if(debouncert1.read()){
      i=setCountPlus(i);
    }
    if(debouncert2.read()){
      i=setCountMinus(i);
    }
    if(i==10){
      i=1;
    }
    show(i);
    delay(250);
  }
}

as for the errors.

sketch 65: error: 'Debounce' does not name a type
sketch 66: error: 'Debounce' does not name a type
sketch .ino: In function 'void loop()':
sketch 108: error: 'debouncert1' was not declared in this scope
sketch 109: error: 'debouncert2' was not declared in this scope

Any help would be great on fixing the code to stop getting errors.


texts: Why my Arduino Uno R3 doesn't work with a recompiled optiboot with BAUD_RATE=57600

texts:
This is a follow on question from How to reduce serial speed on Arduino bootloader (optiboot) and on the IDE?

I did manage recompile optiboot bootloader to work at 57600 bps and uploaded it to a couple of ATmega328-PUs. I just changed the BAUD_RATE to 57600L in Makefile and recompiled it.

They worked just fine with my Arduino Single Sided Serial (Severino) and a couple of custom standalone Arduino boards with FTDI-like header.

However, I couldn't program the same MCUs using my Arduino Uno R3. When I try to upload a sketch, avrdude just sits there waiting for a response that doesn't come. The output I got is something like this:

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Users\Ricardo\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.

Would that have anything to do with the 2nd MCU that acts as the USB driver on the Uno - the ATmega16U2? Do I have to patch it, too?

So, my questions are:

1. Why my recompiled optiboot didn't work with my Arduino Uno R3?

2. What can I do to check what's wrong with the upload process using my new bootloader?


texts:
I recently purchased an Esp32 and am doing some tests using Arduino IDE.
In one of the tests, I am recording a lot of .txt files with some text inside them in the flash memory, however, I would like to know how I can check the remaining space in the flash memory. I'm checking the flash memory space with Serial.println(ESP.getFlashChipSize());, however, the returned value is always the same.

Is this the right command to check? Why is it always with the same value?


texts:
I'm trying, what I thought would be simple, to wake a sleeping ESP8266 via motion detected by a PIR.

There are a lot of schematics around and they all seem to go about it more or less the same way, and the simplest form seems to be this:

Where RST is the RST pin of the ESP8266 and Trigger is the PIR's trigger line.

The problem I'm finding is that this is not working.

The PIR is working fine, and throws out almost 3v for 2 seconds when triggered and 0 when no motion is detected.

My ESP is being woken up when the PIR trigger is OVER, not when it STARTS. So if the PIR senses motion for a long time, the ESP will only wake up when the motion STOPS.

The PIR is one of these.

The ESP is currently a NodeMCU on breadboard, but the final product will be a Wemos D1 Mini.

What am I doing wrong here?


texts: Is there something I can use to control Arduinos easily over Ethernet with .NET?

texts: I'm wondering if there's anything out there that maybe works pretty similarly to Firmata, runs on Unos or Megas, and can be controlled over Ethernet. I am writing a home automation system with .NET, and I see some options for supporting Firmata with .NET, but I want to be able to connect my devices over Ethernet.


texts: I would like to be able to create permanent projects with my arduino Nano but be able to remove the nano in order to use it in other projects. The arduino Nano has 30 pins so I would be looking for some kind of female 30 pin header. Most of the headers that I found like that are too narrow because they are for IC's. Any ideas?


texts:
I need to simulate a pulse train. Everything is in order with this code, it solves its problem.
The question is: I need to change the keys, but it is too difficult to manually type in so many zeros and ones each time.
On the other hand, I know that my hexadecimal key looks much shorter: "B8C4F9".
Is it possible to create a string in such a way that the system itself translates to the binary system?
And the second question: How can you automatically measure the length of an array so as not to manually calculate KEY_LEN?
const int KEY_LEN = 24;
const char key[KEY_LEN] = {"101110001100010011111001"};

int T = 200; // Pulse repetition period in microseconds
int Zero = 80; //0.4*T; // Duration of zero in microseconds
int One = 120; //0.6*T;// Duration of a unit in microseconds

const int LED_PIN = 13; // Used digital pin 13 of the arduino to connect the transmitter

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  for (int n = 0; n < KEY_LEN; n++)
  {
    if (key1[n] == '1') //If the bit read == 1
    {
      sendSignal(One);
    }

    else if (key1[n] == '0')//If the bit being read == 0
    {
      sendSignal(Zero);
    }
  }
}

void sendSignal(int duration)
{
  digitalWrite(LED_PIN, LOW);
  delayMicroseconds(duration);
  digitalWrite(LED_PIN, HIGH);
  delayMicroseconds(T - duration);
}


texts: Making CS (chip select) work in SPI (for and SD card and OLED)

texts:
I'm working on a project that will log data to an SD card and display a user interface on an OLED. The SparkFun OLED breakout was super easy to set up. I was also able to get the SD-Card library working independently, though that was harder.

The trouble is when I combine these examples the SD card only writes during "setup" after that it isn't writing to the SD card as the loop continues. The OLED still works just fine.  I've read up on SPI a bit and tried various things to get "chip select" to work (I suspect this is the problem) I even tried setting the CS pins to LOW or HIGH using digitalWrite, but this had no impact.

My pins are connected as follows:

          SD CARD      OLED
MOSI        A5            A5     same pin
MISO        A4            --     just SD connected
SCK         A3            A3     same pin
CS          A1            A2     different pins

The SD card writes in the main loop if I comment out all of the code that runs the OLED. The OLED works either way.  What could I try next?

Here is the code:

 #include "application.h"
 #include "sd-card-library/sd-card-library.h"
 #include "SparkFunMicroOLED/SparkFunMicroOLED.h"
 #include "math.h"

 //////////////////////////////////
 // MicroOLED Object Declaration //
 //////////////////////////////////
 // Declare a MicroOLED object. If no parameters are supplied,
 // default pins are used, which will work for the Photon Micro
 // OLED Shield (RST=D7, DC=D6, CS=A2)
 // Since I use A1 as the chip select pin for the SD card these
 // defaults seem fine.

    MicroOLED oled;

 // Declare a file object?

    File myFile;

 // These are the pins for the SD card. A5, A4, and A3 are all
 // shared by the OLED.

    const uint8_t chipSelectSD = A1;
    const uint8_t mosiPin = A5;
    const uint8_t misoPin = A4;
    const uint8_t clockPin = A3;

 ////////////
 // setup //
 ////////////
 void setup() {
  delay(500);

  SD.begin(mosiPin, misoPin, clockPin, chipSelectSD);
  File dataFile = SD.open("data.txt", FILE_WRITE);
  dataFile.println("this text was printed to the SD card during setup");
  dataFile.close();

  oled.begin();  // Initialize the OLED
  oled.clear(ALL); // Clear the display's internal memory
  delay(1000);  // Delay 1000 ms
  oled.clear(PAGE); // Clear the buffer.
  randomSeed(analogRead(A0) + analogRead(A7)); //seed to make test pattern random.

               }//end setup

//////////////////
// main loop //
//////////////////
void loop()  {

  SD.begin(mosiPin, misoPin, clockPin, chipSelectSD);
  File dataFile = SD.open("data.txt", FILE_WRITE);
  dataFile.println("The text was added during the loop.");
  dataFile.close();

//test the display with text and pixels.
  printTitle("Pixels", 1);
  for (int i=0; i<512; i++)
  { oled.pixel(random(oled.getLCDWidth()),  random(oled.getLCDHeight()));
  oled.display(); }
   delay(9000);

               } //end loop

//-------------------------//
// function to print titles //
//-------------------------//
  void printTitle(String title, int font) {
  int middleX = oled.getLCDWidth() / 2;
  int middleY = oled.getLCDHeight() / 2;
  oled.clear(PAGE);
  oled.setFontType(font);
  // Try to set the cursor in the middle of the screen
  oled.setCursor(middleX - (oled.getFontWidth() * (title.length()/2)),
  middleY - (oled.getFontWidth() / 2));
  // Print the title:
  oled.print(title);
  oled.display();
  delay(1500);
  oled.clear(PAGE);
                                           } //end title function

This is how the SD card is hooked up.

  oled.begin();  // Initialize the OLED

Any attempt to use the SD card after this line will not work. I've looked for something like "oled.end()" but have not found a way to reset to the state where the SD card works.

I have tried commenting out all of the OLED code and then the SD card writes fine in the main loop. So, I started adding the OLED code back in. This line of code breaks the SD card writing in the main loop:


texts: ATTiny 85 analog input pin number problem

texts:
I am using AT Tiny 85 to read voltage from lead acid battery charger while charging.  Basically the setup has two 7-segment displays driven by two SIPO shift registers(74ls164n). And used tiny 85's pin 4 (physical pin3) to read voltage.

I tested the code using arduino and finally burned it to AT Tiny 85,   it didn't worked, i debugged it for hours, and pulled hair out of my head, tested it on bread board, eventually i changed the port to "A2" from "4" and surprisingly, everything runs as expected.

My question is why this happens? why analogRead(A2) works while analogRead(4) don't. ?

I am using Arduino IDE 1.6.5 with https://github.com/damellis/attiny  (1.0.1 installed from the board manager) .

Full Code:

//// Arduino Uno Pins
//const int data = 8 ; //Tiny pin 3 (Physical 2)
//const int clock = 9 ;//Tiny pin 2 (physical 7)
//const int battery_Sensor = A0; //Tiny pin 4 (physical 3)
//const int charger_ctrl = 5;   //Tinypin 1 (physical 6)

// ATTiny 85 Pins
const int data = 3 ;
const int clock = 2 ;
const int battery_Sensor = 4;
const int charger_ctrl = 1;

int outputValue = 0;
int sensorValue = 0;
int voltage_reading = 0;
int msb = 0;
int lsb = 0 ;

// Qo -> 1
// Q1 -> 2
// Q2 -> 4
// Q3 -> 5
// Q4 -> 6
// Q5 -> 7
// Q6 -> 9
// Q7 -> 10

char c_array[10] = { '0', '1', '2',  '3',  '4',  '5', '6',  '7', '8', '9'} ;

int measure_voltage(){
 sensorValue = analogRead(battery_Sensor);
 return map(sensorValue, 0, 1023, 0, 50);
}

byte seven_segment(char input, bool period){
  byte output_byte;
  switch (input) {
      case '0':
        output_byte = B11101110;
        break;
      case '1':
        output_byte = B10000010;
        break;
      case '2':
        output_byte = B11001101;
        break;
      case '3':
        output_byte = B01101101;
        break;
      case '4':
        output_byte = B00101011;
        break;
      case '5':
        output_byte = B01100111;
        break;
      case '6':
        output_byte = B11100111;
        break;
      case '7':
        output_byte = B00101100;
        break;
      case '8':
        output_byte = B11101111;
        break;
      case '9':
        output_byte = B00101111;
        break;
      default:
        output_byte = B00000001;
      break;
    }
  if(period == 1){
    output_byte = output_byte ^ B00010000;
  }
  return output_byte;
}

void setup()
{
  pinMode(clock, OUTPUT); // make the clock pin an output
  pinMode(data , OUTPUT); // make the data pin an output
  pinMode(charger_ctrl, OUTPUT);
  pinMode(battery_Sensor, INPUT);

}

void loop() {
    voltage_reading = measure_voltage() ; // voltage x 10
    msb = voltage_reading/10;
    lsb = voltage_reading%10;

    shiftOut(data, clock, LSBFIRST, seven_segment(c_array[lsb], 0));// send this binary value to the shift register
    shiftOut(data, clock, LSBFIRST, seven_segment(c_array[msb], 1));
    delay(1000);
}


texts: Arduino Uno rev 3 - what are the additional 2x3 set of pins for?

texts:
I recently bought Arduino Uno rev 3 board and I spent a lot of time trying to figure out the function of each individual pin. I googled all the fancy terms like IOREF, SDA, etc. and one by one I figured out the functional purpose for most of the pins.

However, there are few pins (actually pin groups) which have no labels around and I find it really difficult to figure out what these pins are supposed to do.

Again, I googled around and found this schematic from which I figured out that the 6-pin group  at the bottom is about something called ICSP (or at least this is what is written there). When I googled this term, I found this excellent explanation about the serial communication protocols.

However, at this point I am really confused.

The explanation about the serial protocols doesn't mention at all ICSP. By googling even further I only get more and more confused. Yes, I found the ICSP wiki page but I am not 100% sure that the bottom 6 pins are related to ICSP.
From the same schematic which I found I see there are 4 additional soldered pads with label JP2 right above them. Currently I have no clue about the function of these pads. Question 1 - what are these soldered pads for?
Right next to the JP2 stuff is a group of 6 pins (3 rows, 2 columns). The schematic is not clear about these pins. Question 2 - what is the purpose of these pins? Question 3 - where can I find the actual schematic (layout) about each individual pin?
I am not 100% sure that the bottom group of pins (2 rows, 3 columns) is related to ICSP. Maybe that's the case, maybe it's not. Question 4 - what is the purpose of these pins? Question 5 - where can I find the actual schematic (layout) about each individual pin?

Thank you in advance for your help!


texts:
So I recently bought this off brand arduino uno from betemcu.cn.
it says its r3 compatible.

Can I program this thing with the arduino coder or do I need to use something else? whenever I try uploading the code it says "problem uploading to board"

what settings or program should I use to code this?


texts: Denoising accelerometer data mounted on moving vehicles

texts:
Can you suggest a method for denoising accelerometer data mounted on moving vehicles?
I have read several suggestions like using Kalman filter, moving average, etc. but I'm not sure which suit best in my application. Further, I am hoping to extract smoothed data in a real-time manner since they are inputs for a classification algorithm.
Thank you :-D


texts:
How can I return a char array from a function?

char c[] = getFloat(val, valid);

char getFloat(float val, bool valid){
      if(valid){
        char stringFloat[16];
        dtostrf(val, 10, 8, stringFloat);
        return stringFloat;
      } else Serial.print("No Float");
    }


texts: How much current does an Arduino Mega draw from a LiPo battery (5,000 mAh)?

texts:
I went through Sparkfun's website on how to power a project because I wanted to calculate how much battery capacity I needed for my project. I saw an ATmega 328 micro-controller that is used as the brains for the circuit: it draws about 20mA under normal conditions.

So that got me thinking: how much current will an Arduino Mega draw from a LiPo battery of 7.4V with 5,000 mAh 2s 25C under normal condition? Please anyone do help me out and pardon me, I am new to this.


texts: Why can't my .cpp file have a class of the same name?

texts:
I made a new Arduino IDE project ABC, and am given ABC.ino. Then I create a XYZ.h and XYZ.cpp.

ABC.ino:

#include "XYZ.h"

void setup() {}
void loop() {}

XYZ.h:

#ifndef XYZ
#define XYZ

#include "Arduino.h"

class XYZ { };

#endif

XYZ.cpp:

#include "Arduino.h"
#include "XYZ.h"

When I try to compile this, I get some error:

In file included from sketch/XYZ.cpp:2:0:
XYZ:8: error: abstract declarator '<anonymous class>' used as declaration
 };
 ^
exit status 1
abstract declarator '<anonymous class>' used as declaration

However, when I rename my class to something other than the file name, like XYZa, the compilation succeeds.

Why can't I have the same name class as the file?

I've done C++ projects (independent of Arduino) via Xcode and nano, and this has never been a problem.


texts: Unable to receive data when using multiple SoftSerial on Arduino Nano

texts:
I am trying to use several (four) software-based serial ports to talk to different peripheral hardware. However, I am unable to receive data through the SoftSerial when using more than one software serial port.

I tested each pair of pins be defining it to the first port. All pairs are working as desired. In addition, I am only interested in bridging/piping from a software serial port to the hardware serial (for debugging reasons).

My code is as follows:

#include <stdint.h>
#include <SoftwareSerial.h>

#define SOFT_SERIAL_A_RX        5
#define SOFT_SERIAL_A_TX        6
#define SOFT_SERIAL_B_RX        7
#define SOFT_SERIAL_B_TX        8
#define SOFT_SERIAL_C_RX        9
#define SOFT_SERIAL_C_TX        10
#define SOFT_SERIAL_D_RX        11
#define SOFT_SERIAL_D_TX        12

#define SERIAL_BAUD_RATE        9600

SoftwareSerial softwareSerials[] = {
    SoftwareSerial(SOFT_SERIAL_A_RX, SOFT_SERIAL_A_TX),
    // Unable to receive data on first software serial when un-commenting following lines.
    // All pins are working when declaring each pair for first software serial (tested pins by doing this)
    // SoftwareSerial(SOFT_SERIAL_B_RX, SOFT_SERIAL_B_TX),
    // SoftwareSerial(SOFT_SERIAL_C_RX, SOFT_SERIAL_C_TX),
    // SoftwareSerial(SOFT_SERIAL_D_RX, SOFT_SERIAL_D_TX)
};
const uint8_t numberSoftwareSerials = sizeof(softwareSerials)/sizeof(*softwareSerials);

void initHardwareSerial()
{
  Serial.begin(SERIAL_BAUD_RATE);
}

void initSoftwareSerials()
{
    for(uint8_t i=0; i<numberSoftwareSerials; i++) {
        softwareSerials[i].begin(SERIAL_BAUD_RATE);
    }
}

void setup()
{
    initHardwareSerial();
    initSoftwareSerials();
}

void loop()
{
  // Only one software serial can be used (receive/transmit) at once.
  // So just using a single software serial port (first element from array)
  if (softwareSerials[0].available()) {
    Serial.write(softwareSerials[0].read());
  }
  if (Serial.available()) {
    softwareSerials[0].write(Serial.read());
  }

}

How can I narrow down the issue of being unable to receive when defining several serial ports? If there is no suitable solution I might switch to an Arduino Mega with its four hardware ports (would need only one additional software serial in that case), but an Arduino Nano is strongly preferred due to smaller footprint.


texts: Including an arduino library in Eclipse Neon (undefined reference to)

texts:
I'm trying for the first time to use Arduino Libraries (Servo.h & Servo.cpp in this case) in Eclipse IDE.

So far I've managed to compile and run Arduino code using this tutorial (I suppose many of you already know it).

The problem comes when I add the Servo.cpp and Servo.h files and try to run the program:

    13:35:08 **** Incremental Build of configuration Release for project Servo ****
make all
arduinoEclipse/subdir.mk:268: warning: overriding commands for target `arduinoEclipse/wiring_pulse.o'
arduinoEclipse/subdir.mk:261: warning: ignoring old commands for target `arduinoEclipse/wiring_pulse.o'
Building file: ../ServoTest.cpp
Invoking: AVR C++ Compiler
avr-g++ -I"C:\arduino\arduinoEclipse" -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega328p -DF_CPU=1600000UL -MMD -MP -MF"ServoTest.d" -MT"ServoTest.o" -c -o "ServoTest.o" "../ServoTest.cpp"
Finished building: ../ServoTest.cpp

Building target: Servo.elf
Invoking: AVR C++ Linker
avr-g++ -Wl,-Map,Servo.map,--cref -mrelax -Wl,--gc-sections -mmcu=atmega328p -o "Servo.elf"  ./arduinoEclipse/CDC.o ./arduinoEclipse/HardwareSerial.o ./arduinoEclipse/HardwareSerial0.o ./arduinoEclipse/HardwareSerial1.o ./arduinoEclipse/HardwareSerial2.o ./arduinoEclipse/HardwareSerial3.o ./arduinoEclipse/IPAddress.o ./arduinoEclipse/PluggableUSB.o ./arduinoEclipse/Print.o ./arduinoEclipse/Servo.o ./arduinoEclipse/Stream.o ./arduinoEclipse/Tone.o ./arduinoEclipse/USBCore.o ./arduinoEclipse/WInterrupts.o ./arduinoEclipse/WMath.o ./arduinoEclipse/WString.o ./arduinoEclipse/abi.o ./arduinoEclipse/hooks.o ./arduinoEclipse/main.o ./arduinoEclipse/new.o ./arduinoEclipse/wiring.o ./arduinoEclipse/wiring_analog.o ./arduinoEclipse/wiring_digital.o ./arduinoEclipse/wiring_pulse.o ./arduinoEclipse/wiring_shift.o  ./ServoTest.o
./ServoTest.o: In function `setup':
ServoTest.cpp:(.text.setup+0x8): undefined reference to `Servo::attach(int)'
./ServoTest.o: In function `loop':
ServoTest.cpp:(.text.loop+0x20): undefined reference to `Servo::writeMicroseconds(int)'
ServoTest.cpp:(.text.loop+0x5a): undefined reference to `Servo::writeMicroseconds(int)'
ServoTest.cpp:(.text.loop+0xbc): undefined reference to `Servo::write(int)'
./ServoTest.o: In function `_GLOBAL__sub_I_myservo':
ServoTest.cpp:(.text.startup._GLOBAL__sub_I_myservo+0x4): undefined reference to `Servo::Servo()'
collect2.exe: error: ld returned 1 exit status
make: *** [Servo.elf] Error 1

As you can see in the console output, it compiles correctly, but when it comes to the linker, it doesn't find the function references from the Servo.cpp.

As I have seen in this post, the problem comes from the fact that I need also to generate an .a (static library) file in order to link both .h and .cpp files. Still, I have no idea how I am supposed to generate this file.

For this project, I have just added in arduinoEclipse folder all the .cpp and .h files from C:\arduino\hardware\arduino\avr\cores\arduino, C:\arduino\hardware\arduino\avr\variants\standard & C:\arduino\libraries\Servo.

Do you see what I could be missing?

Thank you in advance


texts: for loop reads pots, passes value to PWM pins, can this be in the same for loop?

texts:
In the code below I am using a for loop to iterate over analog pins (potentiometers) and pass their value, after being mapped, to PWM enabled analog output pins (currently controlling LED brightness). While this works as is, I am curious about the following: would it be better to split the analogRead and analogWrite lines into separate for loops, or would that simply be redundant from a code standpoint? My concern is accidentally mixing up the pot values due to difficult-to-perceive timing issues.

The code:

static const uint8_t analog_pins[] = {A0, A1, A2, A3};
static const uint8_t digital_pins[] = {3, 5, 6, 9};
int pot_vals[] = {0, 0, 0, 0};
int val[] = {0, 0, 0, 0};

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

  // setup inputs, outputs
  for ( int i = 0; i < 4; i++ ) {
    pinMode( analog_pins[i], INPUT );
    pinMode( digital_pins[i], OUTPUT );
  }
}

void loop() {
  for (int i = 0; i < 4; i++) {
    val[i] = analogRead(analog_pins[i]);
    analogWrite(digital_pins[i], map( val[i], 0, 1023, 0, 255 ));
  }
  delay(2);
}


texts: esp32 pico kit - actual clock speed vs crystal vs max_speed etc

texts:
I am trying to understand how the clock speed in the esp32 works.
I am running arduino ide 1.8.12 with 1.04 board definition - on a pico kit 4 module .
The device datasheet says it has a 40mhz crystal.
getCpuFrequencyMhz() reports 240mhz
But the following code is generating 1sec interrupts with 80mhz as a base i.e., as if the clock speed is 80mhz.
If I explicitly set the clock speed to 80 mhz then getCpufrequency correctly reports it as 80, and the code still keeps generating 1sec interrupts (as it should at 80). If I set the clock to 40mhz then I finally see interrupts at 2 secs as would be expected. What is the deal with the 240 report for what is actually 80 and where is 80 coming from on a supposedly 40 mhz part?
I am sure that the explanation is somewhere in expressif's docs, but I have been unable to glean it. Can anyone quickly explain what is going on or point me to some resource that explains this particular circumstance?
---------------
Sample output
getCpuFrequencyMhz() = 240
interrupts so far = 1 - : - mills() = 1018
interrupts so far = 2 - : - mills() = 2018
interrupts so far = 3 - : - mills() = 3018
interrupts so far = 4 - : - mills() = 4018
interrupts so far = 5 - : - mills() = 5018

----------------Sample code
#include "esp32-hal-cpu.h"

volatile int interruptCounter;
int totalInterruptCounter;

hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR onTimer() {
  portENTER_CRITICAL_ISR(&timerMux);
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&timerMux);

}

void setup() {

  Serial.begin(115200);

  Serial.printf("getCpuFrequencyMhz() = %d\n",getCpuFrequencyMhz()); //Get CPU clock

  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmWrite(timer, 1000000, true);
  timerAlarmEnable(timer);

}

void loop() {

  if (interruptCounter > 0) {

    portENTER_CRITICAL(&timerMux);
    interruptCounter--;
    portEXIT_CRITICAL(&timerMux);

    totalInterruptCounter++;

    Serial.printf("interrupts so far = %d - : - mills() = %d \n", totalInterruptCounter, millis());

  }
}


texts: How to serial connect arduino galileo to alarm system

texts:
i'm a little new in this.
I have an alarm system panel which has TX,RX wires with 12V output/input.

how can i  read the output with arduino and control it with serial communication?


texts: There are several different types in the Arduino programming language. They each have different applications that can use up the limited RAM in the Arduino. When should i use each?


texts:
I'm trying to use the last version of leOS2 scheduler from Leonardo Miliani ( https://github.com/leomil72/leOS2 ) but I have a strange behavior with a very simplistic ONETIME task.

Platform : Arduino Uno clone, so Atmel Atmega 328P CPU.

My code is very straightforward :

#include "leOS2.h"
leOS2 myOS; //create a new istance of the class leOS

bool test = true;

void setup()
{
    myOS.begin(); //initialize the scheduler
}
void loop()
{
    // Do some stuff ...

    if(test)
    {
       DoAndUndo(3000);
       test = false;
    }
}

void DoAndUndo(unsigned long duration)
{
    doSomething();

    myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME);
}

void doSomething()
{
    Serial.println("thing on");
}

void cancelTheThing()
{
    Serial.println("thing is off");
}

In case it can be some kind of conflict, my code also relies on the following :

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

The problem is :
        myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME);
is supposed to call asynchronously the "cancelTheThing" method 3 seconds later, and for only one time, and then forget it.
But for an unknown reason, it's called after the expected delay, but it loops infinitely on this method ! In the example case above, my serial stream is filled with a lot of "thing is off" messages, and the µc is unresponsive to anything apart a reset.

The call to DoAndUndo() will produce a such like output :

 thing on

And 3s later, in a very fast infinite loop :

 thing is off
 thing is off
 thing is off
 thing is off

If I remove the "ONETIME" flag, the task is called every three seconds (exactly as it's suppose to do, so the scheduler works, but it's not what I want in my use case).

note : As a try of workaround, I've tried some tricks like calling haltScheduler() inside my cancelTheThing() and reenable it with restartScheduler() in DoAndUndo(), and also tried to call removeTask once it has ran, but it didn't help.

Thank you for your help


texts:
I have the app opened even after force quitting.
I also tried the activity monitor but nothing about Arduino was there except the web editor plugin.
I am using macOS which is why I talked about the activity monitor. Task manager in Windows. I was using the web editor and while it was uploading I opened the Arduino IDE that was not online. It has closed correctly before.


texts: I'd like to decode a PNG on an ESP8266 and access to some pixels of the result. Has anyone got experience with PNG on Arduino? Is it feasible at all? I've done some research on PNG decoding libraries, found UPNG. Will check if it can be used in Arduino/ESP.


texts: Serial.print prints but lcd.print does not

texts:
The following code reads a txt file from a SD card, finds the corresponding character and prints the next 12 characters:

...
      char temp;
      byte who = random(1, 13); // 1 to 12
      temp = findName(who);
      Serial.print(who);
      Serial.print("  ==> ");
      Serial.println(temp);
...

    char findName (byte number) {
      char text[12];
      byte i;
      txt = SD.open("test.txt");
      txt.seek(12 * (number - 1));
      for (i = 0; i < 11; i++) text[i] = txt.read();
      txt.close();
      return text;
    }

But the following, on a LCD, does not. (setCursor, etc. ommited for clarity)

...
char temp;
byte who = random(1, 13); // 1 to 12
temp = findName(who);
lcd.print(who);
lcd.print("  ==> ");
lcd.print(temp);
...

I'm certain the cause is a variable data type mismatch, but I don't know how to solve it. Any help is appreciated.

Thank you.


texts:
In one of my earlier questions it was determined for me that my Futaba Servo should not be powered directly from the 5v pin of my Arduino and should instead be powered by an alternative source. I was told the Servo requires a “high current 5 volt power supply” so I’m wondering what my best options are as my knowledge in servo control is quite limited. Is there some type of board that helps with this? Do I need a specific battery? If the servo needs a battery could it run off of the same battery as the arduino? Im trying to keep my design as compact as possible so multiple battery packs could pose complications.
The specific information can be found here.
Thanks for any help!


texts: Referencing local libraries from higher dir levels

texts:
How can I include libraries not contained in any direct subdirectories of a sketch, using the Arduino IDE?

I want my project structure to look like this:

Project
└> MCUa
   └> MCUa.ino
└> MCUb
   └> MCUb.ino
└> Libraries
   └> TimerLib
      └> TimerLib.cpp
      └> TimerLib.h

So in my project two sketches MCUa and MCUb share a resource, namely the library TimerLib.

I've tried to include the libraries like this:

#include "../Libraries/TimerLib/TimerLib.h"

or this:

#include "./../Libraries/TimerLib/TimerLib.h"

But none of them will compile - this is the error message:

fatal error: ./../Libraries/TimerLib/TimerLib.h: No such file or directory
 #include "./../Libraries/TimerLib/TimerLib.h"
                                              ^
compilation terminated.
exit status 1
Error compiling.

If I put the library directly in of the directories and reference it like this:

#include "./Libraries/TimerLib/TimerLib.h"

Everything goes well.

Using an absolute path like in this answer is not a possibility in this case, as it should compile out of the box for others, without modifying any absolute paths.


texts: Pros and Cons of using a non-pointer class object

texts:
In this example I have an one object which uses a pointer and one object which does not.

class MyClass {
  public:
    void myMethod() {
      // do nothing
    }
};

MyClass* mc1;
MyClass mc2;

void setup() {
  mc1 = new MyClass();
}

void loop() {
  mc1->myMethod();
  mc2.myMethod();
}

Is one implementation better than the other? Why?


texts: Can client IP address be obtained from Arduino Ethernet2 library for W5500 during client.connected() call?

texts: I've found posts explaining how to get client IP by modifying the W5100 Ethernet library and the Adafruit CC3000 library but not the Ethernet2 lib for W5500 chip, which is different enough that the W5100 mod won't work. I suspect the TCP Socket struct will contain it, but haven't been able to find its declaration anywhere to confirm this so I can modify the library to make it accessible.


texts:
I am planning to use an Arduino (Nano ideally, or Other) to send and receive information from several software serial ports to other arduinos, over their available pins, ideally 8 ports.

I could understand an Asynchrounous Communication having one master and 8 slaves, with the master enabling communication from one port, receiving the data from that port, and then move onto the next port, into a sampling loop.

The SoftwareSerial library allows to set up the pins individually, and set the listen() port (thanks Juraj).

I read the AltSoftSerial library handle some of the limitations of the SoftwareSerial library, but I just realized the pins cannot be configured (without... cloning the full library?).

Question is:

Option 1: Should I stick with the SoftwareSerial library?,
Option 2: Should I try the AltSoftSerial library, and figure how to duplicate it (i think this is a NO)?
Option 3: Understand that none of these libraries are prepared for this, and seek for other alternative?
Option 4: It is pointless to have several serial trunks in Arduino, if only one will work at a time, and should hence try to arrange just one serial trunk?