texts: how to differentiate in code between Sangunio and Microduino core+

texts:
Sanguino and Microduino core+ both uses ATMEGA644PA. I need to write a piece of code in my library where I need to check what board has been selected.

#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#   define TIMER_PWM_PIN  11             // Arduino Mega
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)// Sanguino or microduino
#    define TIMER_PWM_PIN  13        //Sanguino PD5
#elif defined(__AVR_ATtiny84__)
# define TIMER_PWM_PIN  6
#else
#   define TIMER_PWM_PIN  9              // Arduino Duemilanove, Diecimila, LilyPad, etc
#endif

If I used the above code #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)// Sanguino or Microduino will be true for both Microduino and Sanguino.

Is there a way I can know which one is it?

Here is the board.txt section for Microduino core +

##Microduino Core+ (644pa)
##############################################################
644p.name= Microduino/mCookie-Core+ (644pa)

644p.upload.tool=avrdude
644p.upload.protocol=arduino

644p.bootloader.tool=avrdude
644p.bootloader.unlock_bits=0x3F
644p.bootloader.lock_bits=0x0F

644p.build.board=AVR_PLUS
644p.build.core=arduino
644p.build.variant=plus


texts: Field Programming a Arduino with another Arduino with SD card over RX/TX lines

texts:
I am not sure if this question has been asked before but here's what I wanted to do.

I have a Arduino Nano, which I need to update with a new sketch. The plan is to be able to use another Arduino (maybe a Nano again), with an SD card reader and a sketch loaded as HEX file on it. Then connect both using a 4 pin RX/TX/5V/GND and upload the sketch from the transmitter to the receiver. Is it possible?

I am not sure how to do this; I know I can use one Arduino as an ISP to update other, but I am thinking of streaming the hex file to the other. Has anyone done this, any hints would be extremely helpful.


texts: Bluetooth Modules not communicating correctly

texts:
I plug in BT rx to digital 11, BT tx to digital 10 and then 5v and ground from the HC-05 to the arduino. I then upload this code to the HC-05 that is set as a master.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

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

void loop() { // run over and over
  Serial.println(mySerial.read());
  delay(2000);
}

I then upload this code to the arduino with the HC-05 that is set as a slave:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11); // RX , TX

void setup() {
  // put your setup code here, to run once:
  mySerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  mySerial.write("100");
  delay(2000);
}

The issue is that I never receive "100" on the serial monitor, I only ever receive 49 and occasionally 48. When I changed it from "100" to "10" same thing happened. Any help would be appreciated.


texts:
I am making an RGB LED project right now using the Arduino UNO board.

At this point everything is working fine so I would like to transfer this onto a small microcontroller circuit to be put inside the enclosure. Since the enclosure is small, I cannot fit the UNO board inside it, hence I want to make a small circuit on perfboard with minimal components.

I read that you can burn the arduino bootloader on a standalone AVR (hooked up to power, filter caps and 16Mhz crystal) which can then execute Arduino code.

Any idea how can I do this? Also can I do this on an ATmega8l AVR, since my code is small enough to fit in one? No point wasting a 328 if 8L can do the job.

Thanks!


texts: Arduino only accepts one programming update per laptop boot

texts: I am only able to upload the code to my Arduino Uno once, and then I have to restart my laptop to do it again.  I am using Ubuntu.  What could be causing an issue like this?


texts:
How much current can I put through the pins of an Arduino Mega at the same time?

The situation: I am building a 7x7x7 LED cube, and my plan was to multiplex in 7 layers of 49 pins, lighting each layer, one at a time. This would mean each pin on the Arduino Mega would only have to supply max. 1 LED at a time.
However, if all 49 LEDs in one layer were on, it would presumably draw 49*20mA (from the LED specs sheet), which is 980mA. This seems like quite a lot of current to put through an ATMega chip, so I was wondering if I could do it, either continuing like this, or using transistors to control the lighting of each layer, or what?
Any help or advice is appreciated!

EDIT: Using ATMega2560, not ATMega328 or alternate.


texts: Arduino buzzer code sequence not triggering

texts:
I have a problem with my arduino buzzer:
the code should be doing the following:
I have a security system where in order to open the door you have to enter a 4 digit code from the remote. If the code is correct the door opens. if not you can try again.
You have 3 chances to try to enter the pin before an alarm goes on. here comes the problem: the alarms code triggers but the buzzer isn't making any sound.
here is the code for the alarm sound:
if (tryCount>=3) { // if the pin is wrong 3 times we sound an alarm
    Serial.println("got in alarm");
    while(true) {
        Serial.println("got in while");
        noTone(buzzer);
        tone(buzzer,100,300);
        delay(300);
        noTone(buzzer);
        tone(buzzer,1000,300);
        delay(300);
    }
}

here is the proof the alarm code triggers:

here is the full code:
https://create.arduino.cc/editor/mihimbc/8ec2fe30-d812-45cc-b0ae-850b437eb05b/preview
and here is the hardware schematics:


texts: Will this AC-DC converter chip really work with arduino?

texts:
I am looking for a compact solution to convert some 220V/20amp AC to something edible by our arduinos (like 5V/2amp DC). I would like to plug directly my arduino to the wall. I found many things like some Hi-link (HLK-PM01) chips ... But I also found this one :

LNK564DN - US $0.34 / piece
LNK564DN - US $1.14 / piece

That seems perfect, but unfortunatly, I can not find any tuto or example of use for this, shipping included, really cheap chip.

The datasheet is here.

What do you think about it ?


texts: Receiving multiple Values from android via Bluetooth

texts:
my question is, how can I receive 3 integer values in Arduino, which I send from my android phone. I send all 3 values at the same time and I also need to read them in about the same time.
I hope you can help me.


texts:
Looking at this shield here: https://store.arduino.cc/arduino-ethernet-shield-2

It states that "Connection speed: 10/100Mb". However from looking at various forums it appears that no one can get much more than 300Kb/sec with this device?

Can anyone explain what causes this limitation and how to overcome it? If its SPI that is the bottleneck is there some alternative? I am looking to get speeds of 6 mega bytes per second or more using a TCP connection.

I am extremely new to all this so apologies if I've missed something extremely obvious here. I also had a look at bluetooth/wifi shields but it appears they seem to also have some similar throughput issues. USB looked like it could work but is extremely complex for a newbie.


texts: WiFi connection times out if credentials retrieved via serial terminal

texts:
I've implemented a small WiFi connection procedure into my ESP32 project.
The available networks get printed with index, then I'm entering the index and retrieve the network name from it. The password is entered via serial in clear text.

Before connecting, I'm printing the credentials and thus could confirm they are read into const char * strings properly.

Unfortunately when using this procedure the connection to my AP times out. I've also tried to override the strings with hardcoded values and then the connection works as expected.

while (!Serial.available()) {
    // (timeout is implemented here)
}
String index_s = Serial.readStringUntil('\n');
long index = index_s.toInt();

// { same while as above }
String passw = Serial.readStringUntil('\n');

const char *ssid = WiFi.SSID(index).c_str();
const char *pass = passw.c_str();

// with this it works:
// ssid = "my_network";
// pass = "my_password";

Serial.printf("connecting to %s using %s", ssid, pass);
WiFi.begin(ssid, pass);


texts: Arduino Mega resets when DFPlayer speaker plugged into amp!

texts:
I have a MP3 DFPlayer Mini connected to a Mega2560. I'm using serial to control it. The Mega is powering/grounding the DFPlayer, and USB is powering the Mega. If I plug a small speaker directly to the DFPlayer speaker pins, I hear the audio as expected. Tracks play correctly, at the proper volume, etc.

I also have a 20w audio amplifier (MAX9744, and 20w speaker ofc), powered separately by a 12v DC wall plug. If I plug an iPod into that via the stereo jack, I hear nice loud audio, as expected. Everything is fine.

For months, I have had the DFPlayer speaker pins supplying audio into the headphone jack on the amplifier. It has been working perfectly. Until recently...

Now, for some reason, the Mega2560 instantly resets, and will continue to reset every couple of seconds while the speakers are plugged in to the amplifier. As soon as the line in stereo jack is removed from the amplifier, the Mega works again.

This has me completely stumped. This setup has previously been working perfectly, for several months. The amplifier is clearly affecting the Mega somehow (via the DFPlayer!), even when no audio is actively playing. But I'm stuffed if I can figure out where the problem is!

I appreciate any ideas and suggestions you may have.


texts: How can you check how long a timer interrupt really is?

texts:
I'm trying to set a 33 ms interrupt on my Arduino Mega and I'm not sure if I a in fact getting that kind of delay time. Is there a way to check?

I've calculated that that I need 515.6 ticks to achive this kind of delay with a prescaler of 1024 and I've coded it up like so:

void setupInterupt()
{
  noInterrupts();
  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2 = 0;
  OCR2A = PERIOD - 1;
  TIMSK2 = _BV(OCIE2A);
  TCCR2B |= _BV(CS12) | _BV(CS10); // prescale by 1024
  interrupts();
}

I followed the information on the Arduino Playground page and if my math is correct this interrupt should be going off every 33 milliseconds. I tried to test that using the millis(); method but it only returns the time that program was on.


texts: Unable to retrieve heart rate reading and send to JY-MCU Bluetooth

texts:
Hello Arduino Community,

I am encountering an issue trying to retrieve a heart rate reading from an op-amp and instrumentation amplifier and sending it via Bluetooth.  I used this website as a basis of my design:  http://www.instructables.com/id/Electrocardiograph-Heart-Rate-Monitor/?ALLSTEPS.  I would appreciate it if you could take a look at that.  Here are a couple of pictures of my design.

