texts:
So I have to get this function done but I'm not so bright and got confused.
(excuse me! I'm total noob)

The function is basically inputing text using five buttons, directional buttons and an ok button. The up and down buttons will be used to cycle through letters (a-z), and the left and right buttons will be used to control which array to cycle letters.

The control will be:

up button (up): ASCII-1 (z, y, x...)
down button (dw): ASCII+1 (a, b, c...)
right button (ri): array[i] ~> i+1 (go to next character/array)
left button (le): array[i] ~> i-1 (go to previous character/array)
ok button (ok): confirm text and changes the limit to stop function looping

I can't get it work with this code I write.

void intext()
{
  int lim=16;
  lcd.setCursor(0,1);
  lcd.print(input);
  for(i=0; i<lim ; )
  {
    if(digitalRead(dw)==HIGH)
    {
      if(input[i]<'a')
        input[i]='z';
      if(input[i]>'z')
        input[i]='a';
      input[i]=input[i]+1;
      delay(1000);
    }
    if(digitalRead(up)==HIGH)
    {
      if(input[i]<'a')
        input[i]='z';
      if(input[i]>'z')
        input[i]='a';
      input[i]=input[i]-1;
      delay(1000);
    }
    if(digitalRead(ri)==HIGH)
    {
      delay(1000);
      i=i+1;
    }
    if(digitalRead(le)==HIGH)
    {
      delay(1000);
      i=i+1;
    }
    if(digitalRead(ok)==HIGH)
    {
      lim=i+1;
      delay(1000);
    }
  }
}

void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Type your text:");
  intext();
  lcd.setCursor(0,0);
  lcd.print("Success!!");
  lcd.setCursor(0,1);
  lcd.print(input);
}

The result I wanted it to be is like this:
first you got the "type your text:" on the first row and blank in the second row.
our cursor is in the first column of the second row, so we can cycle through the alphabet letters. if you press right you can edit the next column of second row. you can get to the previous column in second row by pressing left. you can input up to 15 characters.
after done typing pressing ok will stop the typing and you will see "Success!!" in the first row and typed text in the second row.

Please help. I'm stumped.
Thank you.


texts:
I am trying to burn bootloader on Arduino UNO using MEGA2560 as the programmer,
I followed the steps stated here but still get the error below:
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/arduino/arduino-nightly/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/webdev/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.02s

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

avrdude done.  Thank you.

Note: The Arduino UNO stopped responding when I mistakenly short-circuited a connection, I mistakenly passed 12v to one of the header pins of sensor shield mounted on the board.
How it was connected


texts: How can I see if volume buttons of Apple earphones are pressed?

texts:
I need to be able to see if the volume controls and the middle button of Apple earphones are pressed.

I am using an Arduino Uno. I was thinking about using the analogRead function.

I tried connecting the ground of the audio jack to the ground of the Arduino, the micro of the audio jack to the analogPin 0 on the left and right of the audio jack to the 3.3 volt output of the Arduino, but the results of the analogRead are not really useful. They are constantly changing.

So guys i have this code that constantly gives a bunch of numbers. They are never constant.

int analogPin = 0;
int ledPinBlue = 8;
int ledPinRed = 9;

int val = 0;
int times = 0;
int clickTimes = 0;

void setup()
{
  pinMode(ledPinBlue, OUTPUT);
  pinMode(ledPinRed, OUTPUT);
  times = 0;
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(analogPin);
  if (val == 0) {
times = times + 1;
  }
  else if (!val == 0) {
times = 0;
  }
  if (times == 500) {
times = 0;
digitalWrite(ledPinBlue, HIGH);   // sets the LED on
delay (500);
digitalWrite(ledPinBlue, LOW);    // sets the LED off
Serial.println("Click");
  }
}

When I press the button of the microphone (the middle button) of the apple earphones, the numbers change to a constant 0.

But when I press the volume buttons, nothing seems to change. Any ideas?


texts: Implement a discrete controller /transfer function with arduino uno

texts:
i want to implement a discrete transfer function at z domain with arduino UNO.I  know that i must do the inverse z transform and find the difference equation.Afterwards i must use PWM because arduino UNO has not DAC.
Is there anyone who knows about this ?and can help me.... i want a code as an example  .Thank you.


texts: Uno to ESP32 - HardwareSerial repeats value on ESP32's side even though Uno is disconnected

texts:
I have an Arduino UNO connected to ESP32 through voltage divider with TX0 from Uno to RX2 to ESP32. My goal is to send data from my Uno to my ESP32 through HardwareSerial. Here's my code for the Uno:
void setup() {
Serial.begin(9600);
}

void loop() {
int t = 100;
String myString = String(t);
Serial.println(t);
delay(5000);
}

Here I assign an int to 100 and then cast it to String so I can send it on my ESP32's side. My code for ESP32 is:
#define RXD2 16
#define TXD2 -1

HardwareSerial Serial2(1); // Use UART channel 1

void setup() {
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

void loop() {
if(Serial2.available() >= 1){
Serial.print("Data received:");
Serial.print(Serial2.readString());
}
}

The serial monitor on ESP's side is printing only "100" on every 5 seconds but if I disconnect the Uno from my Port, the ESP's monitor keeps printing "100" even tho it shouldn't.
However, IF I type Serial.println("100"); then I get "Data received: 100" on ESP's side and if I unplug the Uno, the ESP's monitor doesn't print anything or with other words it works properly. Is there a way I can fix this?


texts: Inspired by an example question before beta, can I make the Leonardo bootloader take less that 8 seconds to run? It is very slow and I want to speed it up somehow.


texts: Mega SPI communication changing between setup and loop

texts:
I am attempting to use an arduino MEGA 2560 to control a digital potentiometer (AD5206), but I am getting some strange behavior. I have attached the CLK and MOSI pins (52 and 51, respectively) to an oscilloscope, and have run the following code:

#include <SPI.h>
void setup() {
    SPI.begin();
    SPI.transfer(5);
    delay(500);
}

void loop() {
    SPI.transfer(5);
    delay(500);
}

When I look at the signal, the transfer in the setup() looks correct (5V x 00000011), but then the transfer in the loop() looks like it's shifted by -5V (-5V x 11111100). Has anyone ever run into this? Is it possible for the MEGA to output a negative voltage?


texts: Send signal to vibrate a Restaurant buzzer via web based app to a PC

texts:
I'm new to Arduino, I want to create a restaurant buzzer using Arduino and it should turn on/off via web based interface. It will be locally connected only.

Is it possible to send a signal with the mac address of the master transmitter pc to vibrate the buzzer?

What are the materials should I need? Suggestions or any tips is greatly appreciated.


texts: how to read all line except the first line?

texts:
is there a way to read only 2nd up to the last line except for the first line?

here's my sample code

File myFile;
char cr;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());

    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}


texts:
I write a piece of code in online GDB using c++, the code calculates some coefficients for a IIR filter which tries to approximate a fractional derivative and integral for a fractional PID control. The code works as expected in the online IDE, but when I try to execute it in a Arduino Due, the results and only overflows and nan, and really don't know what's the problem so,

Here is the code in GDB online https://onlinegdb.com/rycwt62XL which gives the expected results:

Array A, Array B

1.41421,1

-0.707107,0.5

-2.12132,-1.5

0.883883,-0.625

0.883883,0.625

-0.265165,0.1875

-0.0883883,-0.0625

0.0110485,-0.0078125

And here is the code for the Arduino Due, which only change the printing method using the serial commands, https://onlinegdb.com/ByAs5xyVU, and the results are:

Array A, Array B

ovf,1.00

ovf,ovf

ovf,0.00

inf,ovf

ovf,0.00

inf,ovf

ovf,3.89

inf,ovf

And really don't know where to start for fix this results, thanks. The Method is  exactly the same.


texts:
I'm currently working on an Arduino project that sends the charge of my car battery once a day via an ESP8266 to me. During the winter I don't drive my car, and I would like to get informed when the battery drops beyond a critical value, so I can charge it and prevent damage.

So energy efficiency is important for the project, so it doesn't discharge the battery itself. I read a lot about sleep mode, efficient drop down regulators etc. These all have in common that the voltage regulator is always running, which is not what I want.

I'm looking for some kind of "swich-on-timer circuit". It should count down 24 hours and then turn on a relay or MOSFET, which connects the voltage regulator to power and with that turns on the Arduino and the ESP8266. When the Arduino has finished with the transmission, it resets the timer, which disconnects the voltage regulator from power, and so on. Of course, the timer circuit should use only very little power.

Does anybody know a circuit like that? I searched on AliExpress with all variations of words that came to my mind, without success. Or maybe an IC which can be used (easily) to create such a circuit?


texts: Creating a webserver on a Wemos D1 mini pro

texts:
I am trying to put a web server on my Wemos D1 mini pro. I am using this example for the Arduino code:
https://github.com/wemos/Arduino_D1/blob/master/doc/esp8266wifi/server-examples.rst

#include <ESP8266WiFi.h>

const char* ssid = "GL-AR300M-ceb";
const char* password = "********";

WiFiServer server(80);

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

  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

  server.begin();
  Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str());
}

// prepare a web page to be send to a client (web browser)
String prepareHtmlPage()
{
  String htmlPage =
     String("HTTP/1.1 200 OK\r\n") +
            "Content-Type: text/html\r\n" +
            "Connection: close\r\n" +  // the connection will be closed after completion of the response
            "Refresh: 5\r\n" +  // refresh the page automatically every 5 sec
            "\r\n" +
            "<!DOCTYPE HTML>" +
            "<html>" +
            "Analog input:  " + String(analogRead(A0)) +
            "</html>" +
            "\r\n";
  return htmlPage;
}

void loop()
{
  WiFiClient client = server.available();
  // wait for a client (web browser) to connect
  if (client)
  {
    Serial.println("\n[Client connected]");
    while (client.connected())
    {
      // read line by line what the client (web browser) is requesting
      if (client.available())
      {
        String line = client.readStringUntil('\r');
        Serial.print(line);
        // wait for end of client's request, that is marked with an empty line
        if (line.length() == 1 && line[0] == '\n')
        {
          client.println(prepareHtmlPage());
          break;
        }
      }
    }
    delay(1); // give the web browser time to receive the data

    // close the connection:
    client.stop();
    Serial.println("[Client disonnected]");
  }
}

It uploads fine and when I open the serial monitor get this:

Connecting to GL-AR300M-ceb . connected
Web server started, open 192.168.8.119 in a web browser

