texts: Button press with Arduino repeated many times

texts:
I have 5V -> button -> 10K resistor -> PIN2 setup with Arduino UNO.

My code is very simple:

int count = 0;

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

void loop() {
  int state = digitalRead(2);
  Serial.println(state);
  if (state == HIGH) {
    count++;
    Serial.print("Hi");
    Serial.println(count);
  }
  delay(1000);
}

If the button is pressed print "HiX", but what I get is very strange. When I press the button only once I get this:

0
0
0
0
0
1
Hi1
1
Hi2
1
Hi3
1
Hi4
1
Hi5
1
Hi6
1
Hi7
1
Hi8
1
Hi9
1
Hi10
0

The button press is registered 10 times.

What am I doing wrong ?


texts: Can you use crystal oscillators to change the frequency of infrared?

texts:
This perhaps is a dumb question and I assume I can but just to be sure. Can I attach a crystal oscillator to my arduino pin and then to the infrared led instead of using registers?
Yes or No?


texts: How can higher current devices (motors, solenoids, lights, etc.) be controlled by an Arduino?

texts:
I'm looking for a broadly applicable solution, one that can be adapted to a variety of projects.

I'm currently working on several projects that each require controlling devices ranging from 800mA to 2A from an Arduino Uno. One controls stepper motors, one controls 12vdc solenoid actuators, and one controls 12vdc pneumatic valves.

For example:

The Arduino monitors a button, and each time the button is pressed it triggers the solenoid actuator. Because the Arduino is unable to source the current required by the solenoid, a seperate power supply is required with the Arduino controlling a switch (relay, transistor, etc.) that allows the higher current to pass. For the stepper motor, the layout is more complex as there would need to be four pins controlling four separate switches (to maintain interoperability of the circuit). The relay controls an air valve and requires 12vdc as well.

I'm trying to figure out how to use a single circuit that can be used in each of these applications (and any future projects) that involve controlling higher current devices than the Arduino pins can handle.

Prototyping speed, standardized components, and low cost are the driving factors. Switching speed, useful life, and noise are also important.

Is there a breakout board, circuit, or component that can be connected to an Arduino pin and used to control a high current device? Ideally with a software controlled potentiometer so that the resistance for different projects could be set in the sketch itself.


texts:
Right now I have the following code for the Arduino SD Library

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

void printDirectory(File dir, int numTabs)
{
  while (true)
  {
    File entry =  dir.openNextFile();
    if (! entry)
    {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++)
    {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory())
    {
      Serial.println(':');
      printDirectory(entry, numTabs + 1);
    }
    else
    {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.print(entry.size(), DEC);
      Serial.println(":");
    }
    entry.close();
  }
}

My hangup is that for file or folder names of 9 or more characters I get back char56~1.TXT How can I get the full name of the files and folders?

Also, What is the best way to, instead of printing to the serial port, only print trees that have a .TXT (or .CSV ) extension?


texts: How to set string in the structure part of NRF24?

texts:
Can anyone help me on how to correct my program ? I want to transmit value in string form.

I put this to TX code

struct payload_t
{

 String sensor1;
};

..................

At the loop part I put this code

String sensor1 = (String(x) + "," + String(y) + "," + String(z)) ;

In the RX part I put this code

 struct payload_t
{

 String sensor1;
};

At the loop part

RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload));

Serial.println("Sensor1 ");

Serial.println(payload.sensor1);

Below is the Attach picture result of RX code.

Thanks in advance :)


texts:
Hi programming in arduino, I am trying to get a nested for loop inside a for loop with industrial servo which used PUL +- DIR+- (bought motor off amazon).

My goal is to get the puls delay to increase. I have a sensor attached that I want the servo to turn on when triggered.

So the sensor will get triggered and the the servo will start off fast and get slower up to 255 micros second delay.

example:

int sensor = 26;
int PUL = 23; //define Pulse pin
int DIR = 25; //define Direction pin

void setup() {
  pinMode(sensor, INPUT);
  Serial.begin(115200);
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);
}

void loop() {
  int sen = digitalRead(sensor);
  if (sen == HIGH) {
    Serial.println("HIGH");
    delay(1000);
     for (int i=0; i<500; i++)
  {
      for( int x=0; x<255; x++){

    digitalWrite(DIR,LOW);
    digitalWrite(PUL,HIGH);
    Serial.print("i = ");
    Serial.println(i);
    Serial.print("x = ");
    Serial.println(x);
    delayMicroseconds(x);
    digitalWrite(PUL,LOW);
    delayMicroseconds(x);
  }}
  } else if (sen == LOW) {
    Serial.println("LOW");
    delay(1000);
    } else {
    Serial.println("ERROR");
  }
}

EDIT

I am trying to nest a FOR loop inside a FOR loop What I want to do is get x to increase with i until x is 255 then I will continue unit i reaches 500. Right now x goes 0-255 and then i increase by 1. I need the value of x to increase along side with i until 255

for (int i=0; i<500; i++) {
  for( int x=0; x<255; x++){
  digitalWrite(DIR,LOW);
  digitalWrite(PUL,HIGH);
  Serial.print("i = ");
  Serial.println(i);
  Serial.print("x = ");
  Serial.println(x);
  delayMicroseconds(x);
  digitalWrite(PUL,LOW);
  delayMicroseconds(x); }
}


texts:
I have just completed my first project, a clone of the Simon game of the eighties. The main parts of the circuit are an ATMega328, a 1602 2x16 LCD, and a small joystick.
It is powered directly from 3x1.5V batteries with solder bridges connecting all power pins on each part directly to the batteries. Therefore, if I sleep the ATMega, it won't change a thing comsumption-wise, as the LCD will still be powered.

What are (my first project, I am very unknowledgeable) the possible strategies to sleep the whole circuit?

I thought of using an ATMega pin as a positive lead for the joystick and LCD. Is that feasible?

Another strategy would be to interface some component (a relay?) between the battery and LCD, and command that component from an ATMega pin. Does someone know the right part for the job (I have a 220V relay in my parts, but it seems overkill)?

Lastly, even though it seems unlikely, is there a possible strategy without using any ATMega pins, as I currently use every single one (4 buttons, 4 leds, joystick x, y, and button, 1 buzzer, and 6 pins for the LCD, for a total of 18) except Rx and Tx?


texts: What would be the Western / American equivalent of the Troyka Shield and modules?

texts:
I'm taking an online course on Arduino robotics, produced by the Moscow Institute of Physics and Technology. The lectures are translated into English, but all of the parts referenced are by the Russian company Amperka.

It seems the key parts I need to follow along are

The Troyka Shield
Troyka modules, like the potentiometer, Hall sensor, etc
Matryoshka Z set

As fun as it would be to order from the Russian store, there are several practical reasons I'd prefer an American (or Western) equivalent. If they even ship to the US, payment would be difficult, shipping slow, instructions in Russian, etc, etc.

I've spent time and money shopping around Adafruit and SparkFun, but as an Arduino beginner, I'm not 100% sure which parts are analogous to these Russian ones. If a more experienced hobbyist recognizes any of these and can help me identify it, that would be most appreciated.

I think the Troyka components are a necessity, but the Matryoshka Z is a "nice to have" bundle of components. I'm using Arduino Uno, so compatibility with that would be preferable, but I think one of his Russian controllers is supposed to be a clone of the Leonardo, so if these parts only work with a Leonardo that's fine too.

The shield is shown here:

In this view it's combined with its modules using this special snap-together PVC:

The instructor said that he helped invent the PVC components, so I guess there may not be an American version of that yet (or is there)?


texts:
Just trying to understand and use the SoftwareSerial

I want to connect a WiFi Module (ESP8266)
If I send an AT command to the module I would like to print a response on my pc screen in the serial monitor