Here is the code that I used:

    const int  signal = 7;    // Pin connected to the filtered signal from the circuit
    unsigned long time;
    unsigned long frequency;

    // Internal variables
    int period = 2000;
    int starttime = 2000;
    int input = 0;
    int lastinput = 0;
    unsigned long death = 0;

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

     void loop() {
       delay(1000);

       time = millis();
       input = digitalRead(signal);

       if ((input != lastinput)&&(input == HIGH)) {
       // If the pin state has just changed from low to high (edge detector)
       period = time - starttime; // Compute the time between the previous beat and the one that has just been detected
       starttime = time; // Define the new time reference for the next period computing
       death = time;
      }
      lastinput = input; // Save the current pin state for comparison at the next loop iteration

      if (period < 0) {
      frequency = 0;
      }
      else {
      frequency = 60000/period; // Compute the heart rate in beats per minute (bpm) with the period in milliseconds
      }

      if ((time - death) > 2000) { // Detect if there is no beat after more than 2 seconds
      Serial.println("dead");
      }

      else {
      char freq[3];

      if (frequency/100 == 0) {
       freq[0] = 32; // Print a space to the first character if the frequency is below 100 bpm
      }
      else {
       freq[0] = frequency/100+48; // Sort the hundreds character and convert it in ASCII
      }
       freq[1] = (frequency/10)%10+48; // Sort the thents character and convert it in ASCII
       freq[2] = frequency%10+48; // Sort the units character and convert it in ASCII

      Serial.print(freq);
      Serial.print("alive! ");
      }

      }`

But all I'm getting as output is 'dead'.  I am really starting to lose it here since I am a complete amateur with Arduino and circuitry.  For reference, I copied the design from this image from the website (this is just an enlarged version): http://www.instructables.com/file/FVBC6TYHOW0HQ7H/?size=ORIGINAL.  I would appreciate it if anyone could provide some extra guidance.


texts: Can you use clang, with --mpu=arm, etc. and avrdude to program an Arduino Due (Arm Cortex M3)?


texts:
I am new to the Arduino world. I have a question regarding current that the Arduino outputs over its 5V port. Why is the current in the Arduino too weak for current hungry circuit when the only thing that changes in this equation V=IR is the current itself.

For instance, the voltage in an Arduino is restricted to 5 volts. Assuming that the resistance of the current stays the same, shouldn't the current also increase (following Ohm's law) over its 5V port? More specifically, I am talking about powering ESP8266 with an Arduino.


texts: Run Stepper with A4988 driver in highest resolution

texts:
I have a Bipolar Stepper Motor (12V, 350mA, 28oz-in NEMA-17) and would like to run it in the highest resolution (Sixteenth Step) with the A4988 Driver. According to multiple sources I read I need to "put 5V" to the MS 1,2,3 pins. What does this mean/How can I achieve this ?

Do I need to hook up the MS 1,2,3 to the digital pins of the Arduino and write Digital High. Or do I need to hook all of them to 5V together ? And should the code look like this ? Is this safe/good pratice ?

int MS1Pin = 8;                 // Set MS Pins
int MS2Pin = 9;
int MS3Pin = 10;

void setup()
{
  pinMode(MS1Pin, OUTPUT);      // sets the digital pin as output
  pinMode(MS2Pin, OUTPUT);      // sets the digital pin as output
  pinMode(MS3Pin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(MS3Pin, HIGH);
  digitalWrite(MS2Pin, HIGH);
  digitalWrite(MS1Pin, HIGH);
<<MY CODE here>>

}

Sorry for these beginner questions, I just don't want to fry the Chip and this to work.

Thank you.


texts:
I made a sample using two of them using Arduino UNO.
So I did that like this:

(There aren't any resistor on that image, but there are 220ohm resistor on every LEDs.)
And uploaded this code.

//1.6us+62.5ns
#include <SPI.h>

#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))

int latchPin = 12;
int clockPin = 13;
int dataPin = 11;

byte data[]={ 0b10101010,0b11001100 };

void _595_out() {
    cbi(PORTB, 4);
    SPI.transfer(data[0] );
    SPI.transfer( data[1] );
    sbi(PORTB, 4);
}

void setup() {
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);

    SPI.setClockDivider(SPI_CLOCK_DIV2);
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.begin();
}

void loop() {
    _595_out();
}

And this worked as I expected. But, when I changed sketch like this,

//1.6us+62.5ns
#include <SPI.h>

#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
#define CHIPNO 2
int latchPin = 12;
int clockPin = 13;
int dataPin = 11;

byte data[]={ 0b10101010,0b11001100 };

void _595_out() {
    cbi(PORTB, 4);
    SPI.transfer(data[0]);
    SPI.transfer(data[1]);
    sbi(PORTB, 4);
}

void setup() {
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);

    SPI.setClockDivider(SPI_CLOCK_DIV2);
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.begin();
    Serial.begin(9600);
}

void loop() {
    for(unsigned int z = 0; z < 65535; z++) {
        data[0] = z & 255;
        data[1] = (z & 65280) >> 8;
        Serial.println("A");
        Serial.print(data[0]);
        Serial.print("/");
        Serial.println(data[1]);
        Serial.println("B");
        _595_out();
        Serial.println("C");
        delay(500);
    }
}

74HC595s aren't working. Any LEDs aren't on.
Printing Serial works well. Only 74HC595s aren't working.
And Removing all Serial-related thing doesn't solved this problem.
Where did I do wrong?


texts:
I just purchased a set of 10 nRF24l01+ modules with a breakout board that looks like this:

Note: This is the nRF24l01+ chip, not a clone Si24Ri. Also, I'm using an Arduino Mega.

I'm following the Sparkfun tutorial here:
https://learn.sparkfun.com/tutorials/nrf24l01-transceiver-hookup-guide

The wires are hooked up like so:

3.3V → VCC
GND → GND
PWM 8 → IRQ
PWM 9 → CE
PWM 10 → CSN
PWM 11 → MOSI
PWM 12 → MISO
PWM 13 → SCK

I've verified the two modules are hooked up as they should be. I'm using the GettingStarted example program for both units. Whenever I go into the serial monitor when connected to the transmitter, I get garbage values like <¯�SžRÖ being output. Whenever I try to transmit a message by entering t, nothing gets returned. The same problem is happening on the receiver end.

As for troubleshooting:

I've wiggled all of the jumper cables to verify a stable connection.
I've swapped out the modules I was using with others from the package (twice) so the modules probably aren't bad.
After reading that a capacitor is sometimes needed to provide a smoother voltage to the module, I upped the voltage from the 3.3V the Arduino was providing to a stable 3.5V from an external variable power supply to account for any small voltage dips. I don't have any capacitors available to me at the moment, so I figured this would be the next best option.

Unfortunately, my RF modules are still not correctly transmitting any data, and I don't know where to go from here.


texts:
I'm building a basic program that when a button is pressed, a buzzer comes on.

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds).

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;      // variable for reading the touchsensor status

void setup() {
  // initialize the buzzer as an output:
  pinMode(buzzer, OUTPUT);
  // initialize the touchsensor as an input:
  pinMode(touchsensor, INPUT);
}

void loop() {
  // read state of the pushbutton value:
  touchsensorState = digitalRead(touchsensor);

  // check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
  if (touchsensorState == HIGH) {
    // buzzer will emit sound:
    digitalWrite(buzzer, HIGH);
  } else {
    // buzzer will not sound:
    digitalWrite(buzzer, LOW);
  }
}


texts:
I'm using Arduino Pro Micro (5v version) in one of my project for my car. The car's 12V +ve connected to RAW input of ProMicro and everything seems to work perfectly until I crank the ignition of my car.
Here's what actually happened, my circuit works perfectly fine when car's ignition is in ON state. However, as soon as I started my car the voltage dropped from 12v to between 9-10volt and the LG33 (SMD voltage regulator) burned out. Now, I want a good solution as what should I do now?
I have already LM2596 DC 3A Step-Down regulator. So should I use that to step-down 12v to 5v OR is there anything else I can do which might be a better solution?


texts: Programming Questions / Capacitive Soil Moisture Sensor

texts:
Good day All,
This is my first time posting to this forum and kind off my last resort as I would've liked to figure it out myself. I am trying to create a soil moisture probe which can be used on farms to determine soil moisture at different depths. The project consists of a Arduino Nano, a DIY capacitive moisture reading setup (schematic attached- My setup is the same except for the LED moisture indicator)) and an LCD screen to display the required value.
My initial setup was a Arduino Nano (328P Old Bootloader) with a resistive soil moisture sensor. However, these sensors (as they are resistive) do not give reliable readings when measuring at different spots in a field. I believe it is largely influenced by pH, salt content etc.
My next approach was to build a DIY capacitive soil moisture sensor. After searching the web I came across a setup on hackster.io ( https://www.hackster.io/Pedro52/arduino-capacitive-soil-moisture-sensor-diy-with-esp32-d7ad72 ) where a signal is sent via a ESP 32 microcontroller to a probe in the soil and a signal is returned. I implemented the same setup with the same components however I only used optimization of the timers on the Nano to generate the PWM wave (Once again this code was also obtained from another website and I am still a bit confused on how the code works).
I seem to get a reading from the sensor but the zero value seems to very volatile. Even if the wire is only picked up, the output reading changes. Is there a way to get around this and can someone please help me to get my system working optimally.
It would be highly appreciated.

 /

    /The setup uses a Chinese Arduino Nano, a 10M ohm, a 10k ohm, a 1N4007 diode and a 1 microfarrad capacitor as shown in the schematic.
    //The LED moisture indicator in the schematic can be ignored

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

    //LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
    //LcdBarGraphRobojax lbg(&lcd, 16, 0, 0);

    float Moistlevel = 0;
    float Moistpin = A1;
    float Moisture = 0;
    float RESET;
    float factor;
    const byte CLOCKOUT = 9;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  TCCR1A = bit (COM1A0);                  //Code which I obtained to initiate the onboard timer 1 to give a signal through D9
  TCCR1B = bit (WGM12) | bit (CS10);
  OCR1A =  0;                             // Apparently this should be changed for prescaling. Is it necessary?

  RESET = analogRead(Moistpin);           // Take a initial reading to zero the setup

  for (int j = 1; j < 5 ; j++)            // Take another 5 readings of which the average will be determined
  {
    RESET = RESET + analogRead(Moistpin);
    delay(200);
  };

  RESET = RESET / 6;

  Serial.print(RESET);
  Serial.println();

  Serial.print("Moistlevel");
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("Moisture");
  Serial.println();
}

void loop() {

  Moistlevel = analogRead(Moistpin);                  //Take an average reading every second

  for (int i = 1; i < 5 ; i++)
  {
    Moistlevel = Moistlevel + analogRead(Moistpin);
    delay(200);
  };

  Moistlevel = Moistlevel / 6;
  Moisture = (RESET - Moistlevel) / (RESET / 100);    //Conversion to go from a voltage reading to a percentage reading

  if (Moisture < 0)                                   //Moves the initial if a negative moisture is obtained.
  {
    RESET = Moistlevel;
  };

  Moisture = (RESET - Moistlevel) / (RESET / 100);    //Obtains the new moisture value and prints it.

  Serial.println(Moistlevel);
  Serial.print("\t");
  Serial.print("\t");
  Serial.print("\t");
  Serial.print(Moisture);
  Serial.println();
  delay (500);
}


texts:
I am trying to do a project on temperature control and found an example but cannot get the code to work. I have read forums and tried to fix the issue which is below the code.

Code:

#include<DHT.h>      // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define dht11dpin 12
DHT11;
#define pwm 9
#byte degree[8] =
{
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

#void setup()
{
  lcd.begin(16, 2);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print("   Fan Speed  ");
  lcd.setCursor(0, 1);
  lcd.print("  Controlling ");
  delay(2000);
  analogWrite(pwm, 255);
  lcd.clear();
  lcd.print("Circuit Digest ");
  delay(2000);
}

void loop()
  DHT11.read(DHT11pin);
  int temp = DHT11.temperature;
  lcd.setCursor(0, 0);
  lcd.print("Temperature:");
  lcd.print(temp);   // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C");
  lcd.setCursor(0, 1);
  if (temp < 26 )
  {
    analogWrite(9, 0);
    lcd.print("Fan OFF            ");
    delay(100);
  }
  else if (temp == 26)
  {
    analogWrite(pwm, 51);
    lcd.print("Fan Speed: 20%   ");
    delay(100);
  }
  else if (temp == 27)
  {
    analogWrite(pwm, 102);
    lcd.print("Fan Speed: 40%   ");
    delay(100);
  }
  else if (temp == 28)
  {
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%   ");
    delay(100);
  }
  else if (temp == 29)
  {
    analogWrite(pwm, 204);
    lcd.print("Fan Speed: 80%    ");
    delay(100);
  }
  else if (temp > 29)
  {
    analogWrite(pwm, 255);
    lcd.print("Fan Speed: 100%   ");
    delay(100);
  }
  delay(3000);
}

Error:

In file included from C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:2:0:
C:\Users\neilb\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:32:15: error: expected unqualified-id before numeric constant
 #define DHT11 11
               ^
C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:6:1: note: in expansion of macro 'DHT11'
 DHT11;
 ^
C:\Users\neilb\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:32:15: error: expected initializer before numeric constant
 #define DHT11 11
               ^
C:\Users\neilb\Documents\Arduino\sketch_jan20b\sketch_jan20b.ino:35:1: note: in expansion of macro 'DHT11'
 DHT11.read(DHT11pin);
 ^
sketch_jan20b:36: error: request for member 'temperature' in '11', which is of non-class type 'int'
 int temp=DHT11.temperature;
                ^
sketch_jan20b:37: error: 'lcd' does not name a type
   lcd.setCursor(0,0);
   ^
sketch_jan20b:38: error: 'lcd' does not name a type
   lcd.print("Temperature:");
   ^
sketch_jan20b:39: error: 'lcd' does not name a type
   lcd.print(temp);   // Printing temperature on LCD
   ^
sketch_jan20b:40: error: 'lcd' does not name a type
   lcd.write(1);
   ^
sketch_jan20b:41: error: 'lcd' does not name a type
   lcd.print("C");
   ^
sketch_jan20b:42: error: 'lcd' does not name a type
   lcd.setCursor(0,1);
   ^
sketch_jan20b:43: error: expected unqualified-id before 'if'
   if(temp <26 )
   ^
sketch_jan20b:50: error: expected unqualified-id before 'else'
     else if(temp==26)
     ^
sketch_jan20b:57: error: expected unqualified-id before 'else'
      else if(temp==27)
      ^
sketch_jan20b:64: error: expected unqualified-id before 'else'
      else if(temp==28)
      ^
sketch_jan20b:71: error: expected unqualified-id before 'else'
     else if(temp==29)
     ^
sketch_jan20b:77: error: expected unqualified-id before 'else'
      else if(temp>29)
      ^
sketch_jan20b:83: error: expected constructor, destructor, or type conversion before '(' token
   delay(3000);
        ^
sketch_jan20b:84: error: expected declaration before '}' token
 }
 ^
exit status 1
request for member 'temperature' in '11', which is of non-class type


texts: Which Protocol to use to control WiFi (ESP8266) enabled Led Light

texts:
I am developing a Wifi based Led light (Got Inspired from Philips hue, Lifx). I have little knowledge about web server, clients, Web protocols. I will be using ESP8266 as Controller cum WiFi module.

There are two ways to control Led light over WiFi.

Locally
Remotely

Android/iOS app will be handling all the control part.

Which protocols can I use to control Led light, locally? HTTP or Websockets?

  Note :- The speed is critical, android/iOS app can send around 50-60 values per second.

Also, which protocol should I go with if Led light is controlled Remotely.? So far, MQTT seems reliable. Any suggestion?

Kindly help!


texts:
I am looking for cheap way to have very basic wireless communication between an Arduino and a iphone.
I don't need to send complex data, it would be sufficient to "trigger" the arduino: let's say it is reading a certain pin voltage and waiting for it to be up in order to do stuff, my goal is to trigger this pin up by any (wireless and iphone friendly) mean.

I have figured out two solutions: wi-fi shield, cheap RF transceiver. The problem with the latter is that it is not trivial to communicate with a RF transceiver from an iphone. I should add another arduino controlling an RF transceiver on the iphone side and commanding this arduino with an usb.

The wi-fi shield on the other hand is too expensive. Even small routers such as the wr703n (30 euro more or less) is too expensive in my opinion. I just want to send a "bit" of information, so I don't want to spend more than 10 euro.

The third option would be to hack some cheap wi-fi controlled tool, such a lamp or plug: do you know any?
Do you have any other idea?

Thanks!


texts: Communication between Arduino and python: serial port sending empty data

texts:
Arduino code:

this code is provided communication between sensor gy-521 and arduino. I read data by the command "1", after 1000 samples arduino is waited for new command for read data.

Arduino code works well in arduino port.

#include<Wire.h>
const int MPU=0x68;
int16_t AcX,AcY,AcZ;
unsigned long time;
bool allow = false;
//int incom = 0;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(19200);
  while (!Serial);// wait for serial port to connect. Needed for native USB port only
}

void loop(){
  if (allow){ //if allow == true, read data

    for (int i = 0; i < 1000; i++){
      Wire.beginTransmission(MPU);
      Wire.write(0x3B);
      Wire.endTransmission(false);
      Wire.requestFrom(MPU,12,true);
      AcX=Wire.read()<<8|Wire.read();
      AcY=Wire.read()<<8|Wire.read();
      AcZ=Wire.read()<<8|Wire.read();

      time = millis();
      Serial.print(time);Serial.print(",");Serial.print(AcX);Serial.print(",");Serial.print(AcY);Serial.print(",");Serial.println(AcZ);
      delay(0);
    }
    Serial.println(0); //see UPD.3
    allow = false;
  }
}

void serialEvent() {
  while (Serial.available()){ //wait for command
    int incom = Serial.read() - '0';
    Serial.println(incom);
    if (incom == 0){ //if 0 - stop
      allow = false;
      delay(100);
    }
    if (incom == 1){ //if 1 - read data
      allow = true;
      delay(100);
    }
  }
}

Python code:

    def sensors(self):

        self.arduino_port_sensor.reset_input_buffer() #clear buffer

        self.arduino_port_sensor.write(str(1).encode()) #send command to arduino - read data

        main_array = []

        pbar = tqdm(total=self.time_observation) #just to see the progress

        while True:

            values = self.arduino_port_sensor.readline().decode().rstrip().replace(" ", "") #read data, some manipulation for cleaning
            main_array.append(values)

            pbar.update(1)

            if values == '': #if data is empty
                print('!!!!')
                continue
            if values == '0': #see UPD.3
                break

        pbar.close()
        ...bla bla...

I call this function time to time, then in some step, arduino stops sending data -- it sends empty string.

It looks like:

PS. In this code I use 2 ports: for sensor and for motor, 2 different arduino. The principe of working second arduino with motor the same, but it works without any problem (I just send command with "action" to arduino with motor, and then receive answer "received back")

Question: what's wrong with python? how to fix this problem?

UPD

Initialization:

arduino_port_sensor = serial.Serial('/dev/tty.usbmodem143101', 19200, timeout = 1)

UPD.2

It receive command - "1" - read data, the interruption occurs while reading data:

UPD.3

Also i changed the code of arduino -- added the "0" after loop.

UPD.4

If I recall this function after arduno stopped sending data, I get this:


texts: Arduino IDE get stuck while uploading sketch

texts:
I was trying to use my L293D motor driver module. But when I upload the following sketch to try and run my motor, but it would get stuck on "Uploading". This happens with this sketch only, and happens randomly, with odds of happening being 3 in 5 times. After a bit fiddling around I found an error

  Programmer is not responding.

When I try to reset the board or just reconnect it to my PC it might work.
Here's the sketch-

int RightMotorForward = 12;
int RightMotorReverse = 13;

void setup()
{
  pinMode(RightMotorForward, OUTPUT);
  pinMode(RightMotorReverse, OUTPUT);
}

void loop()

{
   digitalWrite(RightMotorForward, HIGH);
   delay(10000);

   digitalWrite(RightMotorForward,LOW);
   delay(1000);
}

Can anybody point out where I am going wrong? I am using Arduino UNO. Is this just some problem in my code?


texts: mega2560- Interrupts reading digital input

texts:
Hi I am very new to Arduino, with very little programming experience.

I am using mega 2560 and trying to understand how interrupt works.

I have a code written, it is very similar as the example code Memsic2125, so i am gonna use that in here.

For my case, I am reading from my hardware, 5x5 array of sensors.

What I would like to do is to have it --   print out x and y using interrupts   , I want to print outputs the x and y every 10ms. Instead of printing it continuously right now.

I will be sending it out in 16 bits. I tried some other example and read a lot of material. but still couldn't get it to work.

Any idea, suggestion, help, comment is appreciated.

const int xPin = 2;
const int yPin = 3;

void setup() {

  Serial.begin(9600);
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
}

void loop() {

  int pulseX, pulseY;

  int x, y;

  // read pulse from x- and y-axes:
  pulseX = pulseIn(xPin, HIGH);
  pulseY = pulseIn(yPin, HIGH);

  x= ((pulseX / 10) - 500) * 8;
  y= ((pulseY / 10) - 500) * 8;

  // print x,y
  Serial.print("x,y= ( ");

  Serial.print(x);   Serial.print(,);
  Serial.print(y);   Serial.println(")");

  delay(100);
}


texts: Can Arduino accept HDMI input video stream, and output it without any modification to the video?

texts: I'd like to know please whether an Arduino can accept an HDMI signal from a satellite receiver, let it flow without any modification to the stream, and output it to TV?


texts: SIM800L - AT Commands not doing anything on Arduino Serial Monitor

texts:
I am trying to send AT commands to SIM800L through Arduino's Serial Monitor. However when I type any command in the serial monitor nothing happens. I'm using an Arduino MEGA 2560 and the TX/RX of the SIM800L is connected to 9 and 10 respectively. Here is the code:

#include <SoftwareSerial.h>

SoftwareSerial GPRS(9, 10);
boolean state, lastState;

void setup()
{
  pinMode(2, INPUT_PULLUP);
  state = digitalRead(2);
  lastState = state;

  GPRS.begin(9600);
  Serial.begin(9600);

  GPRS.println("AT+CMGF=1");

  delay(1000);
}

void loop()
{
  while(GPRS.available()) {
    Serial.write(GPRS.read());
  }

  lastState = state;
  state = digitalRead(2);

  if ( state != lastState ) {
    sendSMS();
  }

  delay(500);
}

void sendSMS() {
  Serial.print("Switch was turned ");
  Serial.println(state ? "on" : "off");

  GPRS.println("AT+CMGS=\"+64XXXXXXXXX\"");

  delay(500);

  GPRS.print("Switch was turned ");
  GPRS.println(state ? "on" : "off");
  GPRS.write( 0x1a ); // ctrl+Z character

  delay(500);
}

Any help would be much appreciated!

EDIT2: I forgot to mention but I am able to send, receive, and call from the GSM Module (with a different code). However I am not able to read the the received messages, since I only get a +CMT "SM",  message and I can't exactly use AT+CMGR or CMGL commands because the serial monitor does nothing with them. here's the code for that:

#include <SoftwareSerial.h>
SoftwareSerial sim(9,10);
int _timeout;
String _buffer;
String number = "+639XXXXXXXXX"; //-> change with your number
void setup() {
  delay(1000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Lets go!");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}
void loop() {
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
}
void SendMessage()
{
  Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Wala kang jowa!";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}
void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}
String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}
void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}


texts:
I need help with my coding. I'm still learning on how to use interval millis().

Currently I'm working on a water heater with a safety feature. This means that you can only pour water out when you activate the child-lock feature. The child-lock feature will turn on for 5 seconds and within that 5 seconds if you pour the water out, the timer will pause until you finish pouring your water and the 5 second timer will start again and the system goes off after that.

If the child lock feature on for 5 second without any action, it will turn off the system again. My lecturer does not allow me to use the delay() function so I already did my coding using millis().

This is my code so far:

const int redLed = 2;
const int greenLed = 3;
const int yellowLed = 4;
const int greenbigLed = 7;

const int buttonPin1 = 5;
const int buttonPin2 = 6;

int buttonState1 = 0;
int buttonState2 = 0;
float tempC ;
int analogPin = A0;
int yellowLedState = 0;

const long interval1 =0;
const long interval2 = 5000;
unsigned long previousMillis = 0;

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

}

void loop() {
  // put your main code here, to run repeatedly:
int analogValue = analogRead(analogPin);
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int yellowLedState = digitalRead(yellowLed);
tempC = analogValue / 10 ;
Serial.println(tempC);
unsigned long currentMillis = millis();
unsigned long currentMillis2 = millis();

if (tempC <= 89.9 && tempC >= 0){
  digitalWrite(redLed,HIGH);
  digitalWrite(greenLed,LOW);
}else if(tempC == 102){
  digitalWrite(redLed,LOW);
  digitalWrite(greenLed,HIGH);
}

if(currentMillis - previousMillis >= interval2){
  previousMillis = currentMillis;
  if(buttonState1 == HIGH){
   // if(currentMillis2 - previousMillis2 >=interval2){
     if (yellowLedState == LOW) {
          yellowLedState = HIGH;
}
digitalWrite(yellowLed, yellowLedState);
  } else{
  digitalWrite(yellowLed,LOW);
    }
}

if (buttonState2 == HIGH && yellowLedState == HIGH){
  digitalWrite(greenbigLed, HIGH);
}else{
  digitalWrite(greenbigLed,LOW);
}

}

Now, I'm able to pour out water when child lock feature activated, but the problem is the timer (interval) still ticking.

Is there any solution on how can I pause the interval whenever I'm pouring water (button2) and the interval starts back 5 sec when I release button2 (pouring water)?

I would glad if someone can help me. Ask me anything about my code.


texts: Floating pins: digitalRead returns always high or always low

texts:
I was trying to see whether my board operates as expected with random readings on floating pins. Oddly it does not. The following code produces all HIGH readings:

#define PIN_MISO 12

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

void loop() {
  uint16_t data = 0;
  Serial.print("MISO digitalRead: ");
  data = digitalRead(PIN_MISO);
  Serial.println(data, BIN);
  delay(300);
}

MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1
MISO digitalRead: 1

I tried grounding pin 12 and after a few seconds the readings all came back LOW as expected. However leaving it floating produces all HIGH instead of random readings.

I tried the same program for pins 3 and then A3 with more weird output: all LOW.

What am I missing here?


texts: How to override automatic control in Blynk app?

texts:
I am a beginner to Blynk, and have successfully built a simple water temperature control project. It consists of ESP32, a plug-in water heater, and an AC relay board. The ESP32 controls the relay board, while the water heater is plugged into the relay board.
The code I have will turn on the relay once the water temperature dips below 16C. On the Blynk app, I want to add a button that allows the user to manually control the operation of the relay. But I am stumped as to how to code it. Since I have programmed the ESP to turn off the relay once the temperature is above 16C, if I try to switch it on manually at 20C, for example, the relay will not remain on, because IF statement will fail.
How can I code this to have a manual override capability? So that once the user turns on the button inside the Blynk app, the ESP will allow manual control of the digital pin (delay trigger), and will only revert back to automatic temperature control mode once the button is turned off?
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 14        //data wire connected to pin 14
#define RELAY_PIN 23           //IoT relay connected to pin 23

OneWire oneWire(ONE_WIRE_BUS); //instance to communicate with any OneWire device

DallasTemperature sensor(&oneWire); //pass reference to Dallas Temperature object

BlynkTimer timer;       //create Blynk timer object for timed intervals
float waterTemp;        //temperature from DS18B20 in C

char auth[] = "xxxxxxx";
char ssid[] = "xxxxxxx";
char pass[] = "xxxxxxx";

void setup() {
  Serial.begin(9600);
  sensor.begin();
  Blynk.begin(auth, ssid, pass);
  sensor.setResolution(9);           //default is 9 bit
  timer.setInterval(1000L, sendTemp);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
}

void sendTemp() {
  sensor.requestTemperatures();      //must request reading first
  waterTemp = sensor.getTempCByIndex(0);
  if (waterTemp != DEVICE_DISCONNECTED_C) {
    Serial.print("Temp = ");
    Serial.println(waterTemp);
    Blynk.virtualWrite(V1, waterTemp);
    if (waterTemp < 16) {
      digitalWrite(RELAY_PIN, HIGH); //turn on IoT relay
    } else {
      digitalWrite(RELAY_PIN, LOW);  //turn off IoT relay
    }
  } else {
    Serial.println("Error: Could not read temperature data");
    Blynk.notify("Error: Could not read temperature data");
    digitalWrite(RELAY_PIN, LOW);
  }
}

void loop(void) {
  Blynk.run();
  timer.run();
}


texts: #Ardunio Send Float values with bluetooth.print in arduino

texts:
I have been creating the example for bluetooth communication with arduino with hc_05  Problem I am facing are below.

String statuss= "1.00,2.00,3.00";
bluetooth.print(statuss);
Serial.print(statuss);

This is the code where is get only last 2 digits i.e 00 in android while its showing me complete string in serial monitor.

String statuss= "Hello";
bluetooth.print(statuss);
Serial.print(statuss);

Then I get the output as ello in Android n in Serial monitor it show Hello

Can Anybody suggest the whats the problem


texts: How I can send data information without work WiFi to LCD?

texts:
Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have the code and work probably when WiFi ON but I have question How I can get the information data from dht to lcd without open the WiFi. Now I get information ( Temp and humidity ) on LCD when WiFi ON only. How I can make Temp and humidity display on LCD with and without WiFi.
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
char auth[] = "*******************************";
char ssid[] = "***********";
char pass[] = "*********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  EspSerial.begin(ESP8266_BAUD);
  Blynk.begin(auth, wifi, ssid, pass);
  dht.begin();
}

void loop()
{
  LCD();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);
}
void LCD()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" ******************");
  lcd.setCursor(3, 1);
  lcd.print("TEMP: ");
  lcd.print(t);
  lcd.setCursor(3, 2);
  lcd.print("HUM : ");
  lcd.print(h);
}


texts: How can I get a unique ID for all my Arduino boards?

texts:
Once you have uploaded a sketch to one of your Arduino boards, it is hard to know exactly what source code led to that sketch.

Indeed, you may change the source code of your sketch on your PC without updating it (in binary format) to your board.

I had the idea of setting up a kind of "sketch repository" that would be populated as soon as I upload a sketch to one of my boards. Then I could retrieve, later on, the source code for a sketch running on any of my boards.

For such a repository, I would first need to have an "index" that would enable me to know which board the sketch source code is linked to.

Typically, such an index should be unique for every single arduino board.

Hence my question: how can I get a unique ID for an Arduino board?

Edit:

This is my current list of boards (the miniumum list to be supported by a single unique ID approach):

UNO R3
Mega 2560
Yun
Arduino Robot (that must be 2 Leonardo equivalent boards)

In the future, I may also build my own boards (Uno equivalent but barebones, without FTDI), hence if an approach also supports these that would be better.


texts: I would like to know the ATMEGA wiring to Arduino

texts:
I would like to know which pins are connected to the output of the Arduino.

For example:

PC6 is digital 12
PB5 is analog 13
etc...


texts: How can I light one led from two different sensors?

texts:
I want to light one led with two sensors, the first one is a PIR and the other one is a Photocell sensor.

The idea is to turn on the led if the PIR sensor detects movement, and also to turn the led on if the room gets darker(detected by the photocell).

I managed to make a code, but with TWO led's, a different one for every sensor.

int ledPin = 13;
int ledPin1=12;
const int ldrPin = A0;
int inputPin = 2;
int pirState = LOW;
int val = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(inputPin, INPUT);
  pinMode(ldrPin, INPUT);
}

void loop() {

  int ldrStatus=analogRead(ldrPin);
   if(ldrStatus<=400)
 {
    digitalWrite(ledPin, HIGH);
    delay(500);
    Serial.println("LED ON");
 }
   else digitalWrite(ledPin, LOW);
    val = digitalRead(inputPin);
      if (val == HIGH) {
        digitalWrite(ledPin1, HIGH);
          if (pirState == LOW) {
            Serial.println("Motion detected!");
            pirState = HIGH;
         }
      } else {
          delay(5000);
          digitalWrite(ledPin1, LOW);
            if (pirState == HIGH){
             Serial.println("Motion ended!");
             pirState = LOW;
           }
     }
  }


texts:
Which I2C command happen during Wire.requestFrom(address, quantity)?

Is it correct that Wire put a Start condition, then 7-bit address appended with read bit? How would that be different from Wire.write(address)?


texts: Controlling an LED using SIM900A and Arduino

texts:
How can I turn the LED on and off using a received text message?

The sim card is able to receive the message but I can't change the pin status. I also can't see anything in the serial monitor upon reception of the message.

Below is my code.

#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3);
String msg;
const int LED = 13;

void setup() {
  gsm.begin(9600);
  Serial.begin(9600);
  Serial.println("PUMP CONTROL");
  Serial.println("t : to receive text");
  delay(1000);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
}

void loop() {
  if (Serial.available()>0)
  switch(Serial.read())
  {
    case 't':
    showSMS();
    break;
  }
  if (gsm.available()>0)
  Serial.write(gsm.read());

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    delay(1000);
  }
  if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 if (gsm.available()>0)
 {
  msg=gsm.read();
  Serial.print(msg);
 }
}


texts: Why the GSM Shield is discontinued? What options are available?

texts:
I need to build a device with a single button to make a call over a mobile network (GSM)

I wanted to buy an arduino one and an arduino gsm shield for this, but just noticed that the GSM Shield is retired - discontinued.

I checked all the arduino products but there is no options for integration with GSM.

What options do I've to build my products if the GSM Shields is discontinued?


texts: Why is Arduino I2C so sensitive to RFI/EMI?

texts:
I have a 2-motor robot project that uses a MP6050 for relative heading (yaw) measurements, and I'm having problems with the I2C bus when the motors are running.  I have done most of the things suggested here and elsewhere; 2.2K pullups vs default, shortest possible (3cm) I2C wires, MPU6050 as far away from the motor drivers as possible, reduced I2C clock speed to 100KHz, etc, etc (for additional details, see my blog post on the subject).

So, my question is, why is the I2C bus so sensitive to RFI/EMI, especially with 2.2K pullups to +5V?  Looking at the levels with my O'scope shows a 0-4.6V swing, so it's hard to believe that EMI-induced currents could be high enough across 2.2K to pull the 'high' level low enough to be considered a '0', so something else must be going on.  Maybe the EMI is getting into the MPU6050 output driver circuit, causing it to turn off?  If so, maybe capacitive bypasses on the I2C lines would help.  Any ideas?  Are other IMU modules less susceptible to motor driver EMI?

TIA,

Frank


texts: A recommendation for a fast-response-time-resolution-mp3-module for arduino

texts:
I am working with Arduino which activates a box which is similar to a Skinner Box. Some of the output sound stimuli are sine waves with duration of less then 5 milliseconds. I output the sounds using the MP3 module DFR0299.

However there are too much problems using this module: it seems like the module has a wakening delay of around 100 ms, so it is not working well with this duration and below (the response time of the module is important).

So, I was thinking of buying a better module. However, I am far from being an expert in these things..

I can look for other modules in the internet, but, just from looking at the datasheets, I cant tell if the quality of the module is what I need.

I would be grateful if any of you could give me names of modules that might feet my requirements (or even advice me at what to look in the datasheets)

Thanks!


texts: ATtiny85 AC Phase Control for dimming a light bulb

texts:
I'm trying to dim a light bulb via an ATtiny85, which accepts commands sent over I2C. My problem is that the bulb is barely dimming and is flickering quite a bit.

My circuit can be seen here:

The opto-isolator (and thus the triac) is controlled via pin 2 (AKA PB3, AKA PCINT3) and AC zero cross detection is done on pin 3 (AKA PB4, AKA PCINT4) on the ATtiny85.

The code uses Pin Change Interrupt Enable rather than the single External Interrupt Enable, because the External Interrupt pin is pin 7 (aka PB2), which is used as the SCL for the I2C communication.

The 8MHz internal clock is used and the timer/counter prescaler is 1024, which means that I have an effective input range (see level variable in the code) of roughly 0-65. My AC source is USA (60Hz).

#include <avr/interrupt.h>
#include <avr/io.h>
#include <TinyWireS.h>

#define PULSE 4       //trigger pulse width (counts)
#define I2C_SLAVE_ADDR 0x4 // the 7-bit address (remember to change this when adapting this example)

byte trigger = 3;
byte detector = 4;
byte level = 50;
byte maxLevel = 65;
byte minLevel = 0;

void setup() {
    TinyWireS.begin(I2C_SLAVE_ADDR); // join i2c network
    TinyWireS.onRequest(requestEvent); //setup i2c requester
    digitalWrite(detector, HIGH);  //enable pull-up resistor
    pinMode(trigger, OUTPUT);// Set AC Load pin as output
    TCCR1 = 0;     //stop timer
    OCR1A = level;    //initialize the comparator
    TIMSK = _BV(OCIE1A) | _BV(TOIE1); //interrupt on Compare Match A and  enable timer overflow interrupt
    GIMSK = 0b00100000; //Enable pin change interrupt
    PCMSK = 0b00010000; //PB4, physical pin 3 PCINT4
    TCCR1 = B00001011; //Prescale the timer
    sei();  // Turn on interrupts
}

ISR(PCINT0_vect) {
    //interrupt looking for zero crossing
    TCNT1 = 0;   //reset timer - count from zero
    OCR1A = level;
    TCCR1 = B00001011;// prescaler on 1024, see table 12-5 of the tiny85 datasheet
}
ISR(TIMER1_COMPA_vect) {
    //comparator match
    digitalWrite(trigger,HIGH); //set triac gate to high
    TCNT1 = 255-PULSE;
    //trigger pulse width for a few cycles for triac to latch on. 255 bc the counter can only count up to 255
}

ISR(TIMER1_OVF_vect) {
    //timer1 overflow
    digitalWrite(trigger, LOW); //turn off triac gate
    TCCR1 = 0;  //disable timer stop unintended triggers
}

void loop() {}

void requestEvent() {
    if (TinyWireS.available()) {
        level = TinyWireS.receive();
        if (level > maxLevel) {
            level = maxLevel;
         else if (level < minLevel){
            level = minLevel;
        }
    }
    TinyWireS.send(OCR1A);
}

I have tried a variety of bulbs (incandescent and dimmable LED), with none working any better than another.

Here is a video showing the zero cross detection (yellow) and the ATtiny85 trigger (blue) on an oscilloscope as I send it different dimming levels Bad phone video

I've thought about the snubber, I just don't have the parts on hand right now. I think it will help but I don't think it will correct whatever my larger issue is.

I'd appreciate all and any help. Thanks.

(Note: I also posted this here. Apologies if crossposting is frowned upon).


texts: ESP8266-01 Wifi module + Wifi shield not present + ESP8266-01 libraries not working?

texts:
I have Arduino IDE v. 1.8.13.
I bought an ESP8266-01 module which I want to use in my Arduino-UNO board to send fingerprint registration confirmation (ID) via HttpClient to a xampp server since I dont want to store the fingerprint image in the database.
My ESP connection is as below:

In the serial monitor, my AT commands work well when I connect the module to my wifi using AT+CWJAP="ssid","password".
When I upload my code, which is supposed to connect to wifi, it says WiFi shield not present.
Im new to this, is there anything I am missing?
Thanks in advance.
Here is my code:
#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;

char serverAddress[] = "localhost/bel/arduino/scannerstatus/php";  // server address
int port = 80;

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;

void setup() {
  Serial.begin(9600);
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
  }

Basically, my uploaded code does not go past the wifi connection stage. Even though the AT commands individually can connect to wifi.
I have tried different ESP8266 libraries and HttpClient libraries but they all seem to not connect to wifi.
Is there any other way to call a php script from arduino without using wifi?


texts: Arduino Due: JTAG and SWD do not work after pressing erase button

texts:
I have an Arduino Due board. I can successfully upload code to it using Arduino upload via USB.
However I am also exploring another approach, which is to upload code via Atmel studio using an Atmel ICE and JTAG connection. Usually this works fine (the code uploads, and a simple "blink" sketch makes the onboard LED flash).
However when I press the erase button, and then try to upload the same sketch via Atmel Studio and JTAG, something strange happens. The code uploads fine:
Erasing device... OK
Programming Flash...OK
Verifying Flash...OK

But then the program on the Due does not actually execute. The LED does not start to 'blink'. If I then again upload via USB (programming port) and the Arduino IDE, the blink program does work. And when I then upload via Atmel Studio and JTAG again without pressing the erase button, everything happens as expected too (LED blinks etc).
Does anyone have any idea what might be going on? The reason I ask is because I would like to design a board using only a JTAG connection. Do you think the above problem could cause issues when using a 'blank' factory SAM MCU as well?
EDIT: the same problem applies to SWD.
Blink sketch that i am uploading:
#define led LED_BUILTIN

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(600);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(600);               // wait for a second
}


texts:
I use this small program on my Raspberry Pi to recieve a string sent by my arduino.

import time
import serial

ser = serial.Serial('/dev/ttyACM0', 9600)

def check_for_command():
    bytestoread = ser.inWaiting()
    if bytestoread != 0:
        temp = ser.read(bytestoread)
        print(temp)

while 1:
    check_for_command()
    time.sleep(0.1)

the code on the arduino is rather simple:

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

void loop(){
Serial.println(“Hello Pi”);
delay(2000);

the annoying part is. I recieve this:

  b'Hello Pi\r\n'

instead of the clean

  Hello Pi

How do I get rid of those extra bits without using a list for each character.

Thank in advance!


texts: Make one button print different sentences on LCD

texts: I am very new to arduino and I've been scratching my brain on how to make one button print out three different sentences. When I press it the first time, a " I am " is suppose to appear, when I press it the second time " very" and then the third time " late". I can't have three different buttons because a tone follows this button as well.


texts:
I'm using Arduino to control a stepper motor. I need it to make one revolution and then stop. I'm new to this and haven't ran it yet. Will this do for me?

#include <Stepper.h>

const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  myStepper.setSpeed(60);
}

void loop() {
  myStepper.step(stepsPerRevolution);
}


texts: Controlling a servo motor with two arduinos?

texts:
I have two Arduinos, two buttons and one servo motor.

I want to control a servo motor with two Arduino's when I pressed the buttons. I linked Arduino PWM pins (first Arduino PWM pin is 9, and second one is 3) to the servo motor signal input.

When I pressed button 1 servo motor moving a few, or pressed button 2. but the signal isn't clear, and servo motor doesn't move correctly that I assigned degree.

What can I do for the solution?

My first Arduino code is here:

#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(3);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  {
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}

and second arduino code is:

#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(9);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  {
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}


texts: What is the opposite of this data operation?

texts:
If I store in an array a double-value in this format, in which format I should be able to read the same double out?

double myDouble = 12.123456;
byte myArray[] = {0x00, 0x00, 0x00, 0x00};

myArray[0] = (myDouble >> 0);
myArray[1] = (myDouble >> 8);
myArray[2] = (myDouble >> 16);
myArray[3] = (myDouble >> 24);


texts: Why does an RGB LED between VCC and PWM work?

texts:
I'm an Arduino beginner and I recently bought a cheap starter kit on eBay. One of the lessons in the starter kit is an RGB LED controlled by 3 PWM output pins. However, the arrangement of the connections seems a bit funny to me:

To my surprise, it worked. I could see the three LEDs inside the plastic change colors. Why does this work? Do the PWM pins accept current whilst low? Is this a common arrangement? See the above link for the code provided in the lesson.


texts: Arduino Uno to drive 2 unipolar stepper motors

texts:
I need to use two stepper motors to move microscope positioning knobs in the X/Y direction. The stepper motors I have are unipolar and are 6V rated (I think).

I know it's possible to drive a unipolar stepper motor via a ULN2003 using an Arduino Uno. I know I can wire it using the 2-wire or 4-wire method.

But my questions are:

Is it possible to drive 2 of them? What are the modifications I will need to make to the circuit? Will this harm my Arduino? Do I need a stepper motor shield?


texts: Is this class declaration wrong? " Declaration has no storage class or type specifier" error

texts:
While trying to setup  an ESP32 as mqtt publisher I am getting strange errors. Here is my code:
#include "mqttSetup.h"
#include <WiFi.h>
#include <PubSubClient.h>

static byte httpFailCounter = 0;
byte counter = 0;

const char *ssid = "SSID";
// const char *password = "xxxxx";
const char *passphrase = "xxxxx";

WiFiClient espClient;

const char *mqtt_server = "192.168.1.39";
const int mqttPort = 1883;
const char *mqttUser = "xxxx";
const char *mqttPassword = "xxxxx";

PubSubClient pubClient(espClient);

pubClient.setServer(mqtt_server, mqttPort);

void checkConnection()
{
    if (WiFi.status() == WL_CONNECTED)
    {
        counter = 0; //reset counter
    }
    else if (WiFi.status() != WL_CONNECTED)
    {
        WiFi.begin(ssid, passphrase);
    }
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");

        counter++;
        if (counter >= 60)
        {
            ESP.restart();
        }
    }
}

void reconnect()
{

    while (!pubClient.connected())
    {
        Serial.print("Attempting MQTT connection...");
        // Create a random client ID
        const char *clientID = "ESP32D-MQTT";
        // Attempt to connect
        if (pubClient.connect(clientID))
        {
            Serial.println("connected");
            // Once connected, publish an announcement...
            pubClient.publish("outTopic", "Hello from ESP");
            // ... and resubscribe
            //   client.subscribe("inTopic");
        }
        else
        {
            Serial.print("failed, rc=");
            Serial.print(pubClient.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}

I don't understand why the compiler is spitting out the following two errors:
this declaration has no storage class or type specifier (referring to my pubClient declaration)

expected a ';'

It doesn't have any issue when I declare the pubClient but at the line :
pubClient.setServer(mqtt_server, mqttPort);
where I use the pubClient it gives the error.
Besides I don't see any ; missing in the code.
Could you please help me figure out the source of error?

Header file for this code chunk
#ifndef MQTTSETUP_H
#define MQTTSETUP_H

void checkConnection();
void reconnect();

#endif

------------ Main sketch---------
#include <Arduino.h>
#include "Wire.h"
#include "tempSensor.h"
#include "mqttSetup.h"

void setup()
{
  Wire.begin();

  Serial.begin(115200);
  while (!Serial)
    ;

  shtBegin();
  checkConnection();
}

void loop()
{
  uint32_t newTime = millis();
  static uint32_t oldTime = 0;
  static uint32_t t2 = 0;

  float temp = 0.0;
  float humid = 0.0;

  char senVals[50];

  if (newTime - oldTime >= 10000)
  {
    oldTime = newTime;

    readsht(temp, humid);
    snprintf(senVals, 50, "Temp: %.2f Humid: %.2f", temp, humid);
    Serial.println(senVals);

  }
}


texts:
I am trying to spare a few bytes of program size.
I faced a problem which I cannot understand and I hope somebody will help.
Look at this empty sketch, pleas. It takes just 444 bytes:
void setup()
{
}

void loop()
{
}

However, this one – 1332 bytes already!
void f() {
    Serial.println(1);
}

void setup()
{
}

void loop()
{
}

Why?
It is supposed that function f() will be cut-off during the linkage stage. But it is not.
And what can I do to cut such things off, since they are not used in the code?


texts:
I am extremely new to arduino and have searched for this on net but have not found it.
My project has 2 files, a ".ino" file with the sketch and another ".h" file with the secrets and configuration parameters, such as reading intervals, credentials to connect to Wi-Fi, etc.
Now I need in runtime to be able to connect to the arduino, either by serial or by any other way to be able to set these parameters.
Edit:
My question is: How can I change the parameters after compiling the sketch ?, for example, how can I specify the credentials for the arduino to connect to the client's wifi, since each client has different credentials.


texts: Using millis() to time the start / stop of a DC motor

texts:
I'm trying to use a DC motor with pinion engaged to a rack gear, and have that motor move a distance, save the distance, delay, reverse, and travel back the same distance from where it started, delay, do it again. I want to start/stop the initial save with a button push, then from those saves, loop the motor movement.

I have considered using a Hall effect sensor or reed switch to count, but it seems a software interrupt or timing is easier using millis(). I researched and found that millis() cannot be reset, so I'm wondering if this is possible.

I haven't started a sketch, but I got this idea from the BlinkWithoutDelay example sketch included with the Arduino IDE. Like, have the motor positioned at "home" position, button push, start the timer, motor travels to end of work piece, stop the timer, save that forward distance traveled into a variable, reverse the motor, (at this point the timer would be at 0 again for the reverse travel) travel back to "home" save that reversed distance traveled into another variable with a button push, and then use these start/stop values in a loop. So I would save the values with a button pushes, then just loop that.

Or I'm thinking about putting an if or while button push outside the loop with a nested counter++, eyeballing the motor travel, once it gets to where I want it, save those counts in variables, then using them in the loop to analogWrite() to the motor.


texts: How to switch an external circuit with Arduino?

texts:
I have an object with a series of led and I want to turn on and off these leds from my Arduino. The input of the LED circuit is 24v DC 100mA.

What I've done is the following:

I've cut a wire of this object and I connected one end to the collector and the other end to the emitter of a NPN transistor
I connected the base of the transistor to a digital output (through a 1k resistance)
I connected the power to the led series while the digital pin was LOW (actually completely disconnected)

But with no current on the base of the transistor, the LED has turned on to my surprise. I may have completely misused the transistor and other items. How do I fix this circuit?


texts: How to prevent the Serial Monitor from closing upon re-uploading sketch?

texts:
I'll be teaching a year 10 class on the Intel Galileo gen2 and there'll be a wide (but high-level) programming curriculum, which includes introduction to console printing, using Serial.

I'd like the students to be able to write their printing code in setup() so that it's only printed once and easily readable by them. However, it's impossible to be fast enough to upload a sketch and open the Serial Monitor (which flat out refuses to open before the sketch has started), and the Serial Monitor closes itself upon re-uploading code.

Without unnecessary (and potentially for the students, confusing) use of the delay function in setup(), it's impossible to read any output originating from setup(); only things printed in loop() (which are constantly re-printed) are ever discoverable.

So; is there a way to somehow keep the Serial Monitor open, or make it capture output from before it's opened, or delay the entire running of the sketch (rather than chucking in delays)?

We'll be using the standard Arduino IDE.

EDIT

This script was run in one of two conditions...

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

  // ensure Serial is ready
  delay(1000);

  for (int i=0; i < 10000; i++) {
    Serial.println(i);
  }
}

void loop() {
}

When the Serial Monitor was opened immediately after upload, all numbers from and including 0 to 9999 were recorded in the monitor.

When the Serial Monitor was opened around 5s after upload, only numbers upward of 2243 were observed. This suggests the sketch WAS being re-run (else no numbers would have been captured; the sketch runs in significantly less time than 5s) but that all numbers between 0 and 2243 were not captured by the monitor; as if opening the Serial Monitor late enough to cause a re-run causes some monitor overhead.
This strange loss of numbers is NOT time dependent: increasing the initial delay from 1s to 4s (and waiting longer after upload before opening the Serial) did not at all vary the soonest number recorded, suggesting it is some 'line' based overhead
(but of course, how could anything fail for 2243 lines?!)

With that mystery aside, this negates the automatic re-running of the sketch upon Serial Monitor opening from being actually useful.


texts:
I want to transmit data to my laptop from arduino with nrf905. I found examples with communicating two nrf905 devices but not an arduino and a PC. By the way, the tutorial is here; http://www.electrodragon.com/w/index.php?title=NRF905_Transceiver_433MHz-Wireless_Module
I can also accept any tutorial link as an answer.


texts: How to merge two GPS coordinates without losing decimals

texts:
I want to take the GPS coordinates like 42.1234 per 22.1234 and merge them as a string, with a separator character:

42.1234 x 22.1234

But using this code:

gps_string = (String)gps.location.lat()+' x '+(String)gps.location.lng();

I lose the last decimals and I get:

42.12 x 22.12

The only way I could see full coordinates is by specifying an extra parameter to println, like this:

Serial.println(gps.location.lat(), 6);

How can I create a string containing both two coordinates without losing decimals ? e.g 42.1234 x 22.1234


texts: Firmware gets stuck at obj.printto(client) in esp32

texts:
I am using an ESP32 to capture some data and then sending it over using ArduinoJson. However, sometimes, the firmware gets stuck at the line where it is transmitting data at obj.printTo(client). I have the logs for the same. Do you have any idea as to what might be making it freeze? And any way to avoid it in the future.

Logs:

12:28:00.584 -> [V][ssl_client.cpp:276] send_ssl_data(): Writing HTTP request...

12:28:00.584 -> [V][ssl_client.cpp:276] send_ssl_data(): Writing HTTP request...
12:47:11.229 -> [E][ssl_client.cpp:33] handle_error(): UNKNOWN ERROR CODE (004E)  12:47:11.229 -> [E][ssl_client.cpp:35] handle_error(): MbedTLS message code:-78

12:47:11.229 -> [V][ssl_client.cpp:245] stop_ssl_socket(): Cleaning SSL connection.
12:47:11.229 -> request sent
12:47:12.217 -> esp32/Arduino CI has failed
12:47:12.217 -> reply was:
12:47:12.217-> ==========
12:47:12.217 ->
12:47:12.217 -> ==========
12:47:12.217 -> closing connection

The send code:

jsonBuffer.clear();
JsonObject &rootObject = jsonBuffer.createObject();
JsonObject &dataObject = rootObject.createNestedObject("data");
JsonArray &X1dataObject = dataObject.createNestedArray("X1");
JsonArray &Y1dataObject = dataObject.createNestedArray("Y1");
JsonArray &Z1dataObject = dataObject.createNestedArray("Z1");
JsonArray &T1dataObject = dataObject.createNestedArray("T1");

vTaskDelay(10);

if (send_flag) {
  digitalWrite(2,0);
  send_flag = false;
  int connection_iterator = 0;
  int connection_iterator2 = 0;
  for (int iterator = 0; iterator < SAMPLE_SIZE; iterator++) {
    X1dataObject.add(X1dataArray[iterator]);
    Y1dataObject.add(Y1dataArray[iterator]);
    Z1dataObject.add(Z1dataArray[iterator]);
  }
  T1dataObject.add((float)(analogRead(NTC)*0.0244));

  rootObject["coreid"] = String(low, HEX) + String(high, HEX);
  //rootObject["coreid_high"] = String(high, HEX);
  rootObject["sample_time"] = int(time_taken);
  rootObject["firmware_version"] = FIRMWARE_UPDATE_VERSION;
  rootObject.prettyPrintTo(Serial);
  Serial.print("connecting to ");
  Serial.println(host);
  while ((!client.connect(host, httpsPort)) && !setup_mode) {
    connection_iterator++;
    Serial.println("connection failed! Retrying..");
    delay(5000);
    if (connection_iterator >= 10)
      ESP.restart();
  }
  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.print("requesting URL: ");
  Serial.println(url);
  client.println(String("POST ") + url + " HTTP/1.0");
  client.println(String("Host: ") + host);
  client.println("Cache-Control: no-cache");
  client.println("Content-Type: application/json");
  client.print("Content-Length: ");
  client.println(rootObject.measureLength());
  client.println();
  rootObject.printTo(client);
  Serial.println("NUMBER OF INTERRUPTS:");
  Serial.println(interruptCounter);
  Serial.println("request sent");
  while ((client.connected()) && !setup_mode) {
    connection_iterator2++;

    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
    Serial.println("Waiting for response");
    delay(500);
    if (connection_iterator2 >= 40)
      break;
  }
  String line = client.readStringUntil('\n');
  if (line.startsWith("{")) {
    Serial.println("esp32/Arduino CI successfull!");
  } else {
    Serial.println("esp32/Arduino CI has failed");
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
  digitalWrite(LED_BUILTIN, LOW);
  // readRegister(INT_SOURCE, 1, &dummy_read);
}


texts:
I was following a tutorial for my class (the tutorial was assigned) and I did everything the guy did to the letter but i got errors he didn't and they were errors I didn't get while programing similar things with the exact same commands as what im getting errors on now.
Code
#include "DHT.h"
#define Type DHT11
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int sensePin=2;
DHT HT(sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int dt=1000;

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   HT.begin();
   delay(setTime);
   lcd.begin(16,2);
}

void loop() {
   humidity=HT.readHumidity();
   tempC=HT.readTemperature();
   tempF=HT.readTemperature(true);

   lcd.setCursor(0,0);
   lcd.print("Temp F= ");
   lcd.print(tempF);
   lcd.setCursor(0,1);
   lcd.print("Humidity= ");
   lcd.print(humidity);
   lcd.print(" %");
   delay(500);
   lcd.clear();

   Serial.print("Humidity: ");
   Serial.print(humidity);
   Serial.print("% Temperature ");
   Serial.print(tempC);
   Serial.print(" C ");
   Serial.print(tempF);
   Serial.print(" F ");
}

Error message
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

DHT_LCD_lab:10:2: error: expected ',' or ';' before 'LiquidCrystal'
  LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
  ^~~~~~~~~~~~~
C:\Users\zacha\Desktop\DHT_LCD_lab\DHT_LCD_lab.ino: In function 'void setup()':
DHT_LCD_lab:24:1: error: 'lcd' was not declared in this scope
 lcd.begin(16,2);
 ^~~
C:\Users\zacha\Desktop\DHT_LCD_lab\DHT_LCD_lab.ino: In function 'void loop()':
DHT_LCD_lab:34:1: error: 'lcd' was not declared in this scope
 lcd.setCursor(0,0);
 ^~~
exit status 1
expected ',' or ';' before 'LiquidCrystal'

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


texts:
Do Arduinos meet military standards?

If not, where does it fall short? Is it something internal to the chip which might be corrected via external circuit? How could I evaluate the potential of a device I'm building?


texts:
So I have been messing around with the Arduino Capsense library with the immensely helpful guide; http://www.instructables.com/id/How-To-Use-Touch-Sensors-With-Arduino/  (many thanks to DangerousTim!)   using the code provided, i managed to get a relay to operate with a sensor.  It worked great and I was able to adjust the distance and sensitivity.  But when i tried adding another sensor and relay, it stopped working.  I've been trying to isolate the problem for a while now and have gotten nowhere.  I'm hoping someone can help me, here's the original code for the single sensor and relay;

#include <CapacitiveSensor.h>
#include <CapacitiveSensor.h> //change '42' to any desired pin...

long time = 0;
int state = HIGH;
boolean yes;
boolean previous = false;
int debounce = 200;
CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);
// To add more sensors...
//CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor       between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
//CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor  between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()
{
    cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
    pinMode(13, OUTPUT);
}

void loop()
{
    long total1 =  cs_4_2.capacitiveSensor(30);

    if (total1 > 60){yes = true;}
    else {yes = false;}

    // to toggle the state of state
    if(yes == true && previous  == false && millis() - time>debounce){
        if(state == LOW){
            state = HIGH; }
        else state = LOW;
        time = millis();
    }

    digitalWrite(13, state);
    previous = yes;
    delay(10);
}

and here's the code for the two sensors and relays

#include <CapacitiveSensor.h>

int led = 13;
int led2 = 12;
long time = 0;
int state = HIGH;
long time2 = 0;
int state2 = HIGH;
boolean yes;
boolean previous = false;
boolean yes2;
boolean previous2 = false;
int debounce = 200;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor  between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_5_7 = CapacitiveSensor(4,6);

void setup()
{
    cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
    cs_5_7.set_CS_AutocaL_Millis(0xFFFFFFFF);  //Calibrate the sensor...
    pinMode(led, OUTPUT);
    pinMode(led2, OUTPUT);
}

void loop()
{
    int total1 =  cs_4_2.capacitiveSensor(30);
    Serial.println(total1);
    int total2 =  cs_5_7.capacitiveSensor(30);

    if (total1 > 60){yes = true;}
    else {yes = false;}
    if (total2 > 60){yes2 = true;}
    else {yes2 = false;}

    // to toggle the state of state
    if(yes == true && previous  == false && millis() - time>debounce){
        if(state == LOW){
            state = HIGH;
        }
        else
            state = LOW;
        time = millis();
    }

    if(yes2 == true && previous2  == false && millis() - time2>debounce){
        if(state2 == LOW){
            state2 = HIGH;
        }
        else
            state2 = LOW;
        time2 = millis();
    }

    digitalWrite(led, state);
    previous = yes;
    digitalWrite(led2, state2);
    previous2 = yes2;
    delay(10);
}


texts:
I bought an Arduino 9 Axes Motion Shield without looking at the pinout. I'm worried it won't work with my Adafruit Motor Shield v1.

It seems the 9 axes shield uses I2C, a reset pin and several other pins for the TinkerKit Input, Output and TWI connectors. Does anyone have a list of specific ports used by the shield on the Arduino UNO?

It also seems that my Arduino UNO r1 only has the original analog pins for I2C, while the 9 axes shield uses the new pins next to the digital pins.

update: I asked support from arduino.org on twitter and on their forums, no reply yet and it seems their twitter account has been suspended. Should have bought a Genuino I guess.


texts: I can make a usb to ttl rs232 arrangement with max490 to be able to do full duplex communication between the PC and two arduino?


texts: I am currently working on a project that would greatly benefit from an arduino uno board with male headers soldered on instead of the female connectors. My question is hence extremely simple, yet I was not able to find an answer myself. Are there uno formfactor boards out there, with male header pins. I have found versions without headers for other boards, but not for the uno. Since I have already designed and 3d printed an enclosure that fits the uno and want to lower the overall height this seems like the easiest way to achieve this.


texts:
I'm new to Arduino.

I'm passing some data from my Android phone to my Macbook via bluetooth (throught the app Sensoduino).

What I'd like to do now is to export that data to my Arduino Mini Pro.

Is there any way to achieve it?

(NOTE: I'm not able to connect my Android Phone directly to the Arduino via Sensoduino)


texts: SPIFFS and LittleFS don't show all my files with readdir() and can't open() them

texts:
I created a simple sketch that just tries to list the files in SPIFFS. The SPIFFS filesystem was created with the version of mkspiffs that's part of the esp8266 package. The upload all seems to work, but it only lists the first file and not the rest.
After running the sketch I downloaded the flash memory and it compared OK so nothing is being corrupted...
$ esptool.py --port=/dev/ttyUSB0 read_flash  0x200000 0x10000 foo
$ cmp html.img foo
$

If I try the same with LittleFS then I get no files reported!
I also tried upgrading to the 3.0.0 libraries (and thus also the later version of mkspiffs that came with the library)
Clearly I'm doing something stupid and wrong!
Hopefully the following (showing how I build it, upload it) will help point out my mistake!
Thanks for any assistance...
================================================================
Creating Image file
This is done using the mkspiffs that comes with the package so it should(!) match the library used by the ESP8266
$ ~/.arduino15/packages/esp8266/tools/mkspiffs/2.5.0-4-b40a506/mkspiffs -c html html.img
/menu_frame.html
/change_ap.html
/top_frame.html
/index.html
/main_frame.html

Compiling with 4M2M memory layout
$ arduino-cli compile --fqbn=esp8266:esp8266:nodemcuv2:eesz=4M2M
Executable segment sizes:
IROM   : 265840          - code in flash         (default or ICACHE_FLASH_ATTR)
IRAM   : 26888   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...)
DATA   : 1248  )         - initialized variables (global, static) in RAM/HEAP
RODATA : 800   ) / 81920 - constants             (global, static) in RAM/HEAP
BSS    : 25120 )         - zeroed variables      (global, static) in RAM/HEAP
Sketch uses 294776 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27168 bytes (33%) of dynamic memory, leaving 54752 bytes for local variables. Maximum is 81920 bytes.

Uploading, writing the bin at 0x0 and the filesystem at 0x200000
$ python ~/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool/esptool.py --port=/dev/ttyUSB0 write_flash 0x0 SPIFFS.esp8266.esp8266.nodemcuv2.bin 0x200000 html.img
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: b4:e6:2d:67:b1:45
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 298928 bytes to 219676...
Writing at 0x00034000... (100 %)
Wrote 298928 bytes (219676 compressed) at 0x00000000 in 19.5 seconds (effective 122.7 kbit/s)...
Hash of data verified.
Compressed 65536 bytes to 1353...
Writing at 0x00200000... (100 %)
Wrote 65536 bytes (1353 compressed) at 0x00200000 in 0.1 seconds (effective 4232.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Results:
... It shows 2M for the filesystem.
... But only one file is listed?
... If I use LittleFS instead then no files are listed!
Starting...
Total size of FS is: 1953282
Used size of FS is: 2259
File list:
/menu_frame.html
Finished

And, finally, the sketch
#include <FS.h>

void setup()
{
  Serial.begin(115200);
  delay(500);

  Serial.println("Starting...");

  SPIFFS.begin();

  FSInfo fs_info;
  SPIFFS.info(fs_info);

  Serial.print("Total size of FS is: ");
  Serial.println(fs_info.totalBytes);

  Serial.print("Used size of FS is: ");
  Serial.println(fs_info.usedBytes);

  Serial.println("File list: ");
  Dir dir = SPIFFS.openDir("/");
  while (dir.next())
  {
    Serial.println(dir.fileName());
  }
  Serial.println("Finished");
}

void loop() { }


texts:
My mega usb/serial adapter died some time ago, so I bought an external FTDI programer wich I got working on 1.0.1 IDE. I can load any program to the mega, even complex led matrix driver I wrote myself so the ATmega works fine and the external FTDI board does too. Strangely enough I if I want to update the IDE (tried once on 1.0.5 and yesterday downloaded 1.6.5) I get an

 avrdude: stk500v2_getsync(): timeout communicating with programmer

When this problem occurs, I see that the programmer board recieves something (it has Rx and Tx LED's) the Mega resets but never sends any data back, which does happen on 1.0.1 IDE.
This happens on my pc, and on a laptop son no pc related problems.
I'd keep using this version but now I got an OLED display I want to drive (SSD1306 from waveshare) but I can't compile u8glib on 1.0.1 but I can on 1.6.5, however I can't get a simple blink example to upload with this IDE.

I suspect the DTR pin (reset pin) is handled differently and that makes the mega stay resetting until it times out.
What can be the problem here? How can I get more info from the console to solve this?


texts: if(Serial) not working correctly on micro or pro micro

texts:
I have an arduino micro and several clone "pro micro"'s both of which are based on the 32u4, i'm trying to make my project have a debug mode which is only active when the serial port is open, the documentation states that using:

if (Serial)

on these boards should only return true if the port is open (on uart based connections it always returns true), i wrote my sketch to take advantage of that but it didn't seem to be working properly, so i stripped back to basics and wrote this sketch:

void setup() {
    // put your setup code here, to run once:
    pinMode(2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial){
        digitalWrite(2, HIGH);
    }
    else{
        digitalWrite(2, LOW);
    }
}

I connected an LED to pin 2 and then tested it by connecting and disconnecting the arduino from the PC, and opening and closing the com port.

after freshly connecting the arduino to the PC the LED is off, when i open a connection to the virtual com port the LED turns on.
however i would expect the LED to go out once the port is closed, but it remains on.

My questions are:
1) have i got an out of date bootloader?
2) if so how do i check?
3) is this intended behavior and if so why?
4) is this a bug in the arduino bootloader or libraries?
5) short of having to change my code to look for serial data to start and stop the debug mode (serial comms are being used for other things in the background) is there any way i can work around this? reading from hidden registers etc?

Edit:
should have mentioned i'm seeing this behavior with or without a call to Serial.begin


texts:
So I've been looking into branchless programming to speed up code and I'm curious as to how exactly Arduino (or rather atmega328) actually reads machine instructions. Does it have a memory cache or does it read every instruction from the flash memory?
From my understanding of branchless programming it speeds up the computation because the CPU does not have to jump inside the instructions and can read it sequentially, hence does not need to load in new instructions in case it has to jump to a location that's not loaded.
My question is, does this apply to the atmega328? If it reads every instruction straight from flash without using a cache then it shouldn't matter much if it has to jump in the instructions, right?


texts: Is it any way to connect ESP8266 to wifi faster?

texts:
I'm uploading this sketch to try connecting ESP to internet. However, most of the times I've ran it it takes a very long time to connect, a lot of times I've had to break the process because it seems it goes to nowhere. Few times it has connected in less than a minute. Is it any alternative to boost the connection?

Also, when I reset the module, it writes to the terminal 3 strange characters, and freezes without even starting to execute its sketch. Do you mind me asking how to solve that?

Regards!

#include <ESP8266WiFi.h>

const char red[] = "CDT10";
const char pass[] = "G7ZSY74Cs";
unsigned long muestra = 0;

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(red,pass);
  while (WiFi.status() != WL_CONNECTED){
    Serial.print(".");
    delay(1000);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: "); Serial.println(WiFi.localIP());
  Serial.print("Chip ID: "); Serial.println(ESP.getChipId());
}

void loop() {
  delay(5000);
  muestra = millis();
  Serial.println(muestra);
}


texts: Code Optimization: Interrupt when a value reaches 0

texts:
I have this working program that I wish to improve efficiency as much as possible.
It will blink slow, then faster and faster until it restarts.
It works, but my main concern is, currently, I am using a if statement in the void loop(), and I am certain that, using an interrupt when a specific variable has reached 0, would improve efficiency.
byte amp = 0;
void setup() {pinMode(13, OUTPUT);
              reset();
}
void loop() {            //The following
  digitalWrite(13,HIGH); //code is for the sake of example
  delay(amp*100);        //Simplified to focus on the loop
  digitalWrite(13,LOW);
  delay(amp*100);
  amp--;
  if(!amp){reset();}     //<-This right here
}
void reset() {amp = 10;}

My understanding is, the if statement is called every time the loop restarts.

Is it possible to set up an Interrupt for when a certain variable reaches 0?
Which option would require less computing power, a continually called if loop, or an interrupt?

Thanks!


texts: What is difference between ATMEGA32 and ATMEGA328?

texts: I'm new in electronics. Just playing with Arduino boards.I just wanted to program ATMEGA328 micro-controller and use it without Arduino for compact design for my personal hobby project. I found there are ATMEGA32 and ATMEGA328 micro controllers in my local store. So, I wanted to know can I use ATMEGA32 instead of ATMEGA328 ? Which one is latest and whats are benefits. Thanks in advance.


texts: How to prevent shoot-through when swiching a motor with a bridge?

texts:
Ideally, when wiring a motor with an H-Bridge one would ensure that all "open" operations are performed before and "close" operations in order to prevent a short circuit. How does one ensure that these operations are performed in order when using a bridge?

I see on some forums that the L298 IC is a recommended bridge for controlling motors with the Arduino, but this condition is seemingly never discussed. It is not an issue with the speed of modern ICs or are the common tutorials overlooking shoot-through in the interest of simplicity?


texts: Performance of internal vs external resistors

texts:
Is there any significant performance trade-off between buttons wired with the internal vs external pull-up/down resistors? I see a lot of tutorials demonstrating the use of external resistors when wiring a simple button, like this and this. But since the Arduino/AVR includes internal pull-up resistors, you can wire a button without any external resistor as demonstrated here.

Is there any good reason to complicate your design with an extra resistor?


texts:
The Arduino SW, under Tools, identifies my Uno as COM Port 3. However, COM Port 3 on my computer is in use by a chip set. My computer assigned COM Port 4 to my Arduino Uno.

Can I reassign my Uno to COM Port 4?

Edit: This question also applies to people who don't have administrative privileges. They do not have privileges to change the port via Windows Device Manager.


texts: Arduino is incorrectly reading serial input from C# program

texts:
I am trying to create a program to operate my arduino based LED controller. I'm pretty sure that my C# program is outputting to serial port correctly as I double checked the output in Debug.WriteLine(). The program is supposed to send information to the arduino in the following format (newlines included):

mode
number of colors
blend speed
beats until color change
Red   <---
Green <---
Blue  <---
Brightness <---

the last 4 are the only ones that matter for now as I am trying to get the LED's to show up one solid color first before worrying about other modes or patterns. The debug writeline loop output of my last test looks like this

1
1
0
1
209
255
255
219

This should be translating to the relevant arduino variables the same way but instead, I only get white light that seems to randomly brighten or darken when I mess with the color/brightness sliders

My code for the arduino is below. I am very new to this so it's probably not even close to right. getData() at the bottom is the function that most likely is the culprit, but I'll put the rest in just in case:

#include <SPI.h>
#include <Adafruit_DotStar.h>

#define NUMPIXELS 60

Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);

// Variables
int mode;
int numColors;
int fadeSpeed;
int BBCC;
int R;
int G;
int B;
int Bright;
String buff;

void setup() {
  strip.begin();
  strip.show();
  //Serial.begin(9600);
}

void loop() {
  getData();

  if (mode == 1)
  {
    //strip.setPixelColor(0, R, G, B);
    strip.setBrightness(Bright);
    strip.show();
  }
}

void getData()
{
 // if (Serial.available() > 0)
 // {
    buff = Serial.read();
    int result = buff.toInt();
   mode = result;
   if (mode != -1)
   {
    buff = Serial.read();
    int result = buff.toInt();
    numColors = result;
    buff = Serial.read();
    result = buff.toInt();
    fadeSpeed = result;
    buff = Serial.read();
    result = buff.toInt();
    BBCC = result;
    buff = Serial.read();
    result = buff.toInt();
    R = result;
    buff = Serial.read();
    result = buff.toInt();
    G = result;
    buff = Serial.read();
    result = buff.toInt();
    B = result;
    buff = Serial.read();
    result = buff.toInt();
    Bright = result;//Serial.read();
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
   else
   {
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
//  }
}


texts:
I am working on Marlin 3D program. I made some changes for xyz prop and I do not make a definition as #define PRB_GCODE_END "G92 X-" XOFF "Y" XOFF "Z" ZOFF "\ n" to send the final xyz coordinates as gcode at the end of the promulgation procedure. It is required. If anyone has any idea how to use float type variables during macro definition please help.
void _user_gcode_exe(const char * const cmd) {
  lcd_return_to_status();
  enqueue_and_echo_commands_P(cmd);
}

void user_gcode_exe_1() {
  float XOFF = (25.00 + PRB_XOFFSET + (TOOL_DIA / 2.00));
  float YOFF = (25.00 - (PRB_YOFFSET + (TOOL_DIA / 2.00)));
  float ZOFF = (10.00 + PRB_ZOFFSET);

#define PRB_GCODE_END "G92 X-" XOFF " Y" XOFF " Z" ZOFF "\n"

#define PRB_GCODE "M117 Z-XY Probing now..\nG38.2 F120 Z-20.00\nG92 X0.00 Y.00 Z0.00\nG0 Z5.00 F1200\nG0 X-20.00 F1200\nG0 Z-5.00 F1200\nG38.2 F120 X25.00\nG92 X0.00\nG0 X-5.00 Y-25.00 F1200\nG0 X15.00 F1200\nG38.2 F120 Y25.00\nG92 Y0.00\nG0 Y-5.00 F1200\nG0 Z10.00 F1200\nG0 X-25.00 Y25.00 F1200\n"

#define MSG__OK "M117 Z-XY Probing done..\n"
  _user_gcode_exe(PSTR(PRB_GCODE PRB_GCODE_END MSG__OK));
}

While defining PRB_GCODE_END, ensuring that float type variables are included in this definition. For example: Considering that the variables XOFF, YOFF and ZOFF are calculated as 12.85, 11.25 and 10.50 respectively. PRB_GCODE_END should occur as follows:
G92 X-12.85 Y 11.25 Z10.50 \n


texts: What is the relationship of an Arduino .ino file to main.cpp?

texts:
Is the .ino file an alternative from a main.cpp file?

If yes, then could someone mind explaining the structure of the .ino file in main.cpp and its relationship?