When I go to the IP address that it gives in the monitor, I only see a blank page. I also can't inspect element, so it doesn't load the HTML part I guess.
When I change the code like this:

if (client.available())
{
//        String line = client.readStringUntil('\r');
//        Serial.print(line);
//        // wait for end of client's request, that is marked with an empty line
//        if (line.length() == 1 && line[0] == '\n')
//        {
//          client.println(prepareHtmlPage());
//          break;
//        }
          client.println(prepareHtmlPage());
      }

then i see this

And when i add the break in the code like so:

client.println(prepareHtmlPage());
break;

in the code, i get the blank page again.

Does someone have an idea what the problem might be?


texts:
I am using multiple ATMEGA328Ps  (4 ATMEGA328P) (OR Arduino Unos). The distance between two farthest ATMEGAs is 14 meters (One is Master Device and Other is Node), and other 3 are connected to each other at a distance of 3 meters from the Master Device.
I have a case where i cannot use Wireless communication hence i will have to go Wired. I am also looking to achieve the Mesh topology if possible.

There are many examples on the internet regarding this case but still i am not be able to choose/compare which would be more reliable.

Please suggest me the best solution to work on this.
Thanks.


texts:
I just got the TLE9879 BLDC shield, which I connected to an Arduino Leonardo. Compiling the example sketch (bldc_shield_blinky_test) went fine, however, upon flashing it to the board the LED on the shield doesn't change the color (it stays white) and the following line is repeatedly printed to the Serial console:

  WARNING: Board[1]; Command[901]; Answer[0]

I have initially tried the shield in its out of the box state. I have since then flashed it with the HALL version of the shield software, using the project included in the SW distribution that comes with the shield. In both cases, the shield behaved as described above when connected to the Arduino.

Does anybody know what this warning message is about?


texts:
I'm trying to write the payload of a MQTT message into a file in the SPIFFS file system of my esp32 board. I've tried this:

if(file.print((long)payload)) {
   Serial.println("File was written");
}else {
   Serial.println("File write failed");
}

payload is a byte* and file was opened in the setup() function like:

File file;
if(!SPIFFS.exists("/testfile")){
  file = SPIFFS.open("/testfile", "r+");
}

I always get an error when writing to it telling me that the file write failed. Is this the correct approach for what I'm trying to accomplish?


texts: Sending NEC IR signals makes LED strip blink

texts:
I'm trying to make my ESP8266 (running NodeMCU meaning Arduino code gets compiled on it). I followed a guide and now I can read the IR codes from my remote using my Arduino UNO, and then send them to the LED strip. So far sending it actually works, but it blinks REALLY fast.

Some part of me tells me it's trying to send it twice or the radio frequency is wrong. For TVs and so on, it doesn't really matter, as you can't turn on and off a TV instantly. You can with this LED strip though. This is how I send my NEC signal to the strip:

irsend.sendNEC(0xFF02FD, 433);

433 is the frequency (433 kHz), as I read that's the most common frequency these LED strips work at. The entire code I used can be found here. Do you think I have a frequency issue? I have tried a lot of different frequencies and they all seem to do the same thing.

Also, when I try to send the exact same NEC signal to my receiver, I get two different results. It is only being sent one time as well. Here is what I receive:

Using the actual receiver:

Decoded NEC(1): Value:FF02FD (32 bits)
Raw samples(68): Gap:51848
  Head: m8750  s4550
0:m450 s650 1:m450 s650      2:m450 s650    3:m450 s650
4:m500 s650 5:m450 s650      6:m450 s650    7:m450 s650
8:m450 s1750    9:m500 s1750         10:m450 s1750  11:m450 s1750
12:m500 s1750   13:m450 s1750        14:m450 s1750  15:m500 s1750

16:m450 s650    17:m450 s650         18:m450 s650   19:m450 s650
20:m500 s600    21:m500 s650         22:m450 s1750  23:m450 s650
24:m450 s1750   25:m500 s1700        26:m500 s1750  27:m450 s1750
28:m500 s1700   29:m500 s1750        30:m450 s650   31:m450 s1750

32:m450
Extent=66900
Mark  min:450    max:500
Space min:600    max:1750

Using irsend.sendNEC(0xFF02FD, 433)

Decoded Unknown(0): Value:0 (0 bits)
Raw samples(38): Gap:18088
  Head: m8850  s4550
0:m500 s1750    1:m500 s650      2:m450 s650    3:m500 s650
4:m500 s650 5:m450 s650      6:m500 s650    7:m450 s1800
8:m450 s700 9:m450 s1800         10:m450 s1800  11:m450 s1800
12:m450 s1800   13:m450 s1800        14:m450 s1800  15:m450 s650

16:m500 s1750   17:m500
Extent=43200
Mark  min:450    max:500
Space min:650    max:1800

EDIT: I forgot to mention: 0xFF02FD is the signal power/on/off button. If I change the 0xFF02FD to anything else (like 0xFF18E7 to make it yellow), the LED strip will just blink.


texts: How does the Arduino handle serial buffer overflow?  Does it throw away the newest incoming data or the oldest?  How many bytes can the buffer hold?


texts: missing some data after data is sent by FS1000A / XY-MK-5V 433Mhz TX/RX Module (WIFI)

texts:
I miss some data ( mostly, the latest characters of one data) when I want to send several messages from arduino to another arduino.
I'm trying to send and receive some data from arduino to another arduino and I'm using arduino UNO and FS1000A / XY-MK-5V 433Mhz TX/RX Modules. If I only want to sent Hello there It works very well but if I want to send several things I miss something. for example for this code, it works very well :
Transmitter:

#include <VirtualWire.h>
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}
void loop()
{
  char msg[11]="Hello there";
  vw_send((uint8_t *)msg, 11);
  vw_wait_tx();
  delay(1000);
}

receiver:

#include <VirtualWire.h>
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}
void loop()
{
  char msg[11]="Hello there";
  vw_send((uint8_t *)msg, 11);
  vw_wait_tx(); // Wait until the whole message is gone
delay(1000);
}

the result is :

Device is ready
Received: Hello there
Received: Hello there
Received: Hello there
Received: Hello there
Received: Hello there
Received: Hello there

for this code I missed some data:
transmitter:

#include <VirtualWire.h>
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}
void loop()
{

char msg[11]="Hello there";
  vw_send((uint8_t *)msg, 11);
  vw_wait_tx();
  char msg2[7]="Goodbye";
  vw_send((uint8_t *)msg2, 7);
  vw_wait_tx();
delay(1000);
}

The result is :

Device is ready
Received: Hello there
Received: Goodbye
Received: Hello t
Received: Goodbye
Received: Hello t
Received: Goodbye
Received: Hello t
Received: Goodbye
Received: Hello t
Received: Goodbye
Received: Hello t
Received: Goodbye
Received: Hello t


texts: Arduino based small LCD screen with camera video capturing

texts:
i have a idea to create a small screen which displays video recorded from arduino with camera. so camera will be back side of human and screen will be at near to eye. human can see the pictures from back side.

i have found https://electronics.stackexchange.com/questions/29139/processing-ntsc-video-feed-for-spi-display

but its not give me a clear idea. is there any one who can advice me for that kind project?


texts: How to programmatically choose "board model" and "port number" in Arduino IDE?

texts:
I'm testing three different Arduino (nano, Uno and Mega) each of them having a nRF module. The codes (sketches) are different for each module.
I've connected the arduinos to my single laptop via 3 USB ports.

Problem is, whenever I want to re-upload a sketch and fix a bug, I have to choose board model and port number of that sketch by using the menus. It has become frustrating using mouse each time I need to change something.
How can I set these parameters in code so each sketch knows which port and model it is related to?


texts:
This is a question about programming. Mainly about the loop() function

As an example
Consider code where you get data from an accelerometer, and if the Gs are high enough you do something.

Consider the following pseudocode:

void setup()
{
pinMode(1, INPUT);
bool flag = false;
}

void loop
{
int x= analogRead(1);
if (x>2)   //if the Gs we get from accelerometer
  flag = true;
if (button)  // if user hits the emergency button
  flag = true;

if (flag == true)
{
//GET SERIAL DATA (EG GPS COORDINATES)
//DO SOME HEAVY PROCESSING
}
}

Now loop runs repeatedly
That means all the commands are executed in a continuous/serial style

Since that happens, what will happen if the accelerometer reading where (x>2), which is what we look for, happen in the REAL world, at a time where in the CPU, the cpu is at that time processing or checking following commands in the program flow, like

if (button)  // if user hits the emergency button
      flag = true;

    if (flag == true)
    {
    //GET SERIAL DATA (EG GPS COORDINATES)
    //DO SOME HEAVY PROCESSING
    }
    }

Is there any chance that the cpu will miss real world events, because at that time the real world event occured, the cpu was processing other code. Or rather, not checking for that at that time. For our example, when the event occured, it wasnt checking the analogread() at that time, but was processing following code.

Should i worry about that?


texts: Galileo Positioning System signal receiving

texts:
I want to determine my arduino's position. However, I want to use the European Galileo system instead of the US-American GPS.

Therefore, I searched for any possibilities receiving the Galileo signals. I figured out, that u-blox has some receivers: NEO 8 or the LEA 6 (firmware update required). However I did not find any arduino breakout board (, etc.) that uses these u-blox sensors or other Galileo-compatible hardware.

Does anyone know, how I could use the Galileo Position System?


texts: Reading names of files on sd card returning odd file names

texts:
When trying to read the file names from an sd card some are being returned with a ~1 and cutting off the full file name.

Initializing SD card...initialization done.
TEST.TXT        402
UNTITL~1        0
HELLOT~1        49
DATALOG.TXT     562288
ALONGN~1        0
done!

Is there any way I get the full file name of each file?

The code for this is from here: https://www.arduino.cc/en/Tutorial/Listfiles


texts: WebSocket message with Arduino MKR 1010 using WiFiNINA and ArduinoHttpClient libraries

texts:
I am trying to send a WebSocket message to a server. The example for the ArduinoHttpClient library uses WiFi101 but that will not work for the MKR 1010. So I am trying to use WifiNINA instead. The WiFi part works fine but is seems the WebSocket cannot "begin".

#include <SPI.h>
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h> /*Need to implement*/
//https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/examples/SimpleWebSocket/SimpleWebSocket.ino
//https://www.arduino.cc/en/Tutorial/WiFiNINAConnectWithWPA