Some example code it tried

   SoftwareSerial dbgSerial(10, 11); // RX, TX
   void setup()
   {
     // Open serial communications and wait for port to open:
     Serial.begin(57600);
     Serial.setTimeout(5000);
     dbgSerial.begin(9600); //can't be faster than 19200 for softserial
     dbgSerial.println("ESP8266 Demo");
     //test if the module is ready
     Serial.println("AT+RST");
     delay(1000);
     if(Serial.find("ready"))
     {
       dbgSerial.println("Module is ready");

I would like to receive ready in the serial


texts: Arduino development vs nRF51 development

texts:
Originally I had an idea to develop an Arduino-compatible project using an ATmega328P, some sensors and the nRF51822 as the BLE radio. As I progressed, I realized that if I relaxed the Arduino-compatible requirement, I could actually do away with the ATmega328P and write the application directly on the nRF51822 as it is a more capable MCU (32-bit, more memory, faster, has SPI, I2C and TTL serial, etc.) I'm not familiar with writing native applications for the nRF51822 but it seems much more complicated.

For someone that has experience in both platforms, can you please list some of the tradeoffs of developing using an ATmega328P for application + nRF51822 for radio and using the nRF51822 for both application and radio?


texts: How do I make a counter that counts the amount of active inputs

texts:
I want to make a direction guide using green, yellow and red LEDs. The lights need to change when ever the active input1 reaches a set value, for example:

Green when the value is lower than 12;
Yellow when the value is higher than 11 and lower than 20;
Red when its higher than 19.

I've been searching for a few days but I couldn't find any references.

1 By active inputs I mean, a series of buttons being pressed at the same time, if there is 29 buttons then when less then 12 of them is pressed the green light would be turned on.


texts: Unable to Configure MQTT Client ID using Adafruit MQTT Library

texts:
I am utilizing the MQTT library that Adafruit has created, located here, and the library itself works wonderfully - however I am finding myself unable to edit the Client ID or configure the PINGRESP. The code that I am currently using can be seen below -

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883);

When the client connects to the MQTT Broker the client ID turns into a random string of letters, numbers, and symbols, as seen below -

1534023607: Client ]7llG5K6J4=^tPHJHqgTUFc<Ep^m3vJ`4vSL2oB<cO[^_chw[GBp]v3smagpOqWS has exceeded timeout, disconnecting.
1534023608: New connection from 10.116.7.21 on port 1883.
1534023608: New client connected from 10.116.7.21 as ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (c1, k300).
1534023608: Sending CONNACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (0)
1534023608: Received SUBSCRIBE from ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu
1534023608:     quantity (QoS 0)
1534023608: ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu 0 quantity
1534023608: Sending SUBACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu

After a duration of time has passed the client exceeds the time out and disconnects.. Any advice on overcoming this obstacle would be greatly appreciated. I've tried the following for changing the ClientID, per the client constructor to the MQTT broker -

Adafruit_MQTT_Client(Client *client, const char *server, uint16_t port,
   const char *cid, const char *user, const char *pass):

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883, "Rear-Controller");

This was the result of adding the clientID, ("Rear-Controller"), after the MQTT Broker port # -

 New client connected from 10.116.7.21 as GFONMktFXFSG1rARE@JWCRv@P^XwLifdo<rCg]YFs4Ndf_>2_XIsjFsAtS08Cf\: (c1, k300, uRear-Controller)


texts:
I have strange problem with u8glib library. I have code:

void void_Menu_draw_func_men()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_func_men();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}

void Menu_draw_func_men()
{

  u8g.setFont(u8g_font_6x13);
  u8g.drawStr(30, 0, "Funkcje");
  u8g.drawStr(15, 15, "Zerowanie modulu");
  u8g.drawStr(15, 30, "Modul na max");
  if(menu_pos == 0){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,20);}
  if(menu_pos == 1){u8g.setCursorFont(u8g_font_cursor); u8g.setCursorStyle(144); u8g.enableCursor(); u8g.setCursorPos(10,35);}
  u8g.setPrintPos(5, 50); u8g.print("R:  "); u8g.print(pot_R , 2); u8g.print("   L:  "); u8g.print(pot_L , 2);

  Serial.println("func md");//just for check...

}

And oled display shows only cursor and I can move that cursor as I change menu_pos value. But no letters or values are printed on screen. Only cursor...

If I copy and paste only code from void Menu_draw_func_men(); to other part of my program:

void void_Menu_draw_test_man()
{
  if ( menu_redraw_required != 0 ) {
   u8g.firstPage();
    do  {
     Menu_draw_test_man();
   } while( u8g.nextPage() );
   menu_redraw_required = 0;
  }
}
void Menu_draw_test_man()
{

  u8g.setFont(u8g_font_6x13);   //replace this dwo lines
  u8g.drawStr(0, 0, "wykonywanie tefsdfs man...");

}

Everything works perfect... I was trying to change void name, and I don't know where is problem...
This is on Arduino Uno; I have 66% used of program memory, and 60% used of dynamic memory.
Maybe you have some idea?...


texts:
I am hitting the limits of my arduino's SRAM and found that SRAM usage can be reduced by storing static stuff in flash memory instead of SRAM.

My project can (optionally) be built with an included SimulatorClass. I use this to 'playback' data at home which I gathered during real-life testing of my project. My project is based on photoelectric sensors, and it's timing-critical, so all timekeeping is done using micros(), which returns unsigned long datatype.

To simulate these photoelectric sensor triggers, I need an array containing a struct of 3 variables each:
unsigned int _iDataPos;

   struct SimulatorRecord
   {
      uint8_t iSensorNumber;
      unsigned long lTriggerTime;
      uint8_t iState;
   };

So one these structs is 6 bytes long in my counting (2x uint8_t = 2 bytes, unsigned long = 4 bytes).
A typical set of simulator records I need to use is about 25-30 records long, so worst case scenario the simulator array is 180 bytes in size.

I initialize these arrays like so:

SimulatorRecord SimulatorQueue[28] = {
      { 1, 41708, 1 }
      , { 2, 60692, 1 }
      , { 1, 176848, 0 }
      , { 2, 197732, 0 }
      , { 1, 4675580, 1 }
      , { 2, 4692252, 1 }
      , { 2, 4830180, 0 }
      , { 1, 4849032, 0 }
      , { 2, 9058416, 1 }
      , { 1, 9074780, 1 }
      , { 1, 9215868, 0 }
      , { 2, 9234968, 0 }
      , { 2, 13497276, 1 }
      , { 2, 13500924, 0 }
      , { 2, 13502728, 1 }
      , { 1, 13514992, 1 }
      , { 1, 13668000, 0 }
      , { 1, 13669344, 1 }
      , { 1, 13681828, 0 }
      , { 2, 13701464, 0 }
      , { 2, 18028788, 1 }
      , { 2, 18034252, 0 }
      , { 2, 18036540, 1 }
      , { 1, 18046892, 1 }
      , { 2, 18160312, 0 }
      , { 1, 18178224, 0 }
      , { 1, 20454580, 1 }
      , { 1, 20456368, 0 }
   };

In my simulator code I then loop through these arrays like so:

   unsigned int _iDataPos = 0;
   SimulatorRecord PendingRecord = SimulatorQueue[_iDataPos];

   //main simulator loop
   if (PendingRecord.lTriggerTime <= lRaceElapsedTime)
   {
      //simulate signal
      digitalWrite(PendingRecord.iSensorNumber, PendingRecord.iState);

      //And increase pending record
      _iDataPos++;
      PendingRecord = SimulatorQueue[_iDataPos];
   }

Now I've been reading various PROGMEM tutorials, and storing the SimulatorQueue array in flash seems to be piece of cake, just change

SimulatorRecord SimulatorQueue[28]

to

const PROGMEM SimulatorRecord SimulatorQueue[28]

But for the life of me I can't find out how I should change the copying of each array item to the PendingRecord variable, as my iDataPos counter increases.

Edit: I should have mentioned that this simulator class and all it's member functions & variables reside in a seperate *.cpp and *.h file.
I alreadt found out that since i'm initializing the SimulatorQueue array in the class itself, and not in the main *.ino file, I should do it like so:

constexpr static SimulatorRecord SimulatorQueue[28] PROGMEM = {<structs go in here>};

Edit2: Sample code which reproduces the problem when the simulator array is available here:
http://1drv.ms/1TRwiIB


texts: Can I read using an analog pin on an arduino Mega whether or not there is a high (5v) voltage on a wire from another board's digital pin?

texts:
I am making a peer-to-peer network of initiating devices and a common hub, which controls most of the hardware. It sends a number over Serial to Mega's Serial1 (Mega's Serial is used for communicating to the computer), but as a fallback it initiates a general alarm by sending a 5v signal (using digitalWrite(pin, HIGH)) to the main board. In order to complete the circuit and get the read, how would I do this?

Thanks!


texts: UART communication issue on Arduino Mega

texts:
I am using an MH-Z19 CO2 sensor with an Arduino Mega using UART. As per the specifications of this sensor, after we send a command, we expect the response in a particular 9 byte format (with starting bytes as 0xFF and 0x86).

byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
byte response[9];
Serial.flush();
Serial.write(cmd,9);
while (Serial.available()<9) {}
for(int n=0; n<9; n++) {
  response[n] = Serial.read();
}
if (response[0] != 0xFF) {
  //Error
  predictCo2 = 0;
} else if (response[1] != 0x86) {
  //Error
  predictCo2 = 1;
} else {
  predictCo2=((response[2]*256)+response[3]);
}

I wait till all the 9 bytes are filled in to read the values.

The problem here is that, when I turn the board ON, most of the times the response isn't in the required format (starting bytes aren't 0xFF or 0x86).
But, if I press the Arduino reset button, it starts reading values in proper format straight away.

I'm wondering why this is happening. Why is the UART response not in the proper format immediately after I turn on the Arduino, and I have to explicitly do a reset? Is the reset button clearing the serial stream? How can this be achieved through software?

I included serial.flush() before sending the command, but that didn't help either.


texts:
I am getting this error from the Visual Studio compiler (I use the Visual Studio add-in Visual Micro for Arduino).

  ModelRailroadCrossingSignalController.ino:In function 'void loop()
  ModelRailroadCrossingSignalController.ino:210:15: error: too few arguments to function 'Adafruit_VS1053_FilePlayer onSignalSound(Adafruit_VS1053_FilePlayer, const char*)
  :onSignalSound()
  ModelRailroadCrossingSignalController.ino:note  declared here
  :Adafruit_VS1053_FilePlayer onSignalSound(Adafruit_VS1053_FilePlayer mp, const char* fileName) {
  Error compiling project sources

Here is the function and loop (all the defines and instances left out for brevity, they aren't the issue

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

signalEntrySensor = checkEntrySensor();
if (signalEntrySensor == true) {
    if (crossingSignalInOperation == false)
    {
        Adafruit_VS1053_FilePlayer mp = onSignalSound(musicPlayer,"Trainxng.mp3");  //all other functions are called in the sound routine?
        if (debugMode)
        {
            Serial.println("Sound byte called");
        }
        while (mp.playingMusic) {
            // file is now playing in the 'background' so now's a good time
            // to do something else
            offRoadPower();
            lowerSignalArms();
            onSignalSound();
            startSignalFlashers();
            crossingSignalInOperation = true;
        }
    }
}

Adafruit_VS1053_FilePlayer onSignalSound(Adafruit_VS1053_FilePlayer mp, const char* fileName) {
// Play the train crossing sound file
if (debugMode)
{
    Serial.println(F("Playing track - "));
    Serial.print(fileName);
}
//all sound files are on the micro sd card on the music player shield
if (!mp.startPlayingFile(fileName)) {
    Serial.println(F("Could not open file "));
    Serial.print(fileName);
    while (1);
}
return mp;  }

I'm a C# guy, not ever using C++ until now, but this code should certainly work, not sure why the function is not compiling.


texts: why is memcpy of unsigned long killing my sampling speed?

texts:
I'm using a Mega 2560 to communicate with a mixture of analog (i.e. measured via analogRead()) and I2C based sensors. Sampled data is placed in a 16 byte array, then written to an SD card once a 512 byte buffer is completely filled. The problem I'm running into is that when I collect data from a MAX30102 pulse oximeter using

measure.pox = pulseOx.getIR();

from my code below, the cycle time of my collectHR() loop drops to about 20 mS. If I preallocate this spot by using the line directly below it (storing a constant instead of reading a new uint32_t each loop), my cycle time is about half a millisecond. What's confusing to me is that if I cast the uint32_t into a string using dtostrf:

dtostrf(pulseOx.getIR(),3,0,pOxBuf); // read pulseOx, convert it into a 3 byte string

it only takes about 1.2 mS to actually read a sample from the MAX30102. It seems to me that by favoring a struct over a string (from an earlier iteration of this code that wrote all data as a txt file instead of a bin file) so that I can write binary to my SD card, I'm absolutely throttling my speed. Shouldn't working bytewise be more efficient than working with a string? What is happening to the other 18 mS that occurs between reading the unsigned long and placing it into by byte buffer, buffer1? Implementing this code using string arrays instead of a struct, I was able to run at approximately 125 Hz. Now I'm at roughly 50 Hz. I'd appreciate any insight here. Relevant code shown below:

#include <Wire.h>
#include "MAX30105.h"
#include <SPI.h>
#include <SdFat.h>
#define moisture0 A0 // Upper back sensor analog pin
#define moisture1 A7 // Trunk sensor analog pin
#define ECGpin A3 // ECG analog pin

SdFat SD; // replace SD with SDfat.
File sdLog; // placeholder to create datalogger

struct meas // a 16 byte structure to hold all of our measurements
{
  unsigned long mils;
  int ECG;
  uint32_t pox;
  int tempInt;
  int m1;
  int m2;
};
struct meas measure; // create an instance of the above structure

byte buffer1[512];
byte *measureLoc = (byte *) &measure; // to access measure structure as bytes
char fileName[] = "WIHMSlog.bin";

void setup {
    Serial.begin(230400);
}

void loop() {
sdLog = SD.open(fileName, O_WRITE | O_CREAT | O_AT_END); // Create file for the datalogging and verify its existance
collectHR();
sdlog.close()
}

void collectHR() {
  unsigned int loopCount = 0;
  int buffLen = 0; // starting position in buffer
  int buffSize = 16;

  while (loopCount < 3200) { // some multiple of 32 (since 512 byte/sd block divided by 16 bytes per loop cycle = 32 cycles per sd write cycle

    measure.ECG = analogRead(ECGpin); // read ECG and stick the int into measures
    measure.pox = pulseOx.getIR();
    //measure.pox = 5555; // Placeholder value
    measure.mils = micros();
    measure.m1 = analogRead(moisture0);
    measure.m2 = loopCount; // just a test to ensure this is actually iterating in the card

    if (buffLen == 512) { // SD buffer is full, time to write!
      sdLog.write(buffer1, 512);
      buffLen = 0;
    }
    memcpy(buffer1 + buffLen, measureLoc, buffSize); // place the 16 byte data structure into the buffer
    buffLen = buffLen + buffSize; // increase the index size in the array
    loopCount++;
    Serial.println(micros());
  }

}


texts:
I'm using a standard 38kHz receiver with Arduino-IRremote library and it works fine for a while but then it stops working. The loop function is running time after time as expected but at some point the library decode function starts returning false until I reset the board.

This example code works for me with any arduino nano or bare atmega328p at 8Mhz but for both of them it freezes after some receptions.

The code is the library example itself:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

Some times this happens fast and other times it is after 20 or more receptions.
I only added a led blink later to test if the board is frozen or is only the infrared that stops receiving and it was the second case.


texts:
I am trying to connect 4 small DC motors to Arduino, like those in the following image:

The specification for each of them is:

  Suggested Voltage: 3V DC;
  No Load Speed: 65 ± 10rpm;
  No Load Current: 125mA (170mA MAX).

But I have no useful knowledge in electronics to do so...

I would be really thankful if anyone could explain me why it is so difficult to connect DC motors to Arduino (I've heard about problems with the magnetic field, but I don't really understand why); and possible point me to an easy (and cheap) solution. I am, of course, willing to study (not expecting a complete solution).

I'm aware there are some shields for doing this kind of connection, but they are really expensive, and I've seen some people using only transistors or components like SN754410.

Thank you in advance! :-)


texts: How does DDRD |= _BV(PD2) differ from digitalWrite(2,HIGH)?

texts:
I'm attempting to copycat the work of Louis Frigon's Toyota Aux Enabler. I have (with a lot of help on this site) managed to begin capturing and understanding messages on the AVC-LAN bus, but I can't quite send messages.
Frigon uses the following line to drive output signal to high:

DDRD |= _BV(PD2) | _BV(PD3);

I have more or less no idea what this means. He then 'releases the output' with the following:

DDRD &= ~( _BV(PD2) | _BV(PD3) );

If I copy these lines verbatim I don't get the same results. If I set the output high and then read the bus, I don't even see the signal I'm putting out. I wonder if this is related to the differences between his Atmega8 and my Arduino Nano?

I can't paste my or Frigon's work here due to character count limitations, so here is his github for the project: https://github.com/halleysfifthinc/Toyota-AVC-LAN

The most important files to my question are BigSchematic.jpg and AVCLanDriver.c.

Here is a dump of my current code: https://pastebin.com/NG9U5FuL

Here is my schematic: https://imgur.com/a/HBkK7


texts:
Id like to make my 5v pro mini use 3.3 v instead of 5 because i want to use it in an existing piece of electronics that uses 3v throughout.

Looking at the specs for the pro mini it says the 3.3v version can accept higher voltages.

So is there a regulator i can bypass/bridge that will convert my 5v version to a 3.3v version? or am i wasting my time?


texts: How to use the pushbutton without using if, else

texts:
I want to let the led blink for 3 seconds then 2 seconds then one second using the button one time and without using if/else

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

void loop() {
    // put your main code here, to run repeatedly:
    digitalRead(5, HIGH);
    digitalWrite(6, HIGH);
    delay(3000);
    digitalWrite(6, LOW);
    digitalWrite(6, HIGH);
    delay(2000);
    digitalWrite(6, LOW);
    digitalWrite(6, HIGH);
    delay(1000);
}


texts: RPM measurement using quadrature encoder

texts:
I am trying to build a RPM controller for my project. I am using a quadrature encoder (ppr=400) and Arduino Uno for this purpose. I am using the code given below inorder to caluculate the RPM of the DC motor. I get a reading on my serial Monitor. However, this RPM doesn't match with my manual calculation (i.e when I calculate the RPM Manually using a stop watch- for lower speeds).

EDIT-> Eg- Manually I get around 10 RPM, but my program shows 60 and more.

I have used one interrupt pin on my Arduino UNO.

#define encoder0PinA  2
#define encoder0PinB  3
int power=6; // to power up the encoder
int gnd=4;  // to provide ground to the encoder
int motor=11; //motor PWM pin
int dir=10;
volatile unsigned int encoder0Pos = 0;

void setup() {
  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // turn on pull-up resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // turn on pull-up resistor
  pinMode(power,OUTPUT);
  pinMode(gnd,OUTPUT);
  digitalWrite(power,HIGH);
  digitalWrite(gnd,LOW);
  pinMode(motor,OUTPUT);
  pinMode(dir,OUTPUT);
  digitalWrite(dir,LOW);

  attachInterrupt(0, doEncoder, RISING);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);
  Serial.println("start");    // a personal quirk
  analogWrite(motor,120); // to set a particular test RPM to the motor.
}

void loop() {
  encoder0Pos=0;
  delay(1000);
  float rpm=encoder0Pos/(400);
  Serial.println(rpm);
}

void doEncoder() {

  encoder0Pos++;
  }

Also I tried the very first code on the following link "https://playground.arduino.cc/Main/RotaryEncoders".. In this case my Arduino stops transmitting completely. I tried the same code on one of my friend's setup.. surprisingly it works there.
Can't understand where I am going wrong... Is my coding approach correct?? Please enlighten me...
Thank you.


texts: When does the ADC start reading again in interupt mode?

texts:
Simple question, I have set my ADC to read in "continuous"/interrupt mode and I take the reading the following way:

ISR(ADC_vect) {
   int val = ADCL;
   val += ADCH << 8;
   ... //Code to do stuff with reading here.
   }

My question is does the ADC start the new reading as soon as I have read the ADCH register or does it wait for the code inside the interrupt to finish? Basically I need to know if having more instructions in the interrupt will slow down my reading rate.

I don't have an oscilloscope or any good way to measure my reading rate accurately enough to know if a few extra lines of codes is affecting the rate or not.


texts:
I am receiving a compilation error from

#include <HX711.h>

The error is

fatal error: HX711.h: No such file or directory

However, C:\Users\user\Documents\Arduino\libraries\HX711 is there and has the correct files in it.
Sketch -> Include Library -> Manage libraries says that HX711 is installed. Strange thing is that I have another sketch that uses this library and it compiles. It uses quotes instead of angle brackets (which is strange because HX711.h is not in the same directory) and it works.
I have tried both quotes and angle brackets.

EDIT: I am really sorry about typing "define" instead of "include" into the question my only excuse was that it was late.
I copied the library directory to:

C:\Program Files (x86)\Arduino\libraries

and the problem remains.

I now have the HX711 directory in both the Arduino program files and the user directories and it still complains about it. The only way I can get it to compile is to place the hx711.h & hx711.cpp files directly into the sketch directory and change the line to #include "HX711.h"

EDIT:
Running Arduino 1.6.5 on Windows 8.1 64bit


texts: I want to use a distance sensor like the HC-SR04 to power a stop light like parking sensor for my garage. I have seen a lot of tutorials on how to use the HC-SR04 to power a single LED and found the schematic below on how to control up to 14 LEDs by hooking them onto the 5v and using a transistor. I have added a box where I would hook the sensor in. My question is, would it work if I had the sensor hooked into the 5v as well. The plan is to have 3 sets of 14 LEDs and have one set on at any given time. I plan on using an Arduino Uno.


texts: Sim900a AT+HTTPREAD does not get fully answer

texts:
changed the firmware on SIM900B

try to send get request http://dummy.restapiexample.com/api/v1/employee/1
AT+HTTPACTION=0returned +HTTPACTION:0,200,98

but, when I try to read (AT+HTTPREAD or AT+HTTPREAD=0,98)the response data
I got broken response

expected result:

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","employee_age":"0","profile_image":""}

and actual results:

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","empe_"0"olme"

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999","empe_"0"fea"}

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999""pea:,piig"

+HTTPREAD:98
{"id":"1","employee_name":"Shibani","employee_salary":"999",moeg""reae}

my Arduino code looks like that

void setup() {
  Serial.begin(9600);
  mySerial.begin(57600);
  delay(5000);
  mySerial.println("AT");
  Serial.println("End of the setup");
}

void loop() {
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}


texts: analogRead always returns 1023 - Arduino Mega 2560

texts:
I have connected an FSR (Force Sensitive Resistor) to  as per image(edited name for avoiding mismatch). When I measure the voltage b/w two pins of fsr, voltage changing as per pressure applied. But analogRead always returns 1023. But my another Mega works good with same code and configurations. Can someone guide me to correct it. Thanks in advance.

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

void loop() {
  int num1 = analogRead(A15);
  Serial.println(num1);
  delay(1500);
}


texts:
So for a while I get some Arduino IDE problem which I can't solve. When I try to upload any kind of code to my Arduino, Arduino IDE just stay at "Uploading". I tried to use another Arduino but I get the same problem. I used Pro Mini, Nano and Uno but it's the same. Then I decided to upload my code from another PC but I get the same problem and so I can't find where the problem is.

Is the problem in all my Arduinos or in my computers?

Note:
The code which I was uploading, was from Arduino examples.

I am using Windows 10 Pro x64 and in my console I get this error:

 avrdude: stk500_recv(): programmer is not responding
 avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x57


texts:
I am running the blinking LED program with stm32duino, and an STM32.  By trial and error, and a bit of debugging, I have worked out the following:

pin C13 blinks as well as the built in LED
(except my external LED is on the built-in LED is off)
the constant LED_BUILTIN equals 17

I found this pinout: https://stm32duinoforum.com/forum/wordpress/wp-content/uploads/2016/07/The-Generic-STM32F103-Pinout-Diagram.pdf

But it says nothing about C13 being pin 17.
Does anybody know where to look to find out where the arduino pins line up to the codes on the board?


texts:
Bought a cheap LCD form china (mcufriend, pictured below) and I cant understand which pin is which to use it with the SPI interface (starting to get worried that I can't use it), I've figured out this much:

LCD_RST; reset pin
LCD_CS; chip select
LCD_RS;
LCD_WR;
LCD_RD;

Which of those is MOSI, SCK, DC? Trying to use it with a ESP8266 (ESP-12).


texts: I need to put arduino in sleep mode. I did not find the library avr/sleep.h . From where to download it.


texts: no response in recieving with arduino uno by nfr905

texts:
from examples of  RadioHead library .
https://github.com/PaulStoffregen/RadioHead/tree/master/examples/nrf905


texts: Arduino YUN server crashes after few hours!

texts:
I have made a simple server using the YUN SERVER and CLIENT Libraries./
The server runs on a loop and waits for a client to connect. After connection it sends the client a simple message and then disconnects the client.

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

#define PORT 6666
YunServer server(PORT);
int pin =13;

void setup() {
  Serial.begin(115200);
  Bridge.begin();
  server.noListenOnLocalhost();
  server.begin();
}
void loop() {
  YunClient client = server.accept();
  if(client.connected())
  {
    digitalWrite(pin,HIGH);
    //startup
    startup_msg(client);
  }
  else
    digitalWrite(pin,LOW);
    delay(500);
}
void startup_msg(YunClient client)
{
    client.print("SAndTerm");
    client.stop();
}

Well this code runs smoothly for few hours. But after that, it stops responding to any client request. I guess the server crashes.
I have to restart the YUN to get it working again.

Is there anyway I can run this without it getting to crash?
Well I want it to be running just like a normal server would.


texts:
I have a simple scenario please:

Two Arduino Nano 33 IoT devices started moving randomly from the same exact origin(Point = [X0, Y0, Z0]);

Can I use the coordinates queried from each device Accelerometer to get the Euclidean Distance between them?

In other words, Is the relative coordinate/position retrieved from the Accelerometer reliable?

Because I read that getting the relative position every time requires double integrations which leads to big accumulated error over time. Though I might be totally wrong.

Your help is very much appreciated.


texts:
I've researched a lot but I couldn't find a solution to my problem, which is that after properly following all steps from this Website: http://www.danielealberti.it/2014/02/collegamento-diplay-lcd-ad-arduino-via.html

and after using the Library LIQUIDTWI2:

(https://drive.google.com/file/d/0BwSP1-P3E2UJY1loYWtWQVRWNlU/edit?usp=sharing)

for I2C connections, the LCD keeps displaying black boxes on the top row.

I'm pretty sure that I have wired (as shown in the tutorial linked above) and programmed everything correctly but I'm still getting the black boxes. Is the problem related with the MCP23017 pin expander or with something else?

I'm using an Arduino UNO


texts:
As described here
https://learn.adafruit.com/multi-tasking-the-arduino-part-2/timers

I use timer 0 to get my own timer with a milliseconds resolution.

It is setup like this:

void setup (void)
{
    ...
    cli();
    OCR0A  = 0xAB;
    TIMSK0 |= (1 << OCIE0A);
    sei();
    ...
}

The value 0xAB is chosen randomly and should not affect the behaviour.

The interrupt handler looks like this:

ISR(TIMER0_COMPA_vect)
{
    if (myTimer != 0)
        myTimer--;
    return;
}

This works just OK but having a closer look at the actual timing values using millis() I've found that the timer values given by this ISR are about 2-3% too long.

According to adafruit.com this method should exactly follow the built-in millis() timer of the Arduino.
In my program there are no other interrupts active. There are some Serial.print() outputs, maybe they affect the timing?
The solution I've found looks like this:

ISR(TIMER0_COMPA_vect)
{
    static unsigned long timeLast;

    unsigned long timeNow = millis();
    uint8_t timeDiff = (uint8_t)(timeNow - timeLast);
    timeLast = timeNow;

    if (myTimer != 0)
        myTimer -= timeDiff;

    return;
}

Instead of simply decrementing the timer, the timer value is decreased by the actual amount of time since the last call of the ISR.

With this my timer follows exactly the millis().
But why doesn't the first approach give an exact timing? Apparently there are some cases where the time between calls of the ISR is not 1ms but 2ms.


texts:
When interfacing my Arduino Uno with a relay I was facing reliability issues, and while investigating it with a multimeter, I found something strange.

I noticed that in the 5V power pin (with which I was powering my circuit) is producing only 3.3V when using the power adapter. However, when connected via the USB-A port, the 5V pin was producing the expected 5V voltage.

I tried powering it in many ways - computer-to-USB-A, computer-to-barrel-jack, phone-charger-to-USB-A, phone-charger-to-barrel-jack and an external 5V DC power supply. In all cases, the above observation held true - powering the board through the barrel jack made the 5V power pins produce only 3.3V.

Question: Why is this happening? Does that mean my board is faulty? Is there any way to fix this?


texts:
I am just running the below DHCPAddressPrinter sketch in Arduino example to setup EthernetShield with MAC and IP

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

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

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {

 }

After uploading the sketch to arduino,below is the output shown in console

Sketch uses 13,614 bytes (42%) of program storage space. Maximum is 32,256 bytes.
Global variables use 539 bytes (26%) of dynamic memory, leaving 1,509 bytes for local variables. Maximum is 2,048 bytes.

And there is nothing shown in Serial monitor
This is the image of Ethernetshield's some leds glowing after connecting to Router.
My router is Binatone Wireless ADSL2+ Router.

I checked arp -a,

C:\Users\Radhamani>arp -a

Interface: 192.168.1.6 --- 0x3
  Internet Address      Physical Address      Type
  192.168.1.1           6c-fd-b9-24-c6-fe     dynamic
  192.168.1.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static

Interface: 192.168.198.1 --- 0xe
  Internet Address      Physical Address      Type
  192.168.198.255       ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static

Interface: 192.168.234.1 --- 0xf
  Internet Address      Physical Address      Type
  192.168.234.255       ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static

Complete result of ipconfig:

Wireless LAN adapter Wi-Fi:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::901:3297:48ad:9e7d%3
   IPv4 Address. . . . . . . . . . . : 192.168.1.6
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter VMware Network Adapter VMnet1:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c954:40b2:c8c1:de0%14
   IPv4 Address. . . . . . . . . . . : 192.168.198.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
Ethernet adapter VMware Network Adapter VMnet8:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2837:7e01:c799:d627%15
   IPv4 Address. . . . . . . . . . . : 192.168.234.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Serial.println in the program is not printing anything.Looks like Ethernet shield is not getting IP.I am not sure where I am wrong.Please help me to fix this issue


texts:
I am currently using a Particle Photon to control a relay that turns a lamp on and off. I would like to power the Photon and the lamp from the same power cord.

Currently, I have a power cord for the lamp and I am also using a usb cable to power the Photon.

I found this (Enclosed AC DC Converter) and I am wondering if this will work if I split the 120V power cord to go to the relay and the converter. Will I need anything else? Are there any other concerns I should worry about? Do I need to worry about polarity?

Thanks for your help in advance.


texts:
Basically the user presses a button and cycles thru 3 different modes. Mode 1 the LED is on, mode 2 the LED is off and mode 3 the LED is kept on for a certain amount of time. I'm using the millis() to keep track of the time. the LED in the third mode just stays on and never switches to off. I have the Serial.Writes in there to help me debug. I have the delay after the button read since if I didnt put it in it would register a lot of button presses.

int ledPin = 5;
int buttonApin = 9;
int ledMode = 0;

boolean lastButton = HIGH;
boolean currentAButton = HIGH;

// debounce button
boolean debounceFUNC(boolean last)
{
    boolean current = digitalRead(buttonApin);
    if (last != current)
    {
        delay(5);
        current = digitalRead(buttonApin);
    }
    return current;
}

void setMode(int ledMode)
{
    // turns on led
    if (ledMode == 1)
    {
        digitalWrite(ledPin, HIGH);
    }
    // turns off led
    if (ledMode == 2)
    {
    digitalWrite(ledPin, LOW);
    }
    // timer - turns off after 5000
    if (ledMode == 3)
    {
        long interval = 5000;
        unsigned long cMillis = millis();
        static unsigned long pMillis;

        if (cMillis - pMillis > interval)
        {
        pMillis = cMillis;
        digitalWrite(ledPin, HIGH);
        Serial.println("On");
        Serial.println(interval - cMillis);
        }
        else
        {
        digitalWrite(ledPin, LOW);
        Serial.println("Off");
        }

        }
    }

void setup()
{
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
    pinMode(buttonApin, INPUT_PULLUP);
}

void loop()
{
    // sets led mode
    currentAButton = debounceFUNC(lastButton);
    delay(500);
    if (currentAButton == LOW)
    {
        ledMode++;
        Serial.println(ledMode);
    }
    else if (ledMode > 3)
    {
        ledMode = 0;
    }
    // ledMode function call
    setMode(ledMode);
}

screenshot of the serial monitor.


texts:
So I am trying to use this thermistor to measure temperature and with this code below it always puts the same value (2147483647).  I used this tutorial to do the wiring and coding.  I don't think the wiring is the problem but think the problem is somewhere in my code or perhaps I am using a wrong type of thermistor?  Am I missing something?  Any help is greatly appreciated.

I am only using a 1k resistor in series with the thermistor but don't think that would be a problem, right?

Edit: I should have mentioned I'm using the adafruit huzzah esp8266 so there are a few pins.

#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Phant.h>
#include <ESP.h>

#define DHTPIN 2
#define DHTTYPE DHT22
#define THERMISTORPIN 4

DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "xxxx";
const char* password = "yyyyyy";
const char* host = "data.sparkfun.com";
const String publickey = "uuuuuu";
const String privatekey = "ttttttt";
const byte NUM_FIELDS = 5;
const String fieldNames[NUM_FIELDS] = {"ghumidity", "gtemp", "light", "otemp", "wtemp"};
String fieldData[NUM_FIELDS];

//thermistor variables
const int thermresistor = 987; //value of resistor in series with thermistor
int thermtemp = 0;
uint8_t i;
uint8_t numsamples = 5;
uint8_t To = 25;
const int B = 3950;

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

    while (WiFi.status() != WL_CONNECTED) {
  delay(500);
}

    fieldData[0] = 1; //humidity
    fieldData[1] = 2; //garden temp
    fieldData[2] = 3; //light
    fieldData[3] = 4; //outside temp
    fieldData[4] = 8; //water temp

//turnpumpon();
posttophant();
//turnpumpoff();
ESP.deepSleep(1200000000, WAKE_RF_DEFAULT);

}

void posttophant()
{
    fieldData[0] = dht.readHumidity();
    fieldData[1] = dht.readTemperature(true);

    //read outside temp (otemp) data and convert to a temp
    for (i=0; i<numsamples; i++){
      thermtemp = analogRead(THERMISTORPIN);
      thermtemp += thermtemp;
      delay(10);
    }

    //take the sum of all the readings and divide by # of samples to get avg.
    thermtemp = thermtemp / numsamples;

    #voltage divider equation
    thermtemp = thermresistor / (1023 / thermtemp - 1);

    //Steinhart eqn.
    thermtemp = 1 / (log(thermtemp / thermresistor) / B + (1 / (To + 273))) - 273;
    fieldData[3] = String(thermtemp);

    WiFiClient client;

    const int httpPort = 80;
if (!client.connect (host, httpPort)){
  return;
}

    client.print("POST /input/");
    client.print(publickey);
    client.print("?private_key=");
    client.print(privatekey);
    for (int i=0; i<NUM_FIELDS; i++)
    {
      client.print("&");
      client.print(fieldNames[i]);
      client.print("=");
      client.print(fieldData[i]);
    }
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(host);
    client.println("Connection: close");
    client.println();
}


texts:
I'm currently writing a tool that automatically detects connected arduinos and provides a one-button solution for flashing new firmware.
I've got a couple of arduinos at home (Diecimilla, Uno R3 SMD and some nanos from china) and each type presents with a different serial port name.

Questions

Can someone explain where these port names come from?
Can I assume that /dev/cu.usbserial-A9UPDRZB is, atleast in most cases, an arduino nano?
Are there other ways to identify the type of the board?
Is the name of the serial port some kind of hash generated from informations retrieved from the device?


texts: Can't Flash ESP8266 latest firmware, says "Fast Flashing error" and "Invalid head of packet(' ')

texts:
I can't figure out how to flash the firmware found on http://www.electrodragon.com/w/ESP8266_AT-Command_firmware. I am using ESP8266 Download tool v3.4.4. When I am adding a firmware in download path it goes on till a fixed percentage (77 or 99..mostly) and gives the error Invalid head of packet, FAST FLASHING ERROR. One more thing is that the tutorials I am using to do this have many download path entries filled in the download tool while mine are just blank. It says upload the combined file to 0x0000. I tried uploading V1.54... file's content (both files) but still got the similar error(http://i.imgur.com/3GXB9Yi.png). :P

So anyone could just guide me through this as I am a complete newb into this. Please mention any other information needed in comments.

PS

I am pretty sure the power supply is adequate as I have been using esp8266 with the old firmware smoothly. I have also connected a 200uF capacitor b/w gnd and vcc(3.3v from FTDI).
I have double checked the connections.(Yes, GPIO0 is grounded).
I flashed an earlier version successfully ai-thinker-v1.1.1.bin but when I connected it to arduino IDE serial monitor it started giving unending gibberish text :P.


texts: My circuit is being goofy with regards to my PIR sensor

texts:
Here is the code I've written so far. I am making a circuit with a couple of motors and 3 sensors. My plan is for the PIR Motion sensor, distance sensor, and photoresistor to tell the motors to stop when they're triggered. When I set the if proximity = LOW, the LED lights up whether I move the sensor or not. But when it's set to HIGH, the LED won't light up even if motion is detected. I've tested it separately from the rest of the code and it doesn't do this. Is there something wrong with how I've got my simultaneous loops?
int inches = 0;
const int ledPin1=11; // blue LED
const int ledPin3 = 9; // red LED
const int servoPin = 4; // blade motor
const int MOTION_PIN = 2; // Pin connected to motion detector
const int ledPin2 = 10; // green LED
const int photoPin = 3; // photoresistor connected to digital pin 2
const int motorPin = 13; // motor for the wheels connected to digital pin 13
int cm = 0;

long readUltrasonicDistance(int triggerPin, int echoPin) // setting up the distance sensor, this code is pre-set up along with the circuit
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
} // long

void setup()
{
  Serial.begin(9600); // loop time
  pinMode(ledPin1, OUTPUT); // sets the blue LED as an output
  pinMode(ledPin3, OUTPUT);
  pinMode(MOTION_PIN, INPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(servoPin, OUTPUT); // blade
  pinMode(photoPin, INPUT); // light sensor
  pinMode(motorPin, OUTPUT); // wheels
} // end setup

void loop() {

    dist();
    motion();
}

void dist()
{
  // measure the ping time in cm
  cm = 0.01723 * readUltrasonicDistance(7, 7);
  // convert to inches by dividing by 2.54
  inches = (cm / 2.54);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.println("cm");
  if (cm<150) // if an object (another person) approaches within 1.5 meters
  {
  digitalWrite(ledPin1, HIGH); // turn on the blue LED, symbolically represents roomba reaction to go around or stop
  } // end loop
}

void motion()
{
  int proximity = digitalRead(MOTION_PIN);
  Serial.println(proximity);
  if (proximity == HIGH) // If the sensor's output goes high, motion is detected
  {
        Serial.println("Motion detected!");
        digitalWrite(ledPin2, HIGH);
  }

}


texts: Autonomous Quadcopter power distribution and sensing concerns

texts:
I've been programming and testing an Arduino based quadcopter for the past 4 months. Until now I did not need to use an external power source for my sensors. Now I want to use the 'BEC' power from my electronics speed controllers.

Each of the 4 ESCs gives 5V @ 2A. I would set these up in a parallel circuit, which would give me 5V @ 8A (theoretically).

I also want to use a cheap chinese voltage sensor to sense the voltage from my 5000mAh 25-50c 11.1v battery. I'm not sure if it is safe to connect my batteries wires to my sensor with the 125A that it can put out.

My question is whether or not it is safe to have a common ground on Arduino with an 8A power supply AND if it is safe to use a 5V 8A power supply with these sensors.

Here is a problem that I've encountered before:

while powering my IMU off the BEC and sending motor PWM signals, my sketch would run for about 10 seconds then freeze. It was not until I powered my IMU off the Arduinos 5V power that I was able to run the sketch flawlessly. What could have been causing that?

I've made a diagram of my circuit in Fritzing (not actually tested yet due to fear of ruining my sensors). I'm using an Arduino Mega.


texts:
How can I get my programmer board/windows computer to recognize my board again. I am using the esp32 cam and have put two boards in a state where I am unable to flash them anymore. here is the error:

serial.serialutil.SerialException: could not open port 'COM5'WindowsError(2,'The system cannot find the file specified.')Failed to execute script esptoolthe selected serial port Failed to execute script esptool

I tried reinstalling the drivers and understand that the com port is a separate chip
https://gist.github.com/wybiral/2a96c1d1605af7efa11b690586c4b13e

Here is the sketch I used. I uploaded it using the dev module board setting as well as with 80mhz and 112500 speed. I uploaded with 3v and then provided 5v to the board to run the sketch. The sketch runs but prints out gibberish.

Edit:

Here is a schematic of the board
https://github.com/SeeedDocument/forum_doc/raw/master/reg/ESP32_CAM_V1.6.pdf


texts:
I am using a 16*2 lcd display as a dashboard computer.
I want it to display a logo at the very beginning of the code, but some letters occupy the space of 4 characters, and are using both lines of the display, and creating those letters character by character (some actually require 6 characters) is very difficult.
Is there anyway i can address the lcd as a big matrix ?
there would be 16 lines ( the oringinal 2 lines * 8 lines of each character) and 80 columns (the original 16 columns * 5 columns each character has).
This would make it A LOT easier.


texts:
I am doing a project on Arduino controlled light dimmer circuit...

I have a separate circuit for zero crossing detector and IR receiver but when I am combining both of them in arduino then my IR receiver stops working and zero crossing interrupt is not detected...

Here is my code:

#include <IRremote.h>
int RECEIVE_PIN = 8;
int AC_LOAD = 3;
int dimming;

IRrecv irrecv(RECEIVE_PIN);
decode_results results;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();
    pinMode(AC_LOAD, OUTPUT);
    attachInterrupt(0, zero_crosss_int, RISING);
}

void zero_crosss_int()
{
    int dimtime = 75*dimming;
    delayMicroseconds(dimtime);    // Off cycle
    digitalWrite(AC_LOAD, HIGH);   // triac firing
    delayMicroseconds(10);         // triac On propogation delay
    digitalWrite(AC_LOAD, LOW);    // triac Off
}

void loop()
{
    if (irrecv.decode(&results))
    {
        Serial.print("0x");
        Serial.println(
        results.value, HEX);
        delay(50);

        if(results.value==0xE13DDA28)
            dimming = 120;

        if(results.value==0xAD586662)
            dimming = 80;

        if(results.value==0x273009C4)
            dimming = 20;

        irrecv.resume();
    }
}

Can anyone help me with this????


texts: Will I be able to control stuff from anywhere in the world if I use a wifi shield like ESP8266?

texts:
Currently, I am using a Bluetooth shield, HC-05, which is working perfectly but there are two problems:

Only one person can connect to Bluetooth  at a time.
I have to be in a specific place to be able to control the lights.

I want to be able to control everything from anywhere in the world. I've thought about using an Ethernet Shield, but I'd prefer using a Wifi Shield if it can do the task.


texts: Plotting a real time graph of sensor data from Arduino on Processing, MatLab or Python

texts:
I have an accelerometer connected to my Arduino Due to spit out data on my serial monitor as described in my earlier post. I'm trying to find a sketch I could use to plot a continuous real-time graph on either Processing, MatLab or using Python MatPlot.

The accelerometer data is stored in arrays of xArray[k] for the x-coordinate values, yArray[k] for the y-coordinate values and zArray[k] for the z-coordinate values. How can I plot a real-time graph of these values? Thanks in advance.


texts: where does access point's IP address come from for sketch AP_SimpleWebServer.ino in Github WiFi101 examples

texts:
I don't understand where the access point's IP comes from.
Sketch uses WiFi.beginAP( ssid )   ..to start the AP.
Then, printWifiStatus() gets the access point's IP with:

IPAddress ip = WiFi.localIP();

How does .beginAP() create the IP?  What does it use for a mask?

I'm creating network service on a MKR1000, and want to use .beginAP() to make it an access point, so I don't need a "middle man" (router).  Going to have mobile device (iPhone) connect directly to Arduino MKR1000.


texts: Analog input draws current when Arduino is turned off

texts:
I am using a Arduino Pro Micro from SparkFun (similar to Arduino Leonardo, cpu: Atmega 32u4). It has a analog input: A0, which I use to keep track of the battery voltage in my battery powered project (via analogRead).

I found out that the red LED on the board lights up, even if there is no supply voltage on the usual inputs (micro-USB or Vcc). If I use a multimeter to measure the current between the battery and A0, I see that the analog input is drawing about 30mA if the Arduino is not powered.

Is this the normal behaviour? Can I fix this via hardware?


texts: Why it shows d2 was not declared in scope

texts:
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[] ="your auth token";
char ssid[] = "your wifi name";
char pass[] = "your wifi password";

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  dht.begin();

  timer.setInterval(1000L, sendSensor);
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
   sensors.begin();
}

int sensor=0;

void sendTemps()
{
  sensor=analogRead(A0);
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.println(temp);
  Serial.println(sensor);
  Blynk.virtualWrite(V1, temp);
  Blynk.virtualWrite(V2,sensor);
  delay(1000);
}

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


texts:
I have an Arduino Micro where I want to control a display with IR commands. So the Arduino should send the IR commands to the display.

I have found a library "Arduino-IRremote", which I am using to transmit Commands to the display. The display works perfectly with its remote control, however I can't get it accept signals from my Arduino.

Now the special part about my setup is, that I do not use a "classic" IR transmitter. Instead i uset an IR cable, which is connected to "IR-In" of the display. So no LED - only a wired connection. The IR-cable consists of 3 wires. 2 for power supply (VIN and GND) and one is for the data connection. The wire with the data connection is connected with the Arduino PWM pin 3 (like it is said on the example in the linked library), but I tried all other pins anyway.

#include <IRremote.h>
IRsend irsend;

void loop() {

  for (int i = 0; i < 2; i++) {
    digitalWrite(RXLED, HIGH);
    irsend.sendNEC(0x004eff71, 32);
    Serial.println( "sendNEC 00 4E FF 71" );
    digitalWrite(RXLED, LOW);
    delay(40);

  }
  delay(1000);
}

004eff71 is a NEC-Command from the original remote control

Now can somebody tell me, what I'm doing wrong? The program compiles and the LED lights up, everytime it should send the NEC-command. But still the display receives nothing.
What is wrong?


texts:
I have 4 single color LED strips which I would like to control individually with one remote controller - turn them on/off an dim them. So far I only have my LED strips (They are about 3.5 meters of length combined), an 80W power supply and an Arduino Uno. I'm new to this kind of stuff. Could you help me with the setup. What parts do I need?

EDIT:
So I decided to go with an Arduino Nano. First, I'll try to power up only one strip. My question now is, how to power up the Nano. All the setups I found, have an USB cable connected to the nano to power it up. Can I connect my 12V+ to the VIN?

EDIT2:
Take a look at my setup. Is that OK?

Thanks


texts: I am interested in learning about arduino.  What is the quickest and cheapest way to find out if this is something I can and want to do?


texts: Turn on each of the LEDs in order, by setting the cycle delay to 100 milliseconds

texts:
I have a tutorial to finish and I don't know the code I have to use to make all (4 LEDs) to turn on in order. So this is my code and my simulation. Thanks in advance!

My Code:

void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(6, HIGH);
  delay(100); // Wait for 100 millisecond(s)

  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(9, LOW);
  digitalWrite(6, LOW);
  delay(100); // Wait for 100 millisecond(s)
}

EDITED:
I have to follow this one. I guess my simulator is correct.


texts: "avr/io.h: No such file or directory" while compiling for board Generic STM32F103C series

texts:
I'm trying to compile FastLED library for my STM32F103C using Arduino 1.8.5 IDE, but getting this error:

In file included from C:\Program Files
(x86)\Arduino\libraries\FastLED/led_sysdefs.h:32:0,

                 from C:\Program Files
(x86)\Arduino\libraries\FastLED/FastLED.h:44,

                 from
C:\Projects\ioSmartHome\arduino\ColorPalette_stm32\ColorPalette_stm32.ino:1:

C:\Program Files
(x86)\Arduino\libraries\FastLED/platforms/avr/led_sysdefs_avr.h:12:20: fatal
error: avr/io.h: No such file or directory

 #include <avr/io.h>

                    ^

compilation terminated.

exit status 1
Error compiling for board Generic STM32F103C series.

I just have no idea why it's trying to include this file which isn't existed for this platform. Any idea?


texts:
I just picked up a new Arduino Micro for a project, but the first time I tried to upload to it, things went terribly wrong. The USB cable was loose, so the power light kept blinking on and off. When I did get it stable, I accidentally had 'Uno' selected under 'Tools->Board'. I think this was the source of the problem.

I'm aware that the solution for these kinds of problems is to try to upload some simple code while in bootloader mode, but pressing reset shortly after pressing the Upload button. But this board doesn't even respond when I press reset. I have tried it with both the on-board button and with an externally button linking RS to ground.

Furthermore, the board doesn't show up in my Device Manager, not even as an "Unknown Device". The device managed doesn't even refresh when I plug it in.

I know the connection is okay because the power light is on. And I know it's not a driver issue or an issue with the port, because I have no trouble getting a different Micro recognized.

The only thing I haven't tried is burning the bootloader through ICSP, since I don't have the right cable. Is there anything else I can try, or is this just bricked?

Thanks, everyone


texts:
As you probably know, SoftwareSerial uses Interrupts to do some of the timing stuff of the Serial communication.

What I am trying to accomplish is to measure the time that it takes SoftwareSerial.write() to write/send one byte.

Obviously, I started trying with timestamps based on millis(), but found out that SoftwareSerial messes with the millis() timer and it simply doesn't count properly.

I have something like this:

timestamp = millis();
HC12.write(endByte); //HC12 is a SoftwareSerial object

//After sending waits for the answer
while (HC12.available() > 0) {
  byte r = HC12.read();
  if (r == (byte) 254) { //The other HC12 module sends 0xFE
    unsigned long received = millis() - timestamp;
    Serial.println(received);
  }
...

Any suggestion on how I could measure this?

I am trying to implement a half-duplex communication with HC12 433MHz modules and I am testing some theoretical/real timing values for the communication between two boards.


texts: Anyone have example code for ESP32 as media controller for Android/iPhone Media Apps

texts:
There's actually another post with this very same topic but no answers on that post. Back in January of 2020, the last commenter said he had sample code and then he went dark without posting the actually code. The thread is here:
Want to create bluetooth audio control (volume up/down, play, pause, etc.) for smartphone
My problem is the exactly the same as the original post. Amazon and Aliexpress have literally hundreds of these "media buttons" that you can buy and pair via bluetooth with your Android or iOS. You can then playback media on iOS/Android and the "media buttons" can control the playback. Pretty common controls are volume up/down, next, previous, play and pause.
I've written a lot of Arduino code for Nano, Uno and even MKR. I've written a bunch of ESP8266 and ESP32 code as well. Usually when I try and learn something, a few google searches will find an example that I can figure out. For this, I've been able to find nothing.
Every tutorial or sample code is about how to send commands to the ESP32 via Bluetooth or pair an ESP32 with a bluetooth joystick, etc. None of those examples help me understand what's needed for an ESP32 to pair with my Android and act as media buttons, sending volume up, down and play/pause commands via bluetooth.
Can anyone help with example code for doing this with an ESP32? (by the way, this forum would not let me comment on the original post or I would have. it said I didn't have enough karma points or something)


texts:
I am new to hardware, I have always used plug and play shields to accomplish simple projects. A while back I purchased RGB LED Shutter Shades from Macetech. I got the hacker version thinking I would add a RFDuino and use that to power the glasses and receive commands from my iPhone. I found out that the glasses needed 5v and the RFDuino could only do 3V. So i used a Sainsmart Nano v3 to control the LED's and I added a RFDunio to receive commands from my iPhone, the RFDuino is powered by the Nano.

The issue I am having is that when Im using an external battery pack, the kind you use to charge your phone, I'm guessing the power is not consistent enough and the RFDuino drops its connection to my phone. When I run the glasses using my computers USB port I do not have that problem.

My question: Is there something I can add to my circuit to make this inconsistency with my power stop happening?


texts: Trouble streaming audio from amazon s3 servers

texts:
I am experimenting with streaming audio from servers using an ESP32 and this library. I have been able to stream audio from every http server which i have tried but have had mixed success with https servers. I had originally wanted to stream audio from an amazon S3 server but could not get this to work. I have managed to get it to work using the google cloud servers (Both of these are https servers). Any thoughts on what might be the problem would be much appreciated. thanks.
I'm not sure if this is an appropriate forum but im not qute sure where else to post my question. thanks.


texts: Can the Adafruit PN532 NFC/RFID be used to read Gen-2 EPC class RFID Tags?

texts:
I used Mifare Classic cards on a previous project and it worked brilliantly with the RIFD/NFC shield and Arduino Uno. I came across a Gen 2 EPC Class 1 RFID tags. This tags are long range ones. They use an IC chip called Alien Higgs3. I know that the shield itself is not capable of reading from a long range. I would just like to know if the shield is just able to read this type of tag even in close contact.

Is there a UHF RFID Reader that I can use to connect it with the Arduino and read these tags?

Any advice or suggestions are welcome. Thank alot.

RFID Tag Specifications:

Protocol- EPC Class 1 Gen2
Frequency- 860-960 MHz
IC Type (chip)- Alien Higgs3


texts: How to fix compilation error for tone() using same timer as other function

texts:
I am trying to integrate tone() with the open source program for the Amped heart rate monitor. The error:

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
sketch\PulseSensorAmped_Arduino_1dot4.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

The program comes in three files. PulseSensorAmped_Arduino_1dot4.cpp I don't think references any timers but references a function in another file with this code:
  // Initializes Timer2 to throw an interrupt every 2mS.
  TCCR2A = 0x02;     // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
  TCCR2B = 0x06;     // DON'T FORCE COMPARE, 256 PRESCALER
  OCR2A = 0X7C;      // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
  TIMSK2 = 0x02;     // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
  sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

This uses timer 2; but isn't the error for timer 1? The tone() reference page says that tone interferes with pins 3 and 11. Is there any way to fix this?
references:
https://www.arduino.cc/en/Reference/Tone
https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino


texts: ATtiny85 Comparator C interrupt on timer 1

texts:
I have a program that uses Timer1 comparator A in CTC mode. I realize that I need to set OCR1C for the timer to reset at given value. However there is no such thing as an interrupt generated by timer1 counter matching OCR1C value.

Moreover, if I enable CTC and set for example OCR1A to 10, and OCR1C to 50, the interrupt handler ISR(TIMER1_COMPA_vect) will be triggered when the counter reaches OCR1C value, not OCR1A. I'm really confused...

Can anyone explain to me what's going on?

EDIT:

Here is the program that I'm using.
main program:

#include "avr/interrupt.h"

ISR (TIMER1_COMPA_vect) {
  PORTB ^= (1<<PB0); //toggle pin
}

void setup() {
  cli();
  // put your setup code here, to run once:
  //prescaler value 8192 sets one clock tick to about 1ms
  TCCR1 |= (1<<CS13)|(1<<CS12)|(1<<CS11)|(0<<CS10);
  //turn CTC mode on
  bitSet( TCCR1, CTC1 );
  //set comparatorA value
  OCR1A = 10;
  //enable compA interrupts
  bitSet(TIMSK, OCIE1A);
  //set comp C value
  OCR1C = 19;
  // initialize counter 1 on 0
  TCNT1 = 0;
  pinMode( 0, OUTPUT );
  digitalWrite( 0, HIGH );
  sei();
}

int main() {
  setup();
  // put your main code here, to run repeatedly:
  while(1) {
    }
 return 1;
}


texts:
I have two XBee Pro S2Bs: one is plugged in to a USB explorer, and; the other is plugged into an Arduino Wireless Protoshield, which is connected to an Arduino Uno.

My XBee connected to the explorer is configured as the coordinator in AT mode, and the XBee connected to the Arduino is configured as a router in AT mode. As a side note, I tested the network with a second USB explorer, and I was able to communicate between both XBees.

I uploaded the following code to the Arduino (which is just a sample I pulled off the internet somewhere):

char rx_byte;

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

void loop()
{
    if (Serial.available() > 0)
    {
        rx_byte = Serial.read();
        Serial.print("You Typed: ");
        Serial.println(rx_byte);
    }
}

Once I upload the code and turn on the serial monitor for the Arduino (using either the Arduino IDE or Visual Micro, with the Arduino plugged in via USB), and turn on the serial monitor on for the XBee connected to the USB explorer (using the serial monitor in XCTU), I get the following results:

If the wireless proto shield has its switch set to USB mode, then I can send data from the Arduino serial monitor to the serial monitor in XCTU, but the Arduino serial monitor doesn't receive data that is typed into the XCTU serial monitor.
If the wireless proto shield has its switch set to Micro mode, then I get mostly the opposite result.  I can send data from XCTU serial monitor to the Arduino serial monitor, which the result is returned to the XCTU serial monitor, e.g., if I type "X" in XCTU serial monitor, both serial monitors say "You Typed: X".  However, if I try to send data through the Arduino's serial monitor, neither serial monitor displays anything.

What I would like to do is be able to type in either serial monitor and have the data displayed in both serial monitors, like you would expect in a simple chat program.

Can someone see where I have gone wrong and/or how to get to the correct result?


texts: What is the Arduino Nano maximum wattage?

texts:
Hello,

I am currently working on a DIY project and I would like to know the Maximum Wattage of a Arduino Nano with a ATmega328 processor. If anyone know what it is it would be a great help.

Ricky


texts: Why do most arduino function return a -1 instead of a 0

texts:
Many arduino functions return -1 if something 'fails'. Serial.read for example returns -1 or the infamous ÿ when this function is called while the serial buffer is empty.

As embedded C progammer, I am personally a fan of letting functions return data in the form of modifying pointers which points to passed on addresses and return states with the actual return functionality of a function. I am used to return a 0 if a function is 'not done' or 'failed'.

I see no logic in why many arduino functions return an int type which contains -1 instead of just a 0.

Would it not be better to let functions return a boolean type or an unsigned char type in which false or '0' would indicate a 'failed' process and true or '1' would indicate a 'succesful' process?

Also: if I type:
if(Serial.read()) {/* body */ }
and Serial.read() returns -1 because the buffer is empty. Will the If's body be executed or not?


texts: Easy way to upload sketches using MIDI (without RX pin removed)

texts:
I noticed when I use sketches with MIDI (using RX/TX), before uploading I have to remove every time the RX wire ... is there an easy way to prevent this?

(I'm thinking about making a push button/toogle for this to prevent it, but maybe there is an easier way).

Update: I use an Arduino Uno


texts: Read only selected Packet SoftwareSerial

texts:
I am reading data from RS485 which is in the following format:

void sendkwh()
{
  RS485Serial.write((byte)0x01); // Meter Address
  RS485Serial.write((byte)0x03); // Read Function Code
  RS485Serial.write((byte)0x40); // Register Address Variable (Start address high bit)
  RS485Serial.write((byte)0x34); // Register Address Variable (Start address low bit)
  RS485Serial.write((byte)0x00); // Register Quantity (High Bit)
  RS485Serial.write((byte)0x02); // Register Quantity (Low Bit)
  RS485Serial.write((byte)0x90); // CRC check code (CRC code Low bit)
  RS485Serial.write((byte)0x05); // CRC check code (CRC code High bit)
}

and I need to read only the 4th and 5th frame of the packet. I am doing it the following way:

RS485Serial.listen();
  if (RS485Serial.available() > 0)
   {

    if(RS485Serial.read() == 0x01)
    {
    for(int i=0; i<4; i++) {

   byte discard = RS485Serial.read();

   }
    byteReceived = RS485Serial.read(); // 4th frame
    byteReceived2 = RS485Serial.read(); // 5th frame

which is working fine. I wanted to know if there is a method to discard the packets without loop?

As in I have changed the sendkwh() as below:

byte SendKWh[] = { 0x01, 0x03, 0x40, 0x34, 0x00, 0x02, 0x90, 0x05 };
RS485Serial.write(SendKWh, sizeof(SendKWh));

But don't know how to proceed with tapping the 4th and the 5th frame. Your help is appreciated.


texts:
Can someone help me understand how the external antenna IPX connector actually stays connected to the Yun? Do I have to "force" it in so it snaps in? I've been somewhat gentle with it in fear I'll break something. However when I get close to getting it in, it just pops back out.

I've never worked with an IPX connector before, and I'm trying to not break anything.

EDIT: I may have figured this out. Looks like the socket on the Yun is an IPEX socket, which is female. The cable I have is an IPX/uFL/u.FL connector, which also appears to be female.

It looks like I need to use an MCX cable adapter as found here: http://www.adafruit.com/products/1532 If someone could confirm this for me, that'd be great.

Here's a picture of the cable I purchased and my Yun.


texts: Adafruit/Arduino SAMD BSP package and adding SAME51 compatibilty

texts:
I am trying to make a SAME51 variant of an arduino board, in the end I would like to have an arduino compatible board, BSP, and library for controlling canbus.
I have already gone through some things, but I believe I need a slight bit of guidance for the next step, mostly just reference files.
What I have done so far is fork the adafruit SAMD BSP and added a variant. Since the normal Bossa does not recognize my CPU ID I had to add it and recompile bossa. I also went ahead and made a UF2 style bootloader and a corresponding windows driver with matching PIDs/VIDs. At this point I had a working arduino board, but it still thinks it's a SAMD51, not a SAME51. Asking for anything to do with can leads to missing references, which makes sense since SAMD does not have CAN (but it's in DFPs?)
So finally I decided to edit boards.txt again and change the build flag from -D__SAMD51G19A to SAME51G19A. I also found SAME51 DFP online and added them to arduino/tools/CMSIS-Atmel, but this is just me guessing. I also used the DFP to build the UF2 bootloader previously. This breaks everything and if I had to guess from looking the compiler is missing the DFP and everything is very upset about that.
Earlier I had found a version of what I am after, except for a SAMC21 and not a SAME51. I thought the can peripheral was the same for each, so this should be an easy port besides maybe configuring the gclk since those are different from M0 to M4. If you compare DFPs, both are identical as far as CANBUS is concerned, at least at that level.
But, using this code and the SAMC21 BSP referenced in the readme will compile!
https://github.com/hugllc/samc21_can
Is it something to do with adafruit fork using CMSIS 5.4 and arduino using CMSIS-Atmel 1.2.0?
Thank you in advance for any and all tips!


texts:
I was playing with Vin and a transistor when the arduino got disconnected from my pc and after a few seconds it started to smoke. It wasn't much smoke but enough to panic and disconnect everything. I waited a few minutes and then i plugged it into my pc. The power led and the 13 pin led were on but my pc couldn't recognize my device. In arduino ide i couldn't find the port and the tx and rx leds didn't blink at all. I tried to restart my px, reset arduino, i powered it with a 12v source and i got 12v out on Vin but 0 on 5V and 3V. The 13 pin doesn't want to turn off and my pc doesn't recognize it. It is not a ch arduino and it worked perfectly until i did this. I've benn searching on internet for 2 hours now about this but i still couldn't find something relevant. In device manager it sais "unknown usb device (device descriptor request failed)" and inside proprieties at device status this is written:

"Windows has stopped this device because it has reported problems. (Code 43)

A request for the USB device descriptor failed."

I also tried to update drivers automatically and manual but didn't work. I have no idea where that smoke came from.

Is it dead? can i do anything to make it work?


texts: DC motor with slow speed to actuate mirrors

texts:
I am thinking to use Arduino to control a DC motor and apply a small torque to move the mirrors of my interferometer experiment. I have the components from the Arduino Starter Kit K000007, just to understand how it works because I am approaching it just now.
The mirror mount has a knob with a 2mm Hex hole and each revolution corresponds to a displacement of 50 microns: I would need a speed around 1/50 revolution/second, or even less. Is it possible to move the motor that slow?
Moreover, I should use a coupler to interface the motor with the knob, basically some joint to connect the shaft to a 2mm Hex bar or something: could you suggest a way to do so?


texts: Bad Communication with Multiple I2C Devices

texts:
I have an Arduino Micro connected to two I2C devices. An MPU-6050 that is powered by 5V (though it has its own voltage regulator on it) and a Altimeter that is powered by 3.3V. They are both connected to the SDA and SCL.

I noticed that when I have the MPU powered on but don't power the 3.3V altimeter, the MPU does not communicate with the Arduino. I need to have the 3.3V power on to just communicate with the MPU through I2C. Why does this happen?

Then unfortunately, I believe I may have shorted the 3.3V rail and broke the altimeter. When I remove the MPU from the equation and try to just communicate with the Altimeter, I get nothing. Does this mean that I did short the device, or is there something else going on with I2C that I don't understand?

I have attached a schematic below of how the devices are connected.


texts:
i have an ESP32 and i want to use deepsleep when it's not used. Before sending it to sleep i clean up everything, so disconnect, deinitialize and disable everything i build before. But i get a crash when i try to disable bluedroid. Does anyone have an idea why this happens?
void bt_deinit() {

    Serial.println("Deinit AVRC");
    if (esp_avrc_ct_deinit() != ESP_OK)
        Serial.write("Failed to deinit avrc");

    Serial.println("Deinit A2DP");
    if (esp_a2d_source_deinit() != ESP_OK)
        Serial.println("Failed to deinit a2dp");

    Serial.println("disable bluedroid");
    if (esp_bluedroid_disable() != ESP_OK)
        Serial.println("Failed to disable bluedroid");

    Serial.println("Deinit bluedroid");
    if (esp_bluedroid_deinit() != ESP_OK)
        Serial.println("Failed to deinit bluedroid");

    Serial.println("Stop BT");
    if (btStop() == false)
        Serial.println("Failed to stop bt");
}

output:
Port closed
Uploading to I/O board
Opening port
Port open
Hello there!
Bluetooth init success
good night
Deinit AVRC
Deinit A2DP
disable bluedroid
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:719 (xQueueGenericSend)- assert failed!
abort() was called at PC 0x4008de6f on core 0

Backtrace: 0x40091918:0x3ffce3b0 0x40091b49:0x3ffce3d0 0x4008de6f:0x3ffce3f0 0x4013bfb6:0x3ffce430 0x4013c5f6:0x3ffce460 0x400fdbe2:0x3ffce480 0x400fdc35:0x3ffce4a0 0x400fe12e:0x3ffce4c0 0x400f6bd9:0x3ffce4e0 0x4008e559:0x3ffce510

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Hello there!
Bluetooth init success

it works fine if i just do not deinitialize everything and send him directly to sleep. But this is not the elegant way.


texts: How to operate multiple relay boards using a single RF Remote?

texts: I am working on a Home Automation Project using RF technology. I have to operate more than one switch board or let say more than one relay board, using a single RF remote. Is it possible? And if yes, how to do it using RF and Arduino?


texts: Controlling a flat brushless DC motor with integrated speed controller

texts: I have recently purchased the Brushless DC-Flat Motors Series 2610 from Faulhaber and I am honestly new to this type of motor as it’s pins are not like any other I have used before. I would appreciate any help on how to connect and code this motor to rotate on an arduino using the integrated speed controller in the motor.


texts: Controlling multiple 12v solenoids with 5v relay modules (Arduino Reset Issue)

texts:
I have 4 12V(1A) solenoids running on a 12V(4.16A) power supply.
Each solenoid circuit is controlled by a 5V relay module connected to the Arduino Uno (powered by USB).

The solenoids actuate properly but eventually the Arduino resets, typically when multiple solenoids are turned on/off in fast succession. This is accompanied by random character artifacts on the LCD display (connected to the Uno) during operation but before the reset.

From what I've gathered there are back EMF surges occurring when the solenoids lose their charge. Here are some possible remedies I've found:

Add a flyback diode (IN4004) to each solenoid circuit. (Redirect the surge)
Add a capacitor (4700 - 10,000 uF) to the 5v supply (from the Uno) for the relays. (Filter the surge)
Provide a separate 5v power source to the relay modules instead of using power from the Uno. (Isolate the surge)

Any input on which solution(s) should be applied or other possible causes for the Uno reset and LCD distortion is appreciated.


texts: Connecting Arduino Wifi shield to Arduino Uno based Mcore board

texts:
I am trying to connect this mBot board to an external network, that's why I bought the arduino wifi shield.

I am connecting the wifi shield to the 6pins (5V MOSI GND RST SCK MISO) of the mCore.

Though when uploading any of the Wifi program example, the shield isn't even recognized.

(I've succesfully upgraded the firmware of the shield)

The thing is that I don't really understand how should I plug in the wifi shield on the mCore since I'm struggling to understand the datasheet of the mBot board.

Any advices ?

Regards,

Alex


texts:
I am a complete beginner with very little knowledge. I am trying to do a switch in Arduino UNO using a guide I found on the internet but it won't compile. The servo motor should function if it is switched on loadstate == HIGH. I have no idea what "exit status 1" is or how to fix it, help.

#include <Servo.h>
    Servo myservo;

    int buttonPin = 3;
    int reading;
    int state = 0;
    int Loadstate = 0;

    int pos = 0;
    int trig = 13;
    int echo = 11;

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

    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);
    pinMode (trig ,OUTPUT);
    pinMode (echo ,INPUT);
    myservo.attach(7);

}

void loop() {

    long duration, distance;

    digitalWrite (trig, LOW);
    delayMicroseconds (2);
    digitalWrite (trig, HIGH);
    delayMicroseconds (10);
    digitalWrite (trig, LOW);
    duration = pulseIn(echo, HIGH);
    distance = (duration/2) / 29.1;

      reading = digitalRead(buttonPin);

  if (state == 0 && reading == HIGH){
        state = 1;
        Loadstate = !Loadstate;
  }
  if (state == 1 && reading = LOW){
        state = 0;
  }

  if (Loadstate == HIGH){
      if (distance <= 30 && distance >= 0){
          for (pos = 0; pos<90; pos +=1){

            myservo.write(pos);
            delay(15);
        }

        delay(1000);

          for(pos = 90; pos>=1;pos-=1){
            myservo.write(pos);
            delay(15);
        }
        }
        }
}


texts: SH1106 - Transferring long buffer via SPI

texts:
I am using an SH1106 and am creating my own driver for it. Nearly everything is doing great with about 2/3ms send time using transfer16. I did notice however that I can use transfer with a buffer and length to give a 1ms display time; something that'd be extremely useful.

For reference before here is the datasheet:
http://support.technologicalarts.ca/docs/Components/OLED13-SPI/SH1106.pdf

So the working solution is this:

SPI.beginTransaction(settings);
//
for (int page = 0; page < 8; page++)
{
    digitalWrite(DC, LOW);
    SPI.transfer(0xB0 + page);
    SPI.transfer(0x02);
    SPI.transfer(0x10);
    digitalWrite(DC, HIGH);

    for (int column = 0; column < 128; column += 2)
        SPI.transfer16(buffer[(page * 128) + column]);
}
digitalWrite(DC, LOW);
//
SPI.endTransaction();

This for each of the 8 pages writes the 128 bytes 2 at a time. I want to write the 128 bytes in a single call. This would be something like this:

SPI.transfer(buffer + (page * 128), 128);

This however sort of inverts the display. It literally turns every pixel on for some reason and I can't figure out why. I am just using a few bytes set to 255 for testing and with the original method this works perfect.

Am I using the call wrong? Is there a limit to the buffer size I could use, I haven't really seen anything about that at the moment. I tried changed the pointer arithmetic but wasn't successful. I tried moving the 128 bytes into a temporary location and use that but still nothing.

Obviously this isn't major and maybe I could somehow improve the transfer in other ways but if you have any advice I'd love to have it

----- EDIT -----

I have had some luck now with using the transfer with buffer method when I changed the page datatype to a uint8_t. It also caused a few more issues however and I am not sure what is causing them.

Firstly with a fast display rate the display inverts itself once again with all pixels on.
With a delay between display calls, it works! But after a few seconds those pixels slowly go away, something I have never experienced before.

Here is the edited code:

SPI.beginTransaction(settings);
//
for (uint8_t page = 0; page < 8; page++)
{
    SPI.transfer(0xB0 + page);
    SPI.transfer(0x02);
    SPI.transfer(0x10);

    digitalWrite(DC, HIGH);
    SPI.transfer(buffer + (page * 128), 128);
    digitalWrite(DC, LOW);
}
//
SPI.endTransaction();

It's hard to explain whats actually happening. But without a large delay between the calls of the buffer transfer method the screen freaks out and will maybe invert completely if it's too often. Even with the large delay the pixels randomly vanish over time, something I have never actually seen.

The 2 byte send method doesn't have any of these problems. No delay will work fine.


texts:
A little background:

I need to generate a 40KHz frequency as accurately as possible.

(One of my other posts is here:
Stable frequency generation)

My code is solid- I'm using an Uno R3 and generating the most accurate frequency I can at this point. The only way to get a more accurate frequency is to upgrade the ceramic resonator to a crystal oscillator.

So, my over-arching question is: How do I actually upgrade the ceramic resonator to a crystal oscillator?

Things I'm considering are:

Is it worth it to actually upgrade my Uno R3 - and is it even possible? Is there a clone that drives the ATMega328p with a crystal oscillator that I could use instead? Is there simply just a better model for this application?


texts: Most precise way to measure Linear distance travelled by a wheel

texts:
Suppose a bot with wheels is traveling in a a straight line,and we want to measure this linear distance traversed by it as accurately as possible.
One of the ways is to use an optical encoder to measure the angle of rotation of the wheels and get the linear distance traveled. Another way could be to use the data from accelerometer and get the linear distance traveled. Which of these two methods would be better ? Or,is there a third method which is more precise than the previous two?


texts: ESP8266 requires two resets to wake up from deep sleep

texts:
I'm working with the following circuit using a NodeMCU:
I have the solder jumper bridged between RST and BTN. In addition to what's in the schematic, pins 2, 3, and 4 of J1 are connected to the cathodes of 3 LEDs powered via pin 1 on the same connector.
I'm using the following code to test waking up from deep sleep:
#include <Arduino.h>

void setup() {
  delay(1000);
  Serial.begin(9600);
  Serial.println("start");
  ESP.deepSleep(0);
  while (1);
}

void loop() {
}

I build the code with -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_CORE and observe the following behaviour on the serial port after startup:
SDK:2.2.2-dev(38a443e)/Core:2.7.3-3-g2843a5ac=20703003/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
start
bcn 0
del if1
usl
enter deep sleep␀

This looks as expected to me (except maybe for the trailing ␀?). The current consumption is as low as I'd expect from deep sleep. I now pull RST low by pressing the push button once and see a few bits of garbage (different every time) being output in the device monitor - nothing else happens:
SDK:2.2.2-dev(38a443e)/Core:2.7.3-3-g2843a5ac=20703003/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
start
bcn 0
del if1
usl
enter deep sleep␀␀�

At this point current consumption increases from single-digit milliamps to a few tens of milliamps. However, a full reset doesn't seem to happen and my program doesn't appear to execute again from the beginning.
If I now pull RST low again with a second press of the push button I see a bit more garbage being output before a proper reset seems to finally happen:
SDK:2.2.2-dev(38a443e)/Core:2.7.3-3-g2843a5ac=20703003/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
start
bcn 0
del if1
usl
enter deep sleep␀␀�␕{��1S�
SDK:2.2.2-dev(38a443e)/Core:2.7.3-3-g2843a5ac=20703003/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
start
bcn 0
del if1
usl
enter deep sleep␀

This cycle then repeats, always requiring two button presses for a reset.
Similarly, if I try to upload a new program to the ESP8266 after it entered deep sleep initially, the upload will fail with:
A fatal error occurred: Timed out waiting for packet header
*** [upload] Error 2

Trying the upload again right after that does succeed. The next upload after that will fail again, and so on.
Based on those observations it looks to me like the ESP8266 doesn't get fully reset on the first button push, or it does get reset but enters some state in which it's not executing my application for some reason.
What could be the reasons for that? Is it something I can work around either in hardware or code?
Thanks!