char ssid[] = "SSID_NAME";        // your network SSID (name)
char pass[] = "WPA2_Password";    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the Wifi radio's status
char serverAddress[] = "192.168.0.195";  // server address
int port = 3652;

WiFiClient wifi;

WebSocketClient client = WebSocketClient(wifi, serverAddress, port);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();

}

void loop() {
  // check the network connection once every 10 seconds:
  delay(10000);
  //printCurrentNet();

    Serial.println("starting WebSocket client");
    client.begin();
    Serial.print("Is client connected? -> ");
    Serial.println(client.connected());

      client.beginMessage(TYPE_TEXT);
      client.print("Fire alarm from arduino mkr1010 - sensor1 ");
      client.endMessage();

    while (client.connected()) {
      Serial.print("Sending fire alarm ");
      // send fire alarm
      client.beginMessage(TYPE_TEXT);
      client.print("Fire alarm from arduino mkr1010 - sensor1 ");
      client.endMessage();
    }
    /*
      // check if a message is available to be received
      int messageSize = client.parseMessage();

      if (messageSize > 0) {
        Serial.println("Received a message:");
        Serial.println(client.readString());
      }*/

}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

Could it be that there are compatibility issues between the ArduinoHttpClient library and the Arduino MKR1010? I am thinking of getting an ESP32 instead since there seem to be more WebSocket libraries built around it.


texts: How can I detect which baudrate a virtual COM port is set to?

texts:
I would like my software running on Leonardo to behave differently depending on the baudrate of the USB Serial set by the PC. For example, I want to make a smart USB to UART converter which performs some processing of the data it transmits. It would be much more elegant to set the UART baudrate to whatever value the PC is requesting on USB side, rather than hardcoding a value.

AFAIK 32u4 chip is used as a USB to UART converter on Mega, where it supports different baudrates, so this should be doable.

I also have a Teensy 3.2 board, so if anyone knows how to detect the baudrate on this board I'm also interested.


texts:
I tried to connect xampp/mysql to arduino but connection fails.
mysql is running on port 3306.
I searched a lot on the internet but could not understand where is the problem!
Would you please help me...

#include <Ethernet.h>
#include <MySQL_Connection.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(127,0,0,1);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "";        // MySQL user login password

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  Serial.begin(9600);
  while (!Serial); // wait for serial port to connect
  Ethernet.begin(mac_addr);
  Serial.println("Connecting...");
  if (conn.connect(server_addr, 3306, user, password)) {
    delay(1000);
     Serial.println("Connection stablished.");
    // You would add your code here to run a query once on startup.
  }
  else
    Serial.println("Connection failed.");
  conn.close();
}

void loop() {
}


texts: HTTP Post data from Arduino uno using WiFi

texts:
Please help me to post data from arduino uno to a webpage using wifi(ESP-01) module. I try with AT commands it didn't give the response from my webpage

#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#define DEBUG true

#define RX 10
#define TX 11
String WIFI_SSID = "*****";       // Your WiFi ssid
String PASSWORD = "*****";         // Password
//String DEVICE_SECRET_KEY  = "**";

//String PATH = "/v1/events";
//String PORT = "8000";
//String HOST = "http://10.**.***.66:8000/data";

String HOST = "10.**.240.**";
String PATH = "/data";
String PORT = "8000";

String response;
int countTrueCommand;
int countTimeCommand;
boolean found = false;

SoftwareSerial esp8266(RX, TX);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();

void setup()
{
  Serial.begin(115200);
  esp8266.begin(115200);
  esp8266.println("AT");
  Serial.println(esp8266.read());
  sendCommandToESP8266("AT", 5, "OK");
   sendCommandToESP8266("AT+CWMODE=3", 5, "OK");
  sendCommandToESP8266("AT+CWJAP=\"" + WIFI_SSID + "\",\"" + PASSWORD + "\"", 20, "OK");
}

void loop()
{
  root["key"] =  "sdfsdfsd";
  String key;
  root.printTo(key);
  String postRequest =   "POST " + PATH  + " HTTP/1.1\r\n" +
                         "Host: " + HOST + "\r\n" +
                         "Accept: *" + "/" + "*\r\n" +
                         "Content-Length: " + key.length() + "\r\n" +
                         "Content-Type: application/json\r\n"
                         "\r\n" + key;
  Serial.print("pst:" + postRequest);
  sendCommandToESP8266("AT+CIPMUX=1", 5, "OK");
  sendCommandToESP8266("AT+CIPSTART=0,\"TCP\",\"" + HOST + "\"," + PORT, 15, "OK");
  String cipSend = "AT+CIPSEND=0," + String(postRequest.length());//GET /test.php?Data=2\r\nHost:192.168.1.13\r\n\r\n
  sendCommandToESP8266(cipSend, 4, ">");
  sendData(postRequest);

  while (esp8266.available())
  {
    if (esp8266.find("+IPD,"))
    {
//      String msg;
      esp8266.find("?");
//      msg = esp8266.readStringUntil(' ');
      response = esp8266.readStringUntil(' ');
      Serial.print(response);
      Serial.println();
    }
  }
  printResponse;

  //  sendCommandToESP8266("AT+CIPCLOSE=0", 5, "OK");
}

void sendCommandToESP8266(String command, int maxTime, char readReplay[]) {
  Serial.print(countTrueCommand);
  Serial.print(". at command => ");
  Serial.print(command);
  Serial.print(" ");
  while (countTimeCommand < (maxTime * 1))
  {
    esp8266.println(command);
    if (esp8266.find(readReplay))
    {
      found = true;
      break;
    }

    countTimeCommand++;
  }

  if (found == true)
  {
    Serial.println("Success");
    countTrueCommand++;
    countTimeCommand = 0;
  }

  if (found == false)
  {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }

  found = false;
}

void sendData(String postRequest) {
  Serial.println(postRequest);
  Serial.println();
  esp8266.println(postRequest);
  delay(15000);
  countTrueCommand++;
}

void printResponse() {
  while (esp8266.available()) {
    Serial.println();
    Serial.println(esp8266.readStringUntil('\n'));
  }
}

Please help me to get the response from the webpage using this code.


texts: bitClear doesn't work on most significant bit

texts:
I'm currently working on a project where I read a 32 bit sequence.
The digitalPin is always HIGH when no sequence is received and starts oscilating with about 1kHz when the sequence starts (RC5).
I am setting and clearing bits of an uint32_t depending on which signal is on the digitalPin.
It seems to work very well with every bit except of the MSB.
Here a short code snippet to show what I mean:
const short irPin = 8;
const short msgDelay = 250;

uint32_t data = 0xFFFFFFFF;
long msgArrived = 0;

void setup(){
  Serial.begin(115200);
  pinMode(irPin, INPUT);
}

void loop(){
  long now = millis();

  if( (!(PINB & 1)) && ((now - msgArrived)> msgDelay)){
    msgArrived = millis();
    bitClear(data, 31);

    Serial.println(data, BIN);
  }
}

This gives me an output of
11111111111111111111111111111111

I have already tried
bitClear(data, 32); -> 11111111111111111111111111111111
bitClear(data, 30); -> 10111111111111111111111111111111

So every output is right, but not the when I try to clear the msb.
Has anyone experienced a similar behaviour?


texts:
I was trying to extract data from a multi-function meter with RS485 connectivity and I am using Arduino as master, Arduino Uno and multi-function meter are connected via MAX485 module.
I have tried some code but it returns an E2 error which means communication error.
Kindly explain me the program and help me to solve it.
#include <ModbusMaster.h>

#define MAX485_DE 3
#define MAX485_RE_NEG 2
ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG,1);
  digitalWrite(MAX485_DE,1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG,0);
  digitalWrite(MAX485_DE,0);
}

void setup()
{
  pinMode(MAX485_RE_NEG,OUTPUT);
  pinMode(MAX485_DE,OUTPUT);
  digitalWrite(MAX485_RE_NEG,0);
  digitalWrite(MAX485_DE,0);

  Serial.begin(9600);

  node.begin(1,Serial);
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop()
{
  uint8_t resultMain;

  resultMain = node.readHoldingRegisters(0x0100,6);
  Serial.print(resultMain,HEX);

  if (resultMain == node.ku8MBSuccess)
  {
    Serial.print(resultMain);
    Serial.print(node.getResponseBuffer(0x32));
  }
  delay(1000);
}


texts: So far I have been using TinkerCAD which has them but I am unable to find them on EasyEDA Library. Are connectors supposed to do the same thing? I get this empty rectangle in the EasyEDA library which I am unable to make sense of.


texts:
Can we use serial communication in arduino only for RX pin, so that I am free to use pin 1(TX) as digital I/O:

Serial.write('a');
pinMode(1,OUTPUT);
digitalWrite(1,LOW);


texts: DC motors not running using PWM and L298N motor driver

texts:
I'm just beginning to understand Arduino. Please bear with me. I have a collision avoidance car running on Arduino Uno, WB291111 L298N motor driver, SG90 servo, Arduino Shield v5, and HC-SR04 ultrasonic sensor. Also, I have the entire setup running on 8.4v batteries. If I just use HIGH/LOW on the motors, it will run without any problems. But if I use the PWM to run the motors on different speeds, it will NOT run at all. The sensor and servo works, but not the motors.  See my codes below. Let me know if you need further details. Any help is greatly appreciated.

#include <Servo.h>
#include <NewPing.h>

//our L298N control pins
const int enA = 10;
const int in1 = 6;
const int in2 = 7;

const int enB = 9;
const int in3 = 4;
const int in4 = 5;

//sensor pins
#define trig_pin A2
#define echo_pin A1

#define maximum_distance 500
boolean goesForward = false;
int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance);
unsigned int uS;

#define SERVO_PIN 11
Servo servo_motor;

void setup(){
  Serial.begin(115200);
  pinMode(enA, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

  servo_motor.attach(SERVO_PIN);

  servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

  if (distance <= 20){
    moveStop();
    delay(300);
    moveBackward();
    delay(200);
    moveStop();
    delay(300);
    distanceRight = lookRight();
    delay(200);
    distanceLeft = lookLeft();
    delay(200);

    if (distance >= distanceLeft){
      turnRight();
      moveStop();
    }
    else{
      turnLeft();
      moveStop();
    }
  }
  else{
    moveForward();
  }
    distance = readPing();
}

int lookRight(){
  Serial.print("Look Right");
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

int lookLeft(){
  Serial.print("Look Left");
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=500;
  }
  return cm;

}

void moveStop(){
  Serial.print("Stop");

  digitalWrite(in3, LOW);
  digitalWrite(in1, LOW);
  digitalWrite(in4, LOW);
  digitalWrite(in2, LOW);
}

void moveForward(){

  //if(!goesForward){

    //goesForward=true;

    Serial.print("Forward");

    digitalWrite(in1, HIGH);
    digitalWrite(in3, HIGH);

    digitalWrite(in2, LOW);
    digitalWrite(in4, LOW);

    analogWrite(enA, 250);
    analogWrite(enB, 250);

  //}
}

void moveBackward(){

  //goesForward=false;

  Serial.print("Backward");

  digitalWrite(in2, HIGH);
  digitalWrite(in4, HIGH);

  digitalWrite(in1, LOW);
  digitalWrite(in3, LOW);

}

void turnRight(){
  Serial.print("Right");

  digitalWrite(in1, HIGH);
  digitalWrite(in4, HIGH);

  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);

  delay(200);

  digitalWrite(in1, HIGH);
  digitalWrite(in3, HIGH);

  digitalWrite(in2, LOW);
  digitalWrite(in4, LOW);

}

void turnLeft(){
  Serial.print("Left");

  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);

  digitalWrite(in1, LOW);
  digitalWrite(in4, LOW);

  delay(200);

  digitalWrite(in1, HIGH);
  digitalWrite(in3, HIGH);

  digitalWrite(in2, LOW);
  digitalWrite(in4, LOW);
}


texts: incoming GSM data stored as variable in code

texts:
I am using an Arduino Mega board with a SIM900 GSM.

My goal is to be able to text the GSM with a value of two digits (ex: 79) and then store that value as a variable in the code.

I know how to set up the Mega and the GSM in terms of wiring and initialization of ports, but I am not sure what command/ combinations of commands I should use to take the incoming data from the GSM and store it as a variable.

If anyone can help me with this I would greatly appreciate it.


texts: Arduino Uno Sensor DHT11 Failed to read from DHT sensor

texts:
I get this error every time. I used the DHT tester file from this library. Which gives me an error.

And then I realized that in my code Arduino recognizes only the readTemperature function, not readHumidity, but it doesn't give any compile error. Also, when I read the sensor, this is the output:

  Humidity Sensor Test
  Temp: 0C, Humidity: 0%
  Temp: 0C, Humidity: 0%
  Temp: 0C, Humidity: 0%

My code is here:

//DHT11 Sensor:
#include "DHT.h"
#define DHTPIN 5 // which digital pin we're connected to
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

//I2C LCD:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

// Set the LCD I2C address
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {
  Serial.begin(9600);
  delay(300);
  lcd.begin(16,2);
  Serial.println("Humidity Sensor Test");
  dht.begin();
  delay(300);
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  int t = dht.readTemperature();

  // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:

  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print("C");

  // set the cursor to (16,1):
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");

  Serial.print("Temp: ");
  Serial.print(t);
  Serial.print("C, Humidity: ");
  Serial.print(h);
  Serial.println("%");
  delay(2500);
}

Also I have the 10k resistor between data and Vcc pins. Data is connected to digital pin 5. Has anyone had this problem before?


texts: Cannot get pins on esp 8266 adafruit wifi module to read HIGH on pin 15

texts:
I have an esp8266 and I cannot get the value to read HIGH when 3.3v is applied to directly to pin by hand. I have an Arduino Uno powering the esp8266. It connects to the WiFi like it should, and now all I want is to manually see that when I apply 3v that the state will change from 0 to 1. Does anyone know how I can do this.

When I apply 3 volts directly to pin 15 it outputs 0. Even if I try digitalWrite on the pin and set it to HIGH it still says 0 and i serialPrint. My end goal if to use the arduino uno to fire and ouput on pin 8. On the arduino UNO side I am using a super sonic sensor. When the sensor is triggered I want to turn pin 8 on. From there I want to take pin 8 to feed pin 15 on the 8266 as an input. Before I did that I just wanted to see that when you manually apply 3v that the pin would read 1 or HIGH but no matter I do it wont change value. Once I get that value as HIGH I can send  a second request to the server like im already but now I want to say  that there was an intruder. Im not sure why the value wont change but being a beginner with arduino Im trying to keep it simple and ideally would like to wire it in this manner.

#include <SoftwareSerial.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

const char* ssid = "********";
const char* password = "********";

HTTPClient http;

static const uint8_t D8 = 15;
int featherPin = D8;

//int trigPin = 13;
//int echoPin = 12;
//int ledPin = 10;
//int hornPin = 11;
//
//int spaceIntruded;
//
//long duration, cm, inches;

void setup() {
  Serial.begin(115200);
  pinMode(featherPin,INPUT);

  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Waiting for connection");
 }

//  Serial.begin (9600);
//  pinMode(trigPin, OUTPUT);
//  pinMode(echoPin, INPUT);
//  pinMode(ledPin, OUTPUT);
//  pinMode(hornPin, OUTPUT);
//  delay(5000);
//  Serial.println("Armed...");

}

void loop() {

  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("yay connect");

    http.begin("http://10.150.40.121:3000/");
    http.addHeader("Content-Type", "text/plain");

    int httpCode = http.POST("Message from ESP8266");
    String payload = http.getString();
    Serial.println(payload);
    http.end();

    } else {
      Serial.println("Error in Wifi connection");
    }
//    digitalWrite(featherPin, HIGH);
    int sensorValue = digitalRead(featherPin);
    Serial.print(sensorValue);

//    if (digitalRead(featherPin) == HIGH) {
//      http.begin("http://10.150.40.121:3000/home");
//      http.addHeader("Content-Type", "text/plain");
//
//      int httpCode = http.POST("Message from ESP8266");
//      String payload = http.getString();
//      Serial.println(payload);
//      Serial.print("hi");
//      http.end();
//      } else {
//        Serial.print(featherPin);
//        Serial.println("I am not hot");
//      }

//  digitalWrite(trigPin, LOW);
//  delayMicroseconds(1);
//  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(2);
//  digitalWrite(trigPin, LOW);
//
//  pinMode(echoPin, INPUT);
//  duration = pulseIn(echoPin, HIGH);
//
//  inches = (duration / 2) / 74;
//  Serial.println(inches);
//
//  spaceIntruded = inches;
//
//  if (spaceIntruded <= 50 || spaceIntruded >= 900){
//      digitalWrite(ledPin, HIGH);
//      digitalWrite(hornPin, HIGH);
//      Serial.println("Intruder Detected!");
//      Serial.println("Sending text Notification...");
//      delay(500);
//      Serial.println("Armed...");
//  }
//
//  else{
//    digitalWrite(hornPin, LOW);
//    digitalWrite(ledPin, LOW);
//  }
    delay(30000);

}


texts: Why LED light delay is 5 second in arduino?

texts:
My code :

int pin = 8;
int pout = 12;
int result=0;
void setup() {
  pinMode(pin, INPUT);
  pinMode(pout, OUTPUT);
}

void loop() {

  result = digitalRead(pin);

  if(result == 1)
  {
    digitalWrite(pout, HIGH);
    delay(1000);
  }
  if(result == 0)
  {
    digitalWrite(pout, LOW);
  }

}

I have set delay 1 sec but whenever i put high voltage on pin 8 The LED glow for 5 second. why?

How to set delay to none ? means whenever the pin 8 is HIGH the LED will glow else off.


texts: Reading the DotStar datasheet - power requirements

texts:
I'm trying to figure out my power requirements for a strand of Adafruit DotStar LEDs - APA102 Cool White, not the RGB. I'm not sure how to interpret the datasheet.

In the middle of the product spec table on page 1, under Power Consumption, it says 0.2W (MAX: 1W).  Which would mean at 5V, MAX would be 0.2A, or 200mA.

Then on page 3 in the electrical characteristics table under the symbol/Parameter "LOL/Sink Current Voltage" it says typ. 24.5mA; max. 26.5mA.

I plan on having the strand on full brightness most of the time.

So which is it?  200mA? or 26.5mA?


texts: How to get body temperature using MLX90614 DCI on Arduino

texts:
The MLX90614 provides 2 temperature outputs, namely surface temperature and ambient temperature. But how do you calculate the right body temperature from these two outputs?
Here are the results of my experiment at a distance of 1 inch:
(Temperature centigrade)

If you see table above, in the range with an ambient temperature of 27°C the surface temperature shows, on average, 33°C, but it will go up when the ambient temperature is 29°C; then the surface temperature shows an average of 35°C.
If I test with a temperature device, then my body temperature at the same distance and target is in the range of 36.3°C to 36.7°C.
Please help me how to calculate / get body temperature from MLX90614 DCI.


texts: How to control nokia 5110 display using esp-01

texts: I am working on a smart device using esp-01 to pull data from internet and display on Nokia 5110 LCD display, and send back the resistive touch inputs to my server and display those on my lcd I am using an Arduino UNO as a secondary device that talks to esp-01, my display and the resistive touch panel. As the esp-01 has got a system on chip, I can program it and do most of the thing my UNO is doing, but because of lack of ports I am using UNO (as far as i know that's the only limitation.. I dont exactly know how is the analog pins on UNO different from the gpio pins on esp) is there any ways if I can do the whole task using only my esp-01 by eliminating UNO. If its only about the less gpio pins on esp-01, will I be able to eliminate UNO by using higher esp such as esp-07 or esp-12E? if not, could you suggest a best way of bi-directional communication between esp and UNO? (so that esp can sent the display info to uno and based on that info, uno can send the resistive touch inputs to esp)


texts: Im currently working on a project where i build an NFC device and needed some guidance in regards to the library needed for the NFC chip to work on the Arduino IDE. The chip is an M24SR64 chip and i've looked online for the library related to the chip but i couldn't find it. Although i did found a library for the M24SR64-y chip, though i'm not sure if its possible to use it, or whether it will work. If anyone has an idea or any help it would be much appreciated


texts:
I have read multiple posts on how to reset the sparkfun pro-micro when it gets stuck during upload, and this seems to work to get it back to a state where I can upload new code again - However, I am here to ask if it is possible that it is something in my code that is causing this issue?
The reason I suspect it is my code is because I have tried:

Different pro micro
Different USB cable
Downloaded latest IDE
Downloaded latest AVR boards package
Tried reverting back to an older AVR boards package as suggested in a different post

Not sure if this is a coincidence, but when I upload a simple blink sketch I don't have any trouble, but as soon as I upload my code (below), it gets stuck on uploading...
I can get it to eventually upload after many attempts using the reset during upload trick, but it seems to be unstable. I say unstable because sometimes it will print out the values requested, and other times it will print nothing...

int clampVal = 0;

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

void ClampReading()
{
    const int numRead = 400; //amount of calibration values we will average
    double vals[numRead];      // the readings from the analog input
    int readIndex2 = 0;                 // the index of the current reading
    double total2 = 0;                  // the running total
    int calibration2 = 0;               // calibration incrementer

    for (int thisReading2 = 0; thisReading2 < numRead; thisReading2++) {
    vals[thisReading2] = 0;
    }
    while(calibration2<numRead)
    {
      int rawClamp = analogRead(A0);
      total2 = total2 - vals[readIndex2];
      vals[readIndex2] = rawClamp;
      total2 = total2 + vals[readIndex2];
      readIndex2 = readIndex2 + 1;
      if (readIndex2 >= numRead) {
        readIndex2 = 0;
     }
      clampVal = total2 / numRead;
      calibration2++;
    }

}

void loop() {
 ClampReading();
 Serial.println(clampVal);
}

EDIT:
Once I reset and upload an EMPTY sketch, I can upload the empty sketch with no problems. I did it 5 times in a row with no issues. Then tried to upload the code above once, and it worked..but then tried to upload second time, and stuck in uploading again... it has to be the code, but I can't narrow down what it is.


texts: Arduino continually resets when connected to external power supply, but not USB

texts:
I'm working on a seemingly simple Arduino project which plays a sound and flashes an LED when provoked by some trigger.

The problem:

When powered by an external power supply, the Arduino continually resets after playing ~1/4 seconds of audio. When powered from USB, it works fine (however the LED, being powered from the external power supply, of course does not work here).

Wiring diagram:

Parts list:

Arduino Pro Mini 5V
Adafruit MAX98306 3.7W amplifier
Sparkfun FemtoBuck LED Driver
4 Ohm 3W speakers
3W LED

I am using a 9V 1A power supply. Again, when no speakers are connected, the Arduino and LED work as intended. It's only when a speaker is connected that the board resets over and over again. Playing roughly 1/4 of a second of audio and then resetting implies to me that there's insufficient current, however, the problem persists even after using a 2.5A power supply.

Things I have tried:

Increasing the power supply to 12V 2.5A
Desoldering the LED driver (even with the LED driver removed, the board still resets)
Checking continuity and staring at the wiring for long periods of time while scratching my head

Overall, I'm at a loss as to why it would work when powered via USB instead of through my external power supply.

What am I doing wrong? Any insights are greatly appreciated!


texts: WS2812B only works while I measure the voltage

texts:
I'm going crazy, there is clearly something I'm missing here.
I have a NodeMCU V3.0 and a 5V LED strip WS2812B with 10 diodes.
I tested this first with a 5V 0.3A power supply, only powering 3 diodes, this worked fine.

Than I changed the power supply to a 5V 2A (Measured to 5.2V) and now the colours are way off, they even change everytime its updating, even though nothing is changed. I put my voltmeter across "D3" and "GND" and suddently the LEDs were perfect and stable.

If I remove it again, the LEDs change to random colours again, I tried pulling "D3" to ground with a 10 kOhm resistor, but this doesn't change anything.

What is going on here, why isn't it working, and why does it work with the voltmeter?

Code:

#include <ESP8266WiFi.h>
#include <FastLED.h>

#define LED_PIN     3
#define NUM_LEDS    10

CRGB leds[NUM_LEDS];
int R = 255;
int G = 90;
int B = 10;

//Set up MQTT and WiFi clients
WiFiClient client;

void setup()
{
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Serial.begin(9600);

  //Connect to WiFi
  Serial.print("\n\nConnecting Wifi... ");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
  Serial.println("OK!");
  pinMode(D4, OUTPUT);
  digitalWrite(D4, HIGH);
}

void loop()
{
    leds[0] = CRGB(255, 0, 0);
    leds[1] = CRGB(0, 255, 0);
    leds[2] = CRGB(0, 0, 255);
    FastLED.show();
    delay(5000);
}


texts: Adding more storage to microprocessor 3.3v trinket

texts:
Project:
I'm a software guy trying to learn more about hardware so I've decided to do a project that uses a small micro controller which plays short sound clips over a .5w speaker.

The microcontroller I've selected is Adafruits 3v Pro Trinket along with their 2.5w mono amplifier. The microcontroller however does not have much storage that I could put sound clips on. I'm considering buying a micro sd card breakout board but I'm not sure if this would work (or how to even wire it to the microcontroller). I don't necessarily need to be able to remove the storage and I only need ~16mb so does anyone have suggestions on other chips I could get in place of using an SD Card? I've been searching on Adafruit but haven't been able to find anything.

Rational:
I would love to use a larger micro controller with a build in sd card slot but I need to be able to stick this inside a 1.5" diameter tube, so space is tight and hence the small micro controller.

Links to parts:

Microcontroller: https://www.adafruit.com/products/2010
Amp: https://www.adafruit.com/products/2130
Speaker: https://www.adafruit.com/products/1890
SD Breakout: https://www.adafruit.com/products/254


texts: Initialising timer interrupt crashes Mega 2560

texts:
Below is the entirety of my prototype code, the cycling of pin 13 is what I use to confirm the board is restarting. The board resets continually on this implementation of initialising the interrupt. There is no code implemented for the interrupt, simply initialising the interrupt and specifically enabling the Output Compare Interrupt by setting its bit high is enough to cause the crash. The evidence of the crash is the onboard LED cycling as instructed in the setup() routine.
I have tried setting OCR3A in one and two operations, I have tried initialising TIMSK3 and not, I have tried intialising TCNT3 to zero and non-zero values, and setting the prescaler with the bit shift and the discrete value, nothing seems to work..
What is going on?
void FlashLED() {
  digitalWrite(13, !digitalRead(13));
  delay(100);
  digitalWrite(13, !digitalRead(13));
  delay(100);
  digitalWrite(13, !digitalRead(13));
  delay(100);
  digitalWrite(13, !digitalRead(13));
  delay(100);
}

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

  // Initialise timer 3 and interrupt
  noInterrupts();
  TCCR3A = 0;
  TCCR3B = 0;
  TIMSK3 = 0;
  TCNT3 = 0;

  // Initialise OCR3A in two operations, as OCR3A = 62500; Serial.print(OCR3A); yields 36 (low byte only)
  unsigned int count = 62500;
  OCR3AH = count >> 8;
  OCR3AL = count;
  TCCR3B |= 1 << WGM32; // CTC Mode
  //TCCR3B |= 4; // Prescaler 256
  TCCR3B |= 1 << CS32; // Prescaler 256

  TIMSK3 |= 1 << OCIE3A; // Output Compare Interrupt Enable
  interrupts();
}

void loop() {
  // put your main code here, to run repeatedly:

}

Update:
I had also been trying with an empty ISR handler and discounted its effect:
ISR(Timer3_COMPA_vect) {

}

However, as the astute viewer would notice, the signature is incorrect in its capitalisation. The correct handler is
ISR(TIMER3_COMPA_vect) {

}

This has resolved the issue.


texts:
I built this circuit to learn button control.

But my code (or button) is working in reverse. I want to initialize led flash effect when the button is pressed with this code

buttonState = digitalRead(8);
if (buttonState == HIGH)
  doFlash();

Instead the effect runs continuously and pauses if I push and hold the button. If change the condition as if (buttonState == LOW) code is working as expected. (Effect starts when I push the button.)

This is just the opposite of what I read in tutorials. What is wrong in my circuit or code?

Full code:

 void setup(){
  for(int i=2;i<=6;i++)
  pinMode(i,OUTPUT);
  pinMode(8,INPUT_PULLUP);
 }

 void loop(){
  int buttonState;

  buttonState = digitalRead(8);
  if (buttonState == LOW)
    doFlash();
 }

void doFlash() {
    int i;
    for (i=2;i<=6;i++) {
        digitalWrite(i,HIGH);
        delay(100);
        digitalWrite(i,LOW);
    }
    for (i=6;i>=2;i--) {
        digitalWrite(i,HIGH);
        delay(100);
        digitalWrite(i,LOW);
    }
}


texts: Problem connecting 2 74HC595 8 bit shift registers in cascading connection

texts:
I have now successfully learned how to control a single 8 bit shift register 74HC595 with Arduino UNO but whenever I tried to connect another one with the first shift resistor via cascading connection just like the image shown below (well I didn't use the 10uf capacitor between positive and negative terminal), the first shift register only outputs as desired but the second shift register, connected to a cascading connection, does not seem to work...

Here is the code.
    int latchPin = 10;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 11;  // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 9;    // Data pin of 74HC595 is connected to Digital pin 4

byte leds = 0;      // Variable to hold the pattern of which LEDs are currently turned on or off

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
}

/*
 * loop() - this function runs over and over again
 */
void loop()
{
  leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
  updateShiftRegister();
  delay(500);
  for (int i = 0; i <= 16; i++) // Turn all the LEDs ON one by one.
  {
    bitSet(leds, i);        // Set the bit that controls that LED in the variable 'leds'
    updateShiftRegister();
    delay(500);
  }

 /* The loop above should repeated 16 times as there are 2 shift resistors, each of them containing 8 and we need to lit up all 16 LEDs*/

}

/*
 * updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
 */
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}

so is it my code or wiring problem?
I have read many articles on internet to make myself get it understood but unfortunately, none of the articles satisfied me.
many thanks for giving me a bit of your precious time...


texts: Update Variable via Arduino to Arduino I2C

texts:
I am attempting to send a simple 1 byte value from one arduino to another using I2C with the Wire library. From reading I see that this is typically done using the event monitor supplied by the Wire library, but this has caused problems for me because the handler function may only have one argument and it must be a void function or else the library throws errors during compilation. So I have a couple of questions about what is or is not possible with the Wire library short of modifying the source:

Should the Wire.available() function respond to attempted transmissions if the event handler referenced above does not exist? My first idea was to simply write my own function that would be called whenever this value is not 0, but it appears that this value never changes - unless the event handler is used.
Can you update variables which reside outside of a function from inside of the function WITHOUT passing those variables as pointer arguments? Because recall from above that I cannot pass any arguments besides the one specified for the number of bytes received.

I cannot understand how this library could be useful for Arduino to Arduino communication if it is literally not possible to use the transmitted values anywhere other than inside of the event handler. My next step is start modifying the source to suit my needs, but I would imagine what I'm describing is a basic thing and would be shocked to find out that it's not possible without modification.


texts: Problems with passing objects in tree structure

texts:
I'm new to C++ and arduino. I want to build an object Tree, but it did not behave like I expected. Here is the code:

TreeNode.h

class TreeNode {

  public:
    TreeNode(String inputNodeName);
    TreeNode *children[];
    TreeNode &getChild(int index);
    int getLength();
    String nodeName;
    void addChild(TreeNode &node);
    String getName();

  private:
    int childLength;
};

TreeNode.cpp

  TreeNode::TreeNode(String inputNodeName) {
    nodeName = inputNodeName;
    childLength = 0;
  }

  TreeNode &TreeNode::getChild(int index) {
    return *children[index];
  }

  int TreeNode::getLength() {
    return childLength;
  }

  String TreeNode::getName(){
    return nodeName.c_str();
  }

  void TreeNode::addChild(TreeNode &node) {
    children[childLength] = &node;
    childLength++;
  }

I'm initialising it in the setup function:

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

    TreeNode mainTree("main");
    TreeNode firstChild("first child");
    TreeNode secondChild("second child");
    TreeNode subChild("subschild");

    Serial.println(mainTree.getName()); //prints "main"
    Serial.println(firstChild.getName()); //prints "first child";
    Serial.println(secondChild.getName()); //prints second child";

    mainTree.addChild(firstChild);
    mainTree.addChild(secondChild);
    Serial.println(mainTree.getName()); // prints an empty string
    Serial.println(secondChild.getName()); //prints second child"

    secondChild.addChild(subChild);
    Serial.println(secondChild.getName()); //prints an empty string
}

So my problem is, when I'm adding a child to a node, the node name is empty, or strange characters will be displayed.
I think I misunderstood passing an object by reference. Can anybody explain what I did wrong?


texts: Modifying serial message for Adafruit NFC/RFID card

texts:
Using an Uno configured with an Adafruit RFID-NFC shield to send the UID values to a desktop game I am building.

Works fine. However, in addition to just the UID, I need to send 1 additional value, lets call it 'game choice'. This can be one of 3 values. This is just the relevant code. Can any experts suggest how I might modify the following to send this additional value?

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

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("init");
}
void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  int nfcDEC;
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {

   nfc.PrintHex(uid, uidLength );
}
}


texts: I am using a Arduino Uno 3 for line follower robot. However when I power the Arduino Uno, the L led is turned on and is never turned off. After a bit of searching I found out that the L LED is connected to pin 13. So I set the pin 13 to low but still the led is on. Is there a problem with the arduino? Or there's something that I am unaware about? (Amongst a lot of other things that I don't know.)


texts: Can I power my Arduino Uno with a 9V / 990mAh battery?

texts:
I have a 9V Lion 990mAh battery. I am not sure if I can use it to power an Arduino externally?

Can you please guide me how to understand current specifications of any device?

Thanks and Regards,
Manish


texts: How to write a more compact ANDed conditions with if statement?

texts:
I'm working on the rfid module and found an example that do it well. But it has a long testing the 5 bytes of the rfid received bytes, and I've tried to write it in a more compact way.

I did it with a for loop, but how to AND the conditions of the if statement?

How to change this:

if(bt0[cnt-1] == rfid.serNum[0] &&
   bt1[cnt-1] == rfid.serNum[1] &&
   bt2[cnt-1] == rfid.serNum[2] &&
   bt3[cnt-1] == rfid.serNum[3] &&
   bt4[cnt-1] == rfid.serNum[4]){
   lcd.clear();
   lcd.print("card accepted");
   digitalWrite(green_led,HIGH);
   digitalWrite(red_led,LOW);
 }
 else{
    lcd.clear();
    lcd.print("card denied");
    digitalWrite(green_led,LOW);
    digitalWrite(red_led,HIGH);
}

To something like this:

    for(byte i=0;i<MXCD;i++){
      if(bt[i] == rfid.serNum[i%5]){
        cnt++;
      }
    }
    if(cnt==5){
      lcd.clear();
      lcd.print("card accepted");
      digitalWrite(green_led,HIGH);
      digitalWrite(red_led,LOW);
      cnt = 0;
    }
    else{
      lcd.clear();
      lcd.print("card denied");
      digitalWrite(green_led,LOW);
      digitalWrite(red_led,HIGH);
      cnt = 0;
    }

In this way, I did it with 'cnt' variable to count the number of successful matched bytes then test of the number is equal to 5.

Is there a better way than this one ?

Thanks for any comments or suggestions :)


texts:
I am thinking about buying a gps module for Arduino UNO.

I would like to install it on a self-build RC-car which is also controlled by Arduino.
The problem is, I cannot install the gps module on the top of the car (on the surface), only the bottom and or/middle space is "free".
My questions are:

1)Is there a module which can overcome a small layer of steel (max 2cm thick) and some plastic and still get a good signal?

2)It would be nice to be able to store the data into a memory card.

3)It would be a great plus to be able to gather data real-time through some kind of connection. Sadly I do not know how to do here. Is there some place where I can look up any of this?

Do you think that this http://www.adafruit.com/products/1272 is what I need?

thank you


texts: AT command is not responding on serial monitor

texts:
I am trying to send AT commands to ESP8266. I re-flashed ESP8266 http://imgur.com/a/J8Ueh I followed this tutorial http://remotexy.com/en/help/esp8266-firmware-update/ and I hope it re-flashed successfully as there was no error.

When I uploaded this program http://www.pastebin.com/frhZY7tD I am trying to run AT command at 9600 baud rate on serial monitor then no response..

Below is how my circuit looks like

#include "SoftwareSerial.h"

SoftwareSerial esp8266(2, 3); // RX, TX

void setup()
{
  Serial.begin(9600); // serial port used for debugging
  esp8266.begin(9600);  // your ESP's baud rate might be different
}

void loop()
{
  if(esp8266.available())  // check if the ESP is sending a message
  {
    while(esp8266.available())
    {
      char c = esp8266.read();  // read the next character.

      Serial.write(c);  // writes data to the serial monitor
    }
  }

  if(Serial.available())
  {
    delay(10);  // wait to let all the input command in the serial buffer
    // read the input command in a string
    String cmd = "";
    while(Serial.available())
    {
      cmd += (char)Serial.read();
    }
    // send to the esp8266
    esp8266.println(cmd);
  }
}

Trying to execute AT command -

On clicking on send button then it shows empty response like below -

When I unplug power wire and plug it back then it prints some garbled message on serial monitor. I checked voltage on RX also, it was around 3.5V that seems also OK.

I am facing this issue after I flashed WiFi firmware to ESP8266 then back AT firmware. It seems that AT firmware was not flashed successfully so I tried to erase everything using below command.

  esptool.py --port /dev/ttyUSB0 erase_flash

C:\Users\williams>esptool.py --port COM4 -b 9600 erase_flash
esptool.py v1.3
Connecting...................

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for pack
et header

Before execute above command, I made changes in my circuit like below :-

Update

I have re-flashed ESP8266 on 115200 baud rate, and uploaded empty program then it started to respond AT commands. I connected as like above only change is TX to TX and RX to RX respectively. Alright!

AT

OK
AT

OK
AT+GMR

AT version:0.50.0.0(Sep 18 2015 20:55:38)
SDK version:1.4.0
compile time:Sep 18 2015 21:46:52
OK

Well, I want to send AT commands from the Arduino serial monitor window to ESP8266 and print ESP8266 response to the command. When I upload above program then it stops to respond, same result as like empty screen this is weird. Isn't ?


texts:
Are there interrupt Pin in the GY91 Module?
If not, are there good alternative for periodic sensor reading?
(apart from mcu schedule/external timer)


texts: Arduino + SIM808: How to get only the JSON object response without the header?

texts:
I have been successfully getting the response from my web server. The problem is I get the whole package with header and content/body:

Recv: 325 bytes: HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Wed, 02 Aug 2017 03:26:37 GMT
Connection: close
Content-Length: 18

1501644397698.2585

I want to only assign this 1501644397698.2585 to my double variable. How can I do this?

This is the code which sends and prints the response:

Serial.println("waiting to fetch...");
sim808.send(http_cmd, sizeof(http_cmd)-1);
while (true) {
  int ret = sim808.recv(buffer, sizeof(buffer)-1);
  if (ret <= 0) {
    Serial.println("fetch over...");
    break;
  }
  buffer[ret] = '\0';
  Serial.print("Recv: ");
  Serial.print(ret);
  Serial.print(" bytes: ");
  Serial.println(buffer);
  break;
}


texts:
I need to output a serial message on a 500 microsecond interval (10 bytes), can be a little slower but no more than 1 milisecond between messages.

Can it be done with an Arduino? I know there is a delayMicro(), but not sure if it has the resolution.


texts: Can only write 5V or 0V, not something in between

texts:
I'm working on a bigger project, and needs to give out a voltages between 0 and 5V. I've written this code:

int ledPin = 12;      // LED connected to digital pin

void setup(){
pinMode(ledPin, OUTPUT);   // sets the pin as output
}

void loop(){
analogWrite(ledPin, 255);
delay(2000);
analogWrite(ledPin, 0);
delay(2000);
analogWrite(ledPin, 127);
delay(2000);
analogWrite(ledPin, 128);
delay(2000);
}

If I've understood it right, this should first give about 5V, then 0V, then 2.5V and againg 2.5V. However my voltmeter only reads 5V and 0V, 2 seconds at each. I've attached my voltmeter to pin 12 and ground. The arduino board is also grounded.


texts: Why Can't I Program my Atmega168 Pro Mini?

texts:
I'm trying to program a Atmega168 Pro Mini 3.3V/8mhz I bought online. I followed a tutorial that walks through the steps of how to program a Pro Mini with an Arduino Uno. However, in their example they are uploading code to a Atmega328 Pro Mini though I don't think it matters.
Anyway, I followed the same steps as they did (namely hooking up Uno's ground -> ground, 3v -> Vcc, Reset -> DTR, tx->tx, rx->rx). When I attempted to upload via Arduino IDE I got the message that the programmer was not responding. I also noticed that the transfer led on the Uno was not lighting up. Did I screw up something? Also, are my hookups correct? I would think tx pin should connect to rx pin, but I just followed the instructions. Would appreciate any thoughts


texts: Analog read negative voltage inbuilt protection

texts:
I'm trying to read a -10 to +10V analog signal on my Arduino Mega (2560). I've been using a voltage divider to obtain a -5V to +5V signal (with two 10kOhm resistors), which used to work just fine.
I'm wondering if this -5V signal can damage the Analog Input pins of the Mega ?

Thank you in advance for your time !


texts: Uno doesn’t get enough power from 5v barrel connector. Why?

texts:
I’m using a 5v 20a power supply run through a barrel connector into an Arduino Uno to control an LED strip. When only the barrel is connected, the green light on the Uno comes on but the yellow light lights dimly for a few milliseconds then goes dark. The light strip doesn’t light at all. When a USB is also connected, the board lights up fully (green and yellow LED) and the LED strip runs through its routine.
I’m making this as Christmas lights on a tree outside so I want it to run on the stand alone power supply. Why doesn’t the barrel work on 5v?


texts: APDS-9960 detected but not showing output on serial monitor

texts:
I just bought an APDS-9960 sensor yesterday and tried it out today using Sparkfun's example from its APDS-9960 lib, and the only thing it printed out was:
"SparkFun APDS-9960 - ProximitySensor" twice then it didn't show any output
Using an Arduino Uno, and wires are connected correctly:
APDS :  Arduino Uno
VCC  :  3.3V
GND  :  GND
SDA  :  A4
SCL  :  SCL
INT  :  D2
I've also tried I2C scanning, and the device address was shown, but SparkFun's example code just didn't work at all.

Using PCB terminals because another sensor will also be integrated into the Arduino Uno.

Code:
/****************************************************************
...
****************************************************************/

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint8_t proximity_data = 0;

void setup() {

  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
  Serial.println(F("------------------------------------"));
  Serial.println(F("SparkFun APDS-9960 - ProximitySensor"));
  Serial.println(F("------------------------------------"));

  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }

  // Adjust the Proximity sensor gain
  if ( !apds.setProximityGain(PGAIN_2X) ) {
    Serial.println(F("Something went wrong trying to set PGAIN"));
  }

  // Start running the APDS-9960 proximity sensor (no interrupts)
  if ( apds.enableProximitySensor(false) ) {
    Serial.println(F("Proximity sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during sensor init!"));
  }
}

void loop() {

  // Read the proximity value
  if ( !apds.readProximity(proximity_data) ) {
    Serial.println("Error reading proximity value");
  } else {
    Serial.print("Proximity: ");
    Serial.println(proximity_data);
  }

  // Wait 250 ms before next reading
  delay(250);
}

I've tried putting delay(100); below Serial.begin(9600); as suggested here: https://learn.sparkfun.com/tutorials/apds-9960-rgb-and-gesture-sensor-hookup-guide/discuss and it did not help.
Any help is appreciated!


texts: Max double value or NAN as a sentinel value?

texts:
I am in need of a sentinel value to use to assign to a double variable initially.
0 or -1 won't work because these values are valid values in my computation and I need a value that will stand out.

Possible choices are:

Maximum double value
Minimum double value
NAN (I would also need a method to check is_nan as well)

How can I accomplish this in the Arduino language?


texts: Program an Arduino Uno with an Atmel ICE

texts:
When I connected my atmel ice to my arduino uno everything went okay.
Then I tried debugWIRE and since then I can't connect to my ATMEGA328p.
I get the error
Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool)
I think one of the fuse bits is wrong but can't connect to the ATMEGA328p to change them. Does anyone have a idea what to do?


texts:
I would like to use the IR remote with Arduino to turn on a LED and turn off the same LED when I push on the remote.

That is to say :

If I push on 1 I would like the LED turn on
If I push on 2 I would like the LED turn off

Here is my code :

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

const int L1 = 13;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(L1, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){
        unsigned int value = results.value;
        Serial.println(value);
        irrecv.resume();
        if(value == 12495){
        digitalWrite(L1, HIGH);
        delay(1000);
        }
        else if(value == 6375){
        digitalWrite(L1, LOW);
        delay(1000);
      }

  }
}

But the problem is when I push on 1 I just see the LED turn on but very quickly the LED turns off then whereas I don't push on the button 2.

Could you help me please?


texts: Stuck in a small confusion about Infrared leds and receivers?

texts:
I have a very simple idea I want to implement. I am making a home automation using an Arduino Uno. I am familiar with Arduino programming but the problem is what kind of IR receiver I need to buy if i want my TV remote (or similar) to communicate with my Arduino.

Can you suggest me any example (low cost, and available in India)?


texts: Does Nano not get sufficient power via USB?

texts:
I have an Uno, and I can play all I want with it, just using a USB cable.

Then I got two Nano clones, and they both show the same behavior:

When I connect it to the USB cable (which leads to my PC) it blinks a few times, then seemingly does nothing. I am also not able to connect to it via the Arduino IDE.

If I then connect an external power source to Vin and Gnd, it wakes up and blinks forever, and I am able to connect to it.

Is this just because I got a cheap clone? Or is this really the accepted / expected behavior?


texts: Issue with CD74HC4067 MUX on high values

texts:
I'm having a small issue with the CD74HC4067 multiplexer/demultiplexer: I am using it to receive data from an array of sensors (at the moment I have only 2, but in a near future they will grow). Specifically I have a light sensor and a sound sensor.
Mux output is connected to A0 since the readings I do are analog. The pins I use to switch the channels are A3 and A2 (when the other sensors will arrive also A1 will be dedicated to that).
My problem is that when switching between one channel and another, my readings highly fluctuate, but only when the reading value is > 500 or so, and I don't understand why. In a simple sketch I've tried adding some delay (40 msec) and the issue goes away. But in my project which is far more complex and uses also other analog channels I need a delay of ~1 second to get a correct reading, which is absolutely unacceptable since I need it to run in real-time(ish). I also tried using the digital pins to control the mux but to no avail. The only thing that seems to stabilize everything is connecting a capacitor between the MUX out and ground, and using a 20msec delay, but it only works for a bit.
I hope I've been clear enough and that someone can point me the right way!
EDIT:
Here is the schematic

(Error in the drawing: "temp" is actually a "light sensor" as in the bottom of the post...)
And my code:
#define MUX A0
#define S0 A2
#define S1 A3

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

  selectMux(1);
}

void loop() {

  //selectMux(0);
  //Serial.println(analogRead(MUX));
  //selectMux(1);
  Serial.println(analogRead(MUX));

}

void selectMux(byte port) {
//  pinMode(MUX, mode);
  int r0 = bitRead(port, 0);
  int r1 = bitRead(port, 1);

  digitalWrite(S0, r0);
  digitalWrite(S1, r1);
  analogRead(MUX);
}

the analogRead(MUX) in the selectMux function was added because I read in a post that they suggested to do that in order to get a more accurate reading.
With this code only the results already fluctuate:
Output:
76
41
77
76
76
75
36
75
74
76
77
106
76
76
76
76

but it goes crazy when the input is higher, close to 5V:
Output:
948
780
340
948
948
635
437
949
948
499
551
949
950
396
684
950

If you enable the commented code that starts to switch the outputs it is even worse. As I said, adding delays helps, but in my final application I cannot afford to have 1s delays.
I also show that in the circuit there is a timer that uses other Analog pins, but in the code I didn't include that part. If you need I'll add that too.
Sound Sensor,
Light Sensor


texts: How to connect LED lights for 3D Printed Robot

texts:
I'm new here and a newbie in electronics. I have a project to create a 3d printed robot with lights. I came across neopixels led's and the ardruino microcontrollers recently and find it to be a great possible sollution for what I need.

For my project, the 3d printed toy will have several parts that would need lights and I plan to use roughly over 40 LEDs connected to one source. I' m thinking of using the WS2812B LEDs.

I plan to use one neopixel ring for the robot's chest similar to Iron-Man's arch reactor.. While the head head will have 2x LEDs for the eyes, a smaller neopixel ring for the headpiece, another 2x LEDs for on the side of the robot mouth and 3x LEDs inside each vents on both sides of the robots head.

I need all the LEDs to turn on with a white light with a switch and turn red with another button. Although, I'd still be happy if they can only work with white.

For the power source, I was thinking about using a small powerbank or 2x 18650 batteries as the power source.

As mentioned, I'm very new to electronics and based on my research so far, i get confused really fast from all the jargons used and I'm not sure how to proceed.

Hopefully, i can get some answers here.

So.... My question is, is it possible to connect all the LEDs i plan to use on one microcontroller (ie: Ardruino Uno or Nano)

Most of the examples I can see on youtube are projects using LED strips. Are they diffrences in the way they are connected?

Another problem is coding for the ardruino..i'm totally clueless.

Any suggestions or help would be very much appreciated.


texts: How do I program my Arduino Yun Shield when I keep getting this AVRDUDE error message?

texts:
The error message is:

  avrdude: AVR device initialized and ready to accept instructions
  avrdude: Device signature = 0x1e950f
  avrdude: Expected signature for ATmega32U4 is 1E 95 87
  Double check chip, or use -F to override this check.

This error message is thrown when I attempt to upload any program to the Yun shield through an Arduino Bridge between the Uno and Yun shield with the Uno’s ATMega32 shorted into reset mode.
Any advice on how to get this working? Thanks.


texts: Assembling a float from an array of bytes

texts:
I would like to convert an array of bytes, received from serial, to a float.

Let's consider this exemple. I'm sending 0.12 byte-wise from an Android application. The conversion from float to array of bytes in the Android side is handled by this function

public static byte [] float2Bytes(float value)
    {
        return ByteBuffer.allocate(4)./*order(ByteOrder.LITTLE_ENDIAN).*/putFloat(value).array();
    }

When bytes arrive, they are stored in an array and the assembled.

hiBytew1 = bufferBytes[9];
//Serial.println(hiBytew1);
loBytew1 = bufferBytes[10];
//Serial.println(loBytew1);
hiBytew2 = bufferBytes[11];
//Serial.println(hiBytew2);
loBytew2 = bufferBytes[12];
//Serial.println(loBytew2);
float conAck = assemble(hiBytew1, loBytew1, hiBytew2,loBytew2);

How can I achieve this kind of conversion assuming that bytes are received in the correct order?


texts: Getting a Wemos D1 Mini to work with a M1 Mac

texts: The Wemos D1 mini won't show up on the new M1 Mac. I know it's related to the drivers but I just can't find a viable solution to the problem. Has anyone solved this?


texts: Differences between nodemcu and arduino processer

texts:
I have an arduino Uno and nodemcu development board.

I have an OV7076 camera and used with arduino UNO. It worked flawlessly with it and the code used is provided in the [Instructables tutorial][2] named as FromComputerNerd.ino.

Now i want to use it with Nodemcu. Whereas Nodemcu have a single Analog input but OV7076 uses two analog inputs [shown in][2]. So to get it I am trying to use Multiplexer. I can change the code so that it would adjust for analog pins.

But will the code be compatible with Nodemcu. Since it was written for arduino uno.If not, What changes can be done to make it compatible?

http://www.instructables.com/id/OV7670-Without-FIFO-Very-Simple-Framecapture-With-/


texts: How to disable the write protection of the USART mode register?

texts:
I have a device which transmits USART with inverted polarity, and I would like to read data from it with the help of an Arduino. I use an Arduino Due, which has a SAM3X processor, so it should be able to invert the polarity without any external hardware.

The settings accessible from the Arduino SDK are minimalistic, Serial.begin() only allows to set the baudrate and start/parity/stop, nothing else.

In the SAM3X datasheet I found the "USART Mode Register", US_MR, which dedicates bit 23 (INVDATA) to invert the polarity.

Although it seems not to be documented anywhere, I found in a forum that to access the US_MR register, I have to use UART->UART_MR. I can read that register but cannot change it. The SAM3X datasheet mentions that this register might be write protected, and that the write protection can be cleared in the US_WPMR register.

However, the Arduino SDK doesn't seem to know about this register. I tried several possibilities,

US_WPMR
UART_WPMR
WPMR
UART->US_WPMR
UART->UART_WPMR
UART->WPMR

None of which are known.

The string WPMR is nowhere to be found in any of the files in my Arduino installation folder.

EDIT:

Interestingly, the source code for the UART class doesn't contain any reference to the WPMR. It just sets the required configuration registers without bothering with it.

void UARTClass::begin( const uint32_t dwBaudRate )
{
  // Configure PMC
  pmc_enable_periph_clk( _dwId ) ;
  // Disable PDC channel
  _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ;
  // Reset and disable receiver and transmitter
  _pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS ;
  // Configure mode
  _pUart->UART_MR = UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL ;
  // Configure baudrate (asynchronous, no oversampling)
  _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4 ;
  // Configure interrupts
  _pUart->UART_IDR = 0xFFFFFFFF;
  _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME;
  // Enable UART interrupt in NVIC
  NVIC_EnableIRQ(_dwIrq);
  // Enable receiver and transmitter
  _pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN ;
}

However, when I try to change UART_MR, it remains the same.


texts:
I am using this code to make 10 bit PWM on port number 9, it seems like everything printed is 0,1022 rather than printing 0, 512, 1023. Is there a problem in my code ?

I wired pin9 to A3 to get the output and print it.

  void setup() {
  Serial.begin(9600);
  pinMode(A3,INPUT);
  // Set PB1/2 as outputs.
  DDRB |= (1 << DDB1) | (1 << DDB2);

  TCCR1A =
      (1 << COM1A1) | (1 << COM1B1) |
      // Fast PWM mode.
      (1 << WGM11);
  TCCR1B =
      // Fast PWM mode.
      (1 << WGM12) | (1 << WGM13) |
      // No clock prescaling (fastest possible
      // freq).
      (1 << CS10);
  OCR1A = 0;
  // Set the counter value that corresponds to
  // full duty cycle. For 15-bit PWM use
  // 0x7fff, etc. A lower value for ICR1 will
  // allow a faster PWM frequency.
  ICR1 = 0x03ff;
}

void loop() {
  // Use OCR1A and OCR1B to control the PWM
  // duty cycle. Duty cycle = OCR1A / ICR1.
  // OCR1A controls PWM on pin 9 (PORTB1).
  // OCR1B controls PWM on pin 10 (PORTB2).
  OCR1A = 0x0000;
  delay(500);
  Serial.println(analogRead(A3));
  OCR1A = 0x0200;
  delay(500);
  Serial.println(analogRead(A3));
  OCR1A = 0x03ff;
  delay(500);
  Serial.println(analogRead(A3));
}

The output looks like that:

  0 0 1022 1021 0 1022 1021 0 0 1021 0 1021 1021 0 0 1021 0 0 1022

no data between 0 and 1022 are presented.

thanks.


texts: Use large variables without using much memory

texts:
I've wired up a dot matrix, and I display characters on the screen by using something like the example code below.

The Char_B variable is a global variable in a library used by the Arduino, and displayPixels() is called from inside the library.

bool Char_B[8][8] = {
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0}
};

displayPixels(1000, Char_B);

However, each time I declare a new character like the array above, I use a relatively massive amount of memory. Is there any way to reduce memory usage? Keep in mind I am willing to change the structure of the array if necessary, since I'll need well over 100 characters loaded onto the Arduino to write text.


texts:
Has anyone got sleep/standby + watchdog to work together on their Arduino Zero or Sparkfun SAMD mini?

I am able to get the WDT to reset the device, and am able to put it to sleep - but can't get the WDT to bring it out of sleep.  Every time I try, it pops right back out of sleep mode again as if SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk was never even called


texts: Is there any particular reason why #pragma once doesn't seem to be used in Arduino code? Is this just because it's not a well-known feature, or is there some overriding reason to use #ifndef XXX_H/#define XXX_H/#endif?


texts: Is there any way I can connect the RAM of a computer to Arduino?

texts:
I was thinking about a way to reuse the RAM of my old computer on my Arduino board. I was thinking about some peojects using neural networks, and more RAM would let the Arduino use more neurons.

So that's my question, how could I do that? Maybe soldering some cables to Tx/Rx pins and creating and interface between the board and the memory?


texts: How to add extra USB port to Arduino Nano?

texts:
I'm trying to use V-USB library to emulate a keyboard using Arduino Nano but because of precaution, I don't want to use it's built-in USB port.

My idea is to add another USB port so I cant power my device with the new USB port and use free digital pins as input/output of the new USB serial port in V-USB project.

What circuit I should use and how to add extra USB port to Arduino Nano.


texts: How to read all avaiable data from a Serial stream and then stop

texts:
I am trying to read data from the Serial port in my Arduino, store it in a buffer and when all the data has been read stop reading and then start using the data (the talkMIDI() function). The Arduino succesfully some bytes from Serial but not all of them and then hangs without stopping before the end.

void loop() {
  if (!stop)
  {
    char in = Serial.read();
    if (in != -1)
    {
      buffer[pos] = in;
      pos++;
      Serial.write("read");
      Serial.print(pos);
      Serial.print("\r\n");
    }
    if (in == 126)
    {
      stop = 1;
      Serial.write("STOP");
    }
  }
  else
  {
    if (cursor < pos)
    {
      talkMIDI (buffer[cursor], buffer[cursor+1], buffer[cursor+2]);
      cursor = cursor+3;
      delay(500);
    }
  }
}

After manually sending a 126 value (~) character, I get a "STOP" response on the Serial line but Arduino doesn't start executing the code from the else branch (the talkMIDI() part -- the function doesn't even get called once).


texts: Function for converting milliseconds to minutes?

texts:
I'm playing around with a Neopixel strip and want to be able to enter the amount of minutes I want an LED to do something rather than in milli seconds. So for example,

void loop() {

colorWipe(strip.Color(0, 0, 255), 50);
delay(sConversion(5));

colorWipe(strip.Color(0, 0, 0), 50);
delay(sConversion(5));

In my mind this should then delay the code by 5 minutes instead of doing

void loop() {
colorWipe(strip.Color(0, 0, 255), 50);

delay(300000);

The function I wrote is

sConversion(int minutes) {
    int milli = minutes * 60000;

    return milli
};

When I write this same function in JS it returns the correct value, 300000. But when I run it in the Arduino IDE the blue light never changes.

I have this function outside my void loop() and void setup(). Is that the correct place to put it? I have no errors returned.

Full code sample

void setup() {

strip.begin();
strip.show();

}

int sConversion(int minutes) {
    int milli = minutes * 60000;

return milli;
}

void loop() {

colorWipe(strip.Color(0, 0, 255), 50); // Blue
delay(sConversion(1));

colorWipe(strip.Color(102, 204, 0), 50); // Green
delay(300000);
}

void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
    };
};

Is this the reason?

  No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt.

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


texts: Is it possible to set the Arduino Yun up as an ssh client? If so, how?


texts:
I would like to use the Radiohead library and control a servo from the same Leonardo board.

Now the Radiohead library occupies timer1 and therefore cant be used together with the servo library. (It does offer to use timer2 which the Leonardo does not have.)

Are there any other Servo libraries that use timer3 or timer4 which the Leonardo has?

I have already tried:

https://github.com/nabontra/ServoTimer2  does not compile
https://www.pjrc.com/teensy/td_libs_TimerOne.html does not work (calling function blocks)


texts: Error: 'SofwareSerial' does not name a type

texts:
I have trouble compiling this sketch. The error I get is

  'SoftwareSerial' does not name a type

Any ideas how could I fix it?

#include SoftwareSerial.h

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

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Ready!");

  // set the data rate for the SoftwareSerial port

  // for HC-05 use 38400 when poerwing with KEY/STATE set to HIGH on power on
  mySerial.begin(9600);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}


texts: Does using multiple HX711 amplifiers change the supply voltage of an Arduino?

texts: I’m creating essentially a load cell using an Arduino Nano and an HX711 amplifier. However, I want to have two HX711 amplifiers running off the same Arduino. Will that change the supply voltage since I’m using two (ex. Does it change from 5V to 2.5V)? I need an accurate supply voltage for the Wheatstone bridge equations to determine strain from the strain gauge readings, but I’m unsure what adding another amplifier will do to the supply voltage.


texts: How to operate under linux an USB to I2C adapter based on the FTDI FT232R?

texts: How can I easily use, from the command line, the USB to I2C adapter based on FTDI FT232R?


texts: My motor works for a while but then stops

texts:
I have a simple motor automatization system. It only uses adapter, arduino, relay and motor nothing else.
It works for 15 seconds and stops for 3 seconds. It works properly for 1 minute but then stops working. When I plug out everything wait for a while and plug again, It starts working and then stop again. Any Idea why?


texts: What's the smallest Arduino board with wifi capabilities?

texts: The Photon from Spark IO looks super small. Are there smaller wifi enabled microcontrollers available that can be programmed with the Arduino IDE?