text:
Program NOT responding to loop()- Arduino UNO+GSM + Sensor
I'm trying to monitor the sensor values (range 0-1000) connected to Arduino UNO's 12th-pin. If the value stays below say 500, then it should SEND SMS. I tested the sensor and GSM shield seperately and both of them are working fine. But my program is not giving the sensor reading in the serial monitor nor sending the SMS. I'm pretty sure it got stuck at sendRequest() part of the code.
// the setup routine runs once when you press reset:
#include "Adafruit_FONA.h"

#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 4

// this is a large buffer for replies
//char replybuffer[255];
char buffer[50];
char r[15];
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX,FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
SoftwareSerial Sensor_Serial(12,13);

// Hardware serial is also possible!
//  HardwareSerial *fonaSerial = &Serial1;

// Use this for FONA 800 and 808s
//Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Use this one for FONA 3G
Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

uint8_t type;

byte readCO[] = {0xFF, 0X01, 0X86, 0X00, 0X00, 0X70};
byte response[] = {0,0,0,0,0,0};

//multiplier for value. default is 1.
int valMultiplier = 1;

void setup() {
  while (!Serial);

  Serial.begin(9600);
  Sensor_Serial.begin(9600);    //Opens the virtual serial port with a baud of 9600
  Serial.println(F("FONA basic test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  type = fona.type();
  Serial.println(F("FONA is OK"));
  Serial.print(F("Found "));
  switch (type) {
    case FONA800L:
      Serial.println(F("FONA 800L")); break;
    case FONA800H:
      Serial.println(F("FONA 800H")); break;
    case FONA808_V1:
      Serial.println(F("FONA 808 (v1)")); break;
    case FONA808_V2:
      Serial.println(F("FONA 808 (v2)")); break;
    case FONA3G_A:
      Serial.println(F("FONA 3G (American)")); break;
    case FONA3G_E:
      Serial.println(F("FONA 3G (European)")); break;
    default:
      Serial.println(F("???")); break;
  }

}
void loop()
{
    sendRequest(readCO);
    float valCO = getValue(response);
    static unsigned long startTime = 0;
    if (valCO < 500)

   dtostrf(valCO, 3, 2, r); // I don't know how to covert the unsigned long variable to string and I know //this part does the float to string conversion
    sprintf(buffer, "%s High  Level", r);
    Serial.print("CO  = ");
    Serial.println(valCO);
    if (millis() - startTime > 1UL*60UL*1000UL) {  // Has it been 1 minute since the value was below 500?

      startTime = millis();
      fona.sendSMS("0XXXXXXX", buffer);
     }
  }

void sendRequest(byte packet[])
{
  while(!Sensor_Serial.available())  // If this part works the entire code works I think!!
//keep sending request until we start to get a response
  {
    //Sensor_Serial.write(readCO,9);
    delay(50);
  }

  int timeout=0;  //set a timeoute counter
  while(Sensor_Serial.available() < 9 ) //Wait to get a 9 byte response
  {
    timeout++;
    if(timeout > 10)    //if it takes to long there was probably an error
      {
        while(Sensor_Serial.available())  //flush whatever we have
          Sensor_Serial.read();

          break;                        //exit and try again
      }
      delay(50);
  }

  for (int i=0; i < 9; i++)
  {
    response[i] = Sensor_Serial.read();
  }
}

unsigned long getValue(byte packet[])
{
    int high = packet[2];                        //high byte for value is 3rd byte in packet in the packet
    int low = packet[3];                         //low byte for value is 4th byte in the packet

    unsigned long val = high*256 + low;                //Combine high byte and low byte with this formula to get value
    return val* valMultiplier;
}

OUTPUT:
.
.
.
.
FONA is OK
Found FONA 3G (European)
    ---> AT+GSN
    <--- 8XXXXXXXXXXXXXX
Module IMEI: 8XXXXXXXXXXXX
I guess this part of the is waiting for like ever and not returning any response
while(!Sensor_Serial.available())  //keep sending request until we start to get a response
  {
    Sensor_Serial.write(readCO,9);
    delay(50);
  }

Any help guys?

If I was you I would add a few more print statements to your code to prove that's where it is stopping.  It might be worth checking if pins 12 and 13 are reserved by the shields for something.

Yes inside the while loop it printed a statement.  I mean after  Sensor_Serial.write(readCO,9); Serial.print("CO ppm = "); OUTPUT: I can see the CO ppm=  and I have tested myself pin 12 and 13 they don't seem reserved by the GSM as I got the sensor output. But the code doesn't seem to work with the UART and SMS together...

You have multiple software serial ports and are expecting them to work like real ones.
They don't.
You can only have one of them "active" at a time (that is, ready to receive data). You need to switch between them with Sensor_Serial.listen() and fonaSerial->listen().
In general it is bad to have more than one SoftwareSerial (and personally I think even one is bad) since they are very heavyweight and block all other operations while they are either sending or receiving data (which means your listening one cannot operate at all while your non-listening one happens to be sending).
If you have a requirement for more than one serial port you should really be using a board that has more than one serial port.

In that case, to not use software serial ports I tried one of the four UART's on Arduino Mega for sensor. Can please tell me how do I connect my sensor to the RX0 and TX0. As I have tried assigning sensor pins as: SoftwareSerial Sensor_Serial(0,1); But that didn't make any difference. Please, any fix for this line of code as it is stopping the functioning of sensor's part - while(!Sensor_Serial.available())  as nothing works from this part on.

If you are using a real serial port then you do not try and map it to SoftwareSerial.  I believe T/Rx0 are called Serial, T\Rx1 is called Serial1 etc.

@LD_959 Firstly: do not use pins 0/1 - they are used by your existing Serial connection. Secondly: you must not use SoftwareSerial on pins you expect to be using as a real UART. That is just plain daft. Why use hardware serial pins as GPIO and then slap SoftwareSerial over the top? All UART pins have SerialX objects assigned to them. TX0/RX0 is Serial, TX1/RX1 is Serial1 etc.

Using Serial1 for the sensor worked perfectly. Thank you guys...!!

I have 3 sensors connected to other UART's of Arduino.. can you please tell me how do I print the output sensor readings in this format: CO1= val1   CO2=val2   CO3=val3

With multiple Serial.print() calls.


text:
When uploading a sketch to an esp8266, isn't that the same as "flashing firmware"?
I thought that I read that using a PC running the Arduino IDE to "upload a sketch" to an esp8266 overwrites the original firmware (with the AT commands), and is actually "flashing the firmware" each time a "sketch" is uploaded. If I have that right, then why does the esp8266 WiFi still visible in available connections? There must be some code instructing the esp8266 to do this, but where is it? My sketch was simply the hello blinky thing and contained no #include statements. Where have I slipped?

Uploading a "sketch" is indeed "flashing firmware".

why does the esp8266 WiFi still visible in available connections?

I'm not sure what you mean by that.

Sorry, poor grammar. Should have been "...then why IS the esp8266 still visible..."  And by "available connections" I mean the list of access points within range of the WiFi enabled device being used. Like on my PC there's a WiFi icon in the system tray which I click on when looking to join a network. I don't know what that menu list is called.  Anyway I'm puzzled as to how my esp8266 would still show up on that list even after the original AT commands firmware was overwritten by my little "sketch".  I assume there must be some code somewhere making that happen, and I'm curious to understand.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Alternative for IRF520 mosfet in Arduino shutdown schema
I’am using IRF520 mosfet according to this schema to shut down Arduino by low level on output to 10K ohms resistor
Schema of my device is

The issue is that IRF520 took too much place
Is it possible to substitute IRF520 with smaller mosfet?
Additional info:
I measured average power consumption – it’s about 22 mA on 12V = 0.264W
IRF520 is for 70W max according to datasheets.
The base schema is

check out irlz44n much better option.

For what you are trying to do, any transistor, bjt or MOSFET, would work. 2n2222 or 7000 for example. Irf5x0 is actually a poor choice here. It only worked due to the low load being switched.

I going try 2N7000 - http://www.futurlec.com/Transistors/2N7000.shtml, since 200mA should be enought for my schema. What do you think about resistors? Should I change them or I can left 10K and 120K?

That transistor has a very high R_DSON. You should be looking for sub-ohm resistances.

@Majenko I'm not very good with mosfets, should I increase resistance of R1 or R2 for 2N7000?

No. Choose a different mosfet with a lower resistance.

No need to increase r1 r2. If anything they are already too big. 2n7000 or 2n7002 if you want even smaller devices is more than adequate for your application. Its rds is 6ohm max and if you look at the id vs. Vds chart it is even smaller for a Typical 2n7000. So people arguing for its high rds are reading the spec without understanding it.

I'll try 2N7000 and 2N7002, thanks. What do you think how much I should decrease R1 and R2 to make them work in my schema instead of IRF520?

R1 is there to prevent ringing / overloading the mcu and R2 to help bleed off the charge on the gate. they are useful only for high speed switching on big mosfet. the typical value for R1 is in the <10R range (with a driver). and R2 <1K. If you are switching at high speed (100Khz or over and pushpull), I would consider putting a 47 - 110R as R1 and go without R2.

After picking of the resistors I found that 2N7000 working well for my case with R1 = 10K and R2 = 5.6K. Also 2N7002 is a compact version of 2N7000 for surface mount. I will update my question by this information, thanks

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Slower nRF24L01 round trip delay than expected
Short/summary
I expected that the round trip delay of a nRF24L01+ would be less than 1 ms. In practice I see around 3 to 5 ms and other sources have similar values. Does anybody know why this round trip delay is so long?
In short: nRF24L01+, adapters for them, tmrh20 RF24 library, 16 byte payload, highest speed.
Below is the full problem and related info.
Problem description
I received my nRF24L01+ radios and they work much better so far than my 433 MHz radios.
However, still with my nRF24L01 I get response times which are much lower than I expected.
I used the sketch of Example using dynamic payloads (which I increased to 16). The library I use is from tmrh20.github.
I also reduced the characters written to serial (and increased it to 250K) and some other small changes.
Transmitter code
Below is the code for the transmitter (manually removed receiver code and role switching code since that works/was not used except for first time)
/*
   Dec 2014 - TMRh20 - Updated
   Derived from examples by J. Coliz <maniacbug@ymail.com>
   http://tmrh20.github.io/RF24/pingpair_ack_8ino-example.html

   Results:
  PA                          MAX
  Retries                    2,8   2,4   2,8
  AutoAck                     True       False True
  EnableAckPayLoad            True
  PayLoadSize                  16          16    8   32
  DynamicPayLoad              True                        False True
  CRC Length                   16                                 8

  Failures / 25 iterations     0-1  3-4  ???         24??

  write min [us]              812    (792)    625         652   644
  write avg [us]              2618           2106              2251
  write max [us]              6224   (804)   5756        5756  7724

  logdata[m][n] = millis()       4                  us
  write:                       812..6224 (avg 2617) us
  available:                    28..  32            us
  read                         100                  us
*/
#include <SPI.h>
#include "RF24.h"

RF24 radio(7, 8);
uint32_t counter = 0;

static const int NR_OF_LOG_ITEMS = 10;
static const int LOG_LENGTH = 25;
uint32_t logData[LOG_LENGTH][NR_OF_LOG_ITEMS];
uint8_t currentLogLine = 0;

void setup()
{
  for (int m = 0; m < LOG_LENGTH; m++)
  {
    for (int n = 0; n < NR_OF_LOG_ITEMS; n++)
    {
      logData[m][n] = -1;
    }
  }

  Serial.begin(250000);
  Serial.println(F("TRANSMITTER SPEED TEST"));

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setRetries(2, 8);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.setPayloadSize(16);
  radio.enableDynamicPayloads();
  radio.setCRCLength(RF24_CRC_16);

  byte addresses[][6] = {"1Node", "2Node"};
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1, addresses[1]);
  radio.startListening();

  radio.writeAckPayload(1, &counter, 16);
  //radio.printDetails();
    radio.stopListening(); // Takes 336..348 us

}

uint32_t response = 0;

void loop(void)
{
  uint32_t response;

  uint32_t time = micros();
  logData[currentLogLine][1] = micros();

  if (radio.write(&counter, 16))
  {
    logData[currentLogLine][2] = micros();
    if (!radio.available())
    {
      logData[currentLogLine][3] = micros();
      Serial.print(F("Got blank response. round-trip delay: "));
      Serial.print(micros() - time);
      Serial.println(F(" microseconds"));
    }
    else
    {
      logData[currentLogLine][4] = micros();
      while (radio.available())
      {
        logData[currentLogLine][5] = micros();
        unsigned long timer = micros();
        radio.read(&response, 16);
        logData[currentLogLine][6] = micros();
        logData[currentLogLine][7] = response;
        logData[currentLogLine][8]++;
        Serial.print(F("Got response "));
        Serial.print(response);
        Serial.print(F(" round-trip delay: "));
        Serial.print(timer - time);
        Serial.println(F(" microseconds"));
        counter++;
      }
    }
  }
  else
  {
    logData[currentLogLine][9] = micros();
    Serial.println(F("Sending failed."));  // If no ack response, sending failed
  }

  if (counter == LOG_LENGTH)
  {
    for (int m = 0; m < LOG_LENGTH; m++)
    {
      Serial.print("Location ");
      Serial.print(m);
      Serial.print(": ");
      for (int n = 0; n < NR_OF_LOG_ITEMS; n++)
      {
        Serial.print(logData[m][n]);
        Serial.print("  ");
      }
      Serial.println("");
    }
  }
  currentLogLine++;

  delay(100);  // Try again later
}

Receiver code
Below is the code for the receiver (manually removed transmitter code and role switching code since that was not used)
/*
   Dec 2014 - TMRh20 - Updated
   Derived from examples by J. Coliz <maniacbug@ymail.com>
*/
#include <SPI.h>
#include "RF24.h"

RF24 radio(7, 8);
uint32_t counter = 0;

void setup() {

  Serial.begin(250000);
  Serial.println(F("RECEIVER SPEED TEST"));

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setRetries(2, 8);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.setPayloadSize(16);
  radio.enableDynamicPayloads();
  radio.setCRCLength(RF24_CRC_16);

  byte addresses[][6] = {"1Node", "2Node"};
  radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);
  radio.startListening();

  radio.writeAckPayload(1, &counter, 16);
  //radio.printDetails();
}

void loop(void)
{
  byte pipeNo = 0;
  uint32_t response = 0;
  while ( radio.available(&pipeNo))
  {
    radio.read( &response, 16);
    // Since this is a call-response. Respond directly with an ack payload.
    response++;
    radio.writeAckPayload(pipeNo, &response, 16); // This can be commented out to send empty payloads.
    Serial.print(F("Loaded next response "));
    Serial.println(response);
  }
}

Resulting log fragment
Below are the results:
TRANSMITTER SPEED TEST
Got response 26 round-trip delay: 1960 microseconds
Got response 1 round-trip delay: 1964 microseconds
Got response 2 round-trip delay: 876 microseconds
Got response 3 round-trip delay: 880 microseconds
Got response 4 round-trip delay: 1960 microseconds
Got response 5 round-trip delay: 4128 microseconds
Got response 6 round-trip delay: 6296 microseconds
Got response 7 round-trip delay: 880 microseconds
Got response 8 round-trip delay: 884 microseconds
Got response 9 round-trip delay: 3044 microseconds
Got response 10 round-trip delay: 880 microseconds
Got response 11 round-trip delay: 880 microseconds
Got response 12 round-trip delay: 884 microseconds
Got response 13 round-trip delay: 876 microseconds
Got response 14 round-trip delay: 1964 microseconds
Got response 15 round-trip delay: 1956 microseconds
Got response 16 round-trip delay: 4128 microseconds
Got response 17 round-trip delay: 3044 microseconds
Got response 18 round-trip delay: 4128 microseconds
Got response 19 round-trip delay: 1964 microseconds
Got response 20 round-trip delay: 4124 microseconds
Got response 21 round-trip delay: 8452 microseconds
Got response 22 round-trip delay: 880 microseconds
Got response 23 round-trip delay: 1960 microseconds
Got response 24 round-trip delay: 884 microseconds
Location 0: 4294967295  12328  14216  4294967295  14248  14280  14384  26  0  4294967295
Location 1: 4294967295  115260  117152  4294967295  117184  117216  117316  1  0  4294967295
Location 2: 4294967295  218152  218956  4294967295  218988  219020  219120  2  0  4294967295
Location 3: 4294967295  319916  320728  4294967295  320760  320788  320888  3  0  4294967295
Location 4: 4294967295  421684  423576  4294967295  423608  423636  423736  4  0  4294967295
Location 5: 4294967295  524572  528628  4294967295  528660  528692  528792  5  0  4294967295
Location 6: 4294967295  629624  635844  4294967295  635876  635912  636012  6  0  4294967295
Location 7: 4294967295  736844  737660  4294967295  737688  737720  737820  7  0  4294967295
Location 8: 4294967295  838616  839428  4294967295  839460  839492  839592  8  0  4294967295
Location 9: 4294967295  940388  943364  4294967295  943396  943424  943524  9  0  4294967295
Location 10: 4294967295  1044356  1045168  4294967295  1045200  1045232  1045332  10  0  4294967295
Location 11: 4294967295  1146168  1146980  4294967295  1147012  1147040  1147140  11  0  4294967295
Location 12: 4294967295  1247972  1248784  4294967295  1248816  1248848  1248948  12  0  4294967295
Location 13: 4294967295  1349784  1350588  4294967295  1350620  1350652  1350756  13  0  4294967295
Location 14: 4294967295  1451592  1453484  4294967295  1453516  1453548  1453648  14  0  4294967295
Location 15: 4294967295  1554524  1556412  4294967295  1556440  1556472  1556580  15  0  4294967295
Location 16: 4294967295  1657448  1661508  4294967295  1661536  1661568  1661668  16  0  4294967295
Location 17: 4294967295  1762544  1765516  4294967295  1765548  1765580  1765680  17  0  4294967295
Location 18: 4294967295  1866552  1870612  4294967295  1870640  1870672  1870772  18  0  4294967295
Location 19: 4294967295  1971648  1973540  4294967295  1973572  1973604  1973704  19  0  4294967295
Location 20: 4294967295  2074580  2078636  4294967295  2078668  2078696  2078804  20  0  4294967295
Location 21: 4294967295  2179680  2188060  4294967295  2188092  2188124  2188224  21  0  4294967295
Location 22: 4294967295  2289096  2289912  4294967295  2289940  2289972  2290072  22  0  4294967295
Location 23: 4294967295  2390904  2392800  4294967295  2392832  2392860  2392960  23  0  4294967295
Location 24: 4294967295  2493832  2494644  4294967295  2494676  2494708  2494808  24  0  4294967295

And here some processed (with Excel) results:
    write   available   available   read
    us  us  us  us
    1..2    2..4    4..5    5..6

    4060    32  28  100
    816 32  28  100
    6224    32  32  100
    2980    32  28  100
    1896    32  28  100
    816 32  32  100
    1896    32  32  100
    812 32  32  100
    2976    32  32  100
    2976    32  32  100
    816 28  32  100
    4060    32  32  100
    816 32  28  100
    4060    28  32  100
    816 32  32  100
    816 28  32  100
    1896    32  32  100
    5140    32  28  100
    6220    32  36  100
    816 32  32  100
    4060    32  32  100
    2980    28  32  100
    4060    32  28  100
    816 32  28  100

min     812 28  28  100
avg     2617.666667 31.33333333 30.83333333 100
max     6224    32  36  100

The main chunk is the write which takes 812..6224 us (with an average of 2617 us). Probably this big variance is due to retries, but still the lowest 812 us is more than expected:
Summary of results
I did some more tests, I will not put all log/intermediate results here, but the following table shows some tests:
  PA                          MAX
  Restries                    2,8   2,4   2,8
  AutoAck                     True       False True
  EnableAckPayLoad            True
  PayLoadSize                  16          16    8   32
  DynamicPayLoad              True                        False True
  CRC Length                   16                                 8

  Failures / 25 iterations     0-1  3-4  ???         24??

  write min [us]              812    (792)    625         652   644
  write avg [us]              2618           2106              2251
  write max [us]              6224   (804)   5756        5756  7724

  millis()  [us]                4
  available [us]              24/32
  read      [us]               100

Conclusion of results

Changing the number of retries lower than 2 (= 500 us), 8 (retries) results in too many errors, and does not lower the minimum, just the maximum, but with errors so useless
AutoAck always returns in 7u92-804 us, but I need AutoAck in my project
Changing payload to 8 results in a minimum of 625 us
Changing payload to 32 resulted in too many errors
Disabling dynamic payload resulted in a minimum of 652 us
Changing CRC length to 8 results in 644 us

Expectations
When I use the calculation in the datasheet, I come to the following results:
Datasheet  https://www.nordicsemi.com/eng/nordic/download_resource/8765/2/84238108/2726
Table 15
                Item                          Value Unit    Item              Value Unit
T_OA            Time on-air                 0.0001005 s     Preamble              1 byte
T_ACK           Time on-air Ack             0.0001005 s     Address               5 bytes
T_UL            Time upload                 0.000512  s     Payload              16  bytes
T_ESB           Time Enh Shock-Burst Cycle  0.0008785 s     CRC                   2 bytes
Back and forth?                             0.001757  s     packet Control field  9 bits
                                                            Air data rate   2000000 bits/s
                                                            SPI data rate    250000  bps  (guess)
                                                            T_stby2a        0.00013 s
                                                            T_IRQ          0.000006  s

According to the formulas, I would get around 0,875 ms (probably one way) and about double back-and-forth. Btw, I don't understand why T_OA is not in the formula.
However, I get as minimum 0,812 which may be some rounding/timing inaccuracy.
Conclusion
The retries are causing the longer writes. The minimum is similar to the calculated value from the datasheet.
Question

Home come there are so many retries?
Should I check for noise on channels?

Background
What I hoped for was to send a 32 (but 16 is ok too) byte message, than after 5 ms another message, and have the ack of the second message back within like 6 ms or so (including the 5 ms delay between the first and second message to be sent). This means the sending and receiving of an ack should take about 1 ms (which is well within the 0,256 ms calculated above).
Setup
Note my Uno's with nRF24L01 are about 1 meter apart, settings: 2 mbps, set retries(2, 4), enable ackpayload/dynamic payloads.
RF Radio hardware
The RF radios I'm using are nRF24L01+ like this:

Datasheet: PDF Download
Update: I see people use various capacitors and/or a voltage regulator.
I did not do that, but I have a an adapter from 5V->3.3V specifically for the nRF24L01 (like this). I think there is already a voltage regulator and needed capacitors on this board. As far as I know the IC on the adapter is the voltage regulator and the capacitor (one) is probably just above the GND/VCC connection in the picture above. Or a second capacitor left of the MI/IRQ

Results

You are not new here, so it should beyond obvious to you by now that this is unanswerable without your code.

@ChrisStratton I added the code (and indeed, it was not a good idea to link to the code and manually write some differences. So I added the code for the transmitter and receiver (but manually removed code that was not used/needed to make a 'minimal' code example.

Might want to check the actual frame size. There are a lot of "extra bits"; preamble, address, control, check-sum and there is also the PLL lock time to consider. Need a link to the manual :)

You might want to update the code so that the call to micros(), 32-bit calculation, number to string conversion and Serial print is included. Measure first-print after.

@MikaelPatel I will check into that ... there might be more bytes than expected, also I added a link to a datasheet: http://www.nordicsemi.com/eng/nordic/download_resource/8041/1/45228426

@MikaelPatel ... but I will try first myself, also with changing the measuring (I don't need necessarily the conversion of bytes and calculations, since in my 'real'  program there are other calculations needed (much more, but hopefully not more than 1 ms).

@MikaelPatel: According to par 7.3 from the datasheet the preamble is 1 byte, addres 5 bytes (max), packet control field 9 bits, crc 1-2 bytes, so in total 9 bytes + 1 bit ... however I see there are some calculations which I'm going to do this evening when I have more time to add to the question above.

radio.enableAckPayload();
Disabling ack (or well, not enabling it) will improve the speed of transmission.

@Avamander I know, but I need the acks (or I have to change the roles, which also takes a lot of time).

Disable (or don't enable) dynamic payloads then?

I'm going to do some tests with that too (although I might need dynamic payloads eventually).

@Patel: I checked the datasheet and seems my minimum is very much like the calculated value from the datasheet :-) ... the retries is the problem now.

@Avamander That saves a bit, but I may also need it in my project (see number under summary/conclusion of results)

Could the last answer in this post give you a lead?
https://forum.arduino.cc/index.php?topic=171611.0

@MatsK well I found that the times I get are very similar to the table above that answer, so I cannot expect more from it. There are already capacitors on the adapter board, however, when I will use a 3.3V AVR I will use the capacitor like that answer (Adding 100uF).


text:
How to declare and use "Variabled arrays" inside arrays
Good day folks. I'm new here and have been starting to be enthusiast in Arduino. I have a problem and I don't know what I should do, or whether I did something wrong regarding an array of arrays. Surfed on the internet to find a bunch of examples but the only difference is that they don't use arrays that have been declared to have a name inside array.
Every array inside array I see that works is like this:
byte array[2][4] = { {1,2,3,4}, {5,6,7,8} };
Serial.println(array[0][2]); is equal to '3'.

But mine is like this:
byte arrayX[4] = {1,2,3,4};
byte arrayY[4] = {5,6,7,8};

byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

Serial.println(arrayX[2]); is equals to '3'.
Serial.println(arrayZ[0][2]); is equal to '0'.

Why?
Below is what in reality I am experiencing. I hope someone can try this out too.
softAddr = cycle * 2;

is an expression I used for looping where cycle is the iterated variable
for (byte cycle = 0; cycle < 7; cycle++) {}

I did a simple simulation and I guess the way I initialize the parent array, it initializes a new array in the name same from the declared variables but separate.
byte arrayX[4] = {1,2,3,4};
byte arrayY[4] = {5,6,7,8};

void setup() {
  Serial.begin(9600);
  byte glass[2][4] = {arrayX[4], arrayY[4]};
  Serial.print(F("OLD 1: ")); Serial.println(arrayX[0]);
  Serial.print(F("OLD 2: ")); Serial.println(arrayX[1]);
  Serial.print(F("NEW 1: ")); Serial.println(`glass[0][0]`);
  Serial.print(F("NEW 2: ")); Serial.println(`glass[0][1]`);
}

output:

OLD 1: 1
OLD 2: 2
NEW 1: 0
NEW 2: 0

//answered realized
I forgot that the array I put inside the array already had its data based on its index and the [4] resulted to nothing or 0 since there is no value at index [4] (knowing, indexes where 0, 1, 2, 3 on a 4 sized array). I realized this after I made a simple loop declaration not instantly like this:
byte arrayZ[2][4] = { arrayX[1], arrayY[1] };

But like this:
byte arrayX[4] = {10,11,12,13};
byte arrayY[4] = {20,21,22,23};
byte arrayZ[2][4];
void setup() {
  Serial.begin(9600);
  for (byte parent = 0; parent < 2; parent++) {
    for (byte child = 0; child < 4; child++) {
      if (parent == 0) {
        arrayZ[parent][child] = arrayX[child];
      } else {
        arrayZ[parent][child] = arrayY[child];
      }
    }
  }
  for (byte parent = 0; parent < 2; parent++) {
    for (byte child = 0; child < 4; child++) {
      Serial.print(F("value: ")); Serial.println(arrayZ[parent][child]);
    }
  }
}

Output:

value: 10
value: 11
value: 12
value: 13
value: 20
value: 21
value: 22
value: 23

Resulting in simply like this:
byte arrayZ[2][4] = {
  {arrayX[0],arrayX[1],arrayX[2],arrayX[3]},
  {arrayY[0],arrayY[1],arrayY[2],arrayY[3]}
};

done a simple edit on post

I don't see the point in this? You're just re-naming variables here. Waste of memory.

Something is wrong with your type description:
byte arrayX[4] = {1,2,3,4}; byte arrayY[4] = {5,6,7,8};

byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

Serial.println(arrayX[2]); is equals to '3'.
This is normal ... arrayX[0] = 1, arrayX[1] = 2, arrayX[2] = 3
However, the next one is not good:
byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

You are declaring a byte array, but you add arrayX[4] and arrayY[4] which, where arrayX[4] is the 5th elements of arrayX but it has only 4 elements, so it points to memory outside the array (probably into the next array.
byte arrayX[4] = { 1, 2, 3, 4 };
byte arrayY[4] = { 5, 6, 7, 8 };

byte* arrayZ[2] = { arrayX, arrayY };

Serial.print(arrayZ[0][2]);

This should print 3 (not tested).

just got realized that one also :D thank you for your answer

You're welcome (please upvote if it helped you)

yup already did (^_^)b


text:
Arduino: Digitally Muti-Switch - What is the proper term for hardware?
I have recently purchased a RoboMower. Like most of the automated mowers these use electric-fence wiring to mark the borders of the property and keep a small charge on those wires so that the mower can tell where the borders are. The  RoboMower I purchased is rated for 3/4 of an acre and I have 2.25 acres to mow.
As a result I was thinking of breaking my yard into multiple 3/4 or less acre zones and using an Arduino to shift which zone is active/has current in it so that the mower would follow those boundaries. The base station would be in a place where all zones overlapped slightly. Based on what day of the week it was, the Arduino would activate the proper zone, and the mower would go out and mow in that zone because it was active. I'd clearly have to schedule this so that the switch did not happen when the RoboMower was actively mowing or it would cause all sorts of issues.
In any case, my question is: What is the hardware called that I would need in order to activate one zone or the other? Is that called a digital switch or something else? Is there such a thing of one switch that would be able to switch multiple zones, or would I basically need a bunch of switches to individually control each zone?
Each zone is a loop of wire and therefore there would not be any shared wires between the zones.

The technical term of what you're looking for is demultiplexer. Note that the demux itself will not be enough to activate the zone, it will simply allow you to choose between different zones based on its input. It is still up to you to provide any further electronics required to enable the appropriate zone.


text:
AT+HTTPACTION: What is status 606 means?
I use Sim808 gprs/gsm/gps module and call these:
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","internet"
AT+SAPBR=1,1
AT+SAPBR=2,1
AT+HTTPINIT
AT+HTTPSSL=1
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","https://www.mywebsite.com/getTime?token=jsdaljdaskl"
AT+HTTPPARA="REDIR",1
AT+HTTPACTION=0

I always get +HTTPACTION: 0,606,0 as the result.
What does 606 mean? I cannot find it everywhere in the documentation.

The only 606 I can see is an SSL error. Maybe you have an invalid certificate on your site. Try with other sites.

"606 SSL  alert  message  with  a  level  of  fatal  result  in
the immediate termination of the connection" https://cdn-shop.adafruit.com/datasheets/SIM800+Series_SSL_Application+Note_V1.00.pdf

Read here pdf file, exist thi error 606 and error 605 [https://cdn-shop.adafruit.com/datasheets/SIM800+Series_SSL_Application+Note_V1.00.pdf][1]


text:
Writing int/long on Sd card
I'm working on a project with SDcard, and I would like to write int and long in a file.
If I try to write 0x1954 I had 0x5419 on my file with file.write() so I did a circular shifting like:
  data=(data<<8)|(data >> (16-8)); //circular shift
  file.write((char*)&data,sizeof(data));

But with a long, I have 0x54195521 on my file instead of 0x19542155.
So I don't know how to fix this. If you have any idea, I would like to read it ! (Or another way to do it)
Thanks !

Finally, after some searchs on internet, to have the maximum writing speed, I choose to keep the original writing and post-process it in Matlab. Thanks for your help !

Please don't add "thank you" as an answer. Instead, accept the answer that you found most helpful.  - From Review

(Its not circular shifting, its bit shifting, the bits don't go round in a circle they disappear off the end and are lost forever.)
So in the library you are using you are writing bytes to the SD Card.
If you write the data 0x1954 on the card you get 0x5419.
So what is happening is you are writing the least significant byte followed by the most significant.  This is because you have take your int 0x1954 and cast it to a char[2] which contains c[0] = 0x54 and c[1] = 0x19  and then you write that out in the order c[0]c[1] et voila you have reversed you number.
The solution is to reverse the buffer before you write it:
char tmp = buf[0];
buf[0] = buf[1];
buf[1] = tmp;

HOWEVER - If you are only reading and writing from this code, who cares.  As long as you read it in backwards does it matter how it is stored on the SD Card?

I'm not only reading and writing from this code, I will read my file with matlab later

@bouaaah - OK, didn't want you wasting time on it if it didn't matter. :)

Sry i not finished my comment and can't editing it so here is the full comment:
(I don't lost my bits because I'm doing a right shift on MSB and left shift on LSB, so it's like a circular shifting)
I'm not only reading and writing from this code, I will read my file with matlab later.
And if i want to reverse the buffer like you did, it's only 3 lines for a int but for a long it will be 6 lines at least. And i need to be as fast as possible so i prefer to work with bits shifting/masking instead of writing/reading a temp variable.

but if it's the only solution i will do by this way ;)


text:
Burning Arduinos one after another
I very accidentally caused a short-circuit to two completely different cheap (under 4$ each) Arduino Uno clones, rendering Windows sound alert for unplugged USB several times.
This subsequently led to a problem with uploading code and not blinking green light on reset on both the Arduinos. Now, I am aware what this means but I am unable to see why this happens. I thought it has protection against that.
Is it normal for them to react like that so easily? How can I prevent this happening AGAIN?

There are companies who sell "ruggedised" Arduino clones that are designed to withstand most bad things you can reasonably do to them without actively trying to break them. One I've had particular luck with is the Ruggeduino. Dunno if that's still sold, but just google it.

DO NOT use the Arduino-UNO tag for other boards, and doubly so when the differences are likely related to the problem.

Which boards? What did you short-circuit exactly? An output pin to ground? See Have I bricked my Arduino Uno? Problems with uploading to board - possibly the board can still be used in some capacity.

Beware there is the danger of frying your computer's usb ports with a short circuit (like I did a few days ago..)

@NickGammon I didn't realise you were on here - the articles on your site taught me a tonne! I should spent some more time here; Arduino + Stack Exchange sounds like heaps of fun! :D

From the title, I was expecting a question about the health & safety hazards of placing dozens of arduinos side-by-side and igniting them like a chain of dominos.

@ChrisStratton we should replace the Uno tag with atmega 328, then.

Stop causing short circuits. Fear the vibrating electrons. It helps if you shock yourself immediately after.

@tuskiomi - no, that would be equally wrong. The problem is with the USB interface, or the power supply, probably not the ATmega328.

@ChrisStratton you and I both know that there is not enough detail in this question do make such deductions.

@tuskiomi - untrue. The windows behavior is cased by a USB chip or power failure, not an ATmega328 failure.  Windows will be quite happy with no ATmega328 even present on the board.  Reality is that the CH340 is notorious for failing in this way, which strongly suggests that is what the poster has - technically not an "uno" clone at all.

@Edenia, It would be useful if you added a link to the exact boards you bought and also posted your schematic.

I thought it has protection against that.

Genuine Arduinos do have some protection, yes.

Is it normal for them to react like that so easily?

Cheap rubbish? Sure. You get what you pay for.

How can I prevent this happening AGAIN..

Buy a real one. Also be more careful.
But at the price you pay for cheap clones, do you really care if they end up broken? You can buy many clones for each genuine one, and while a genuine one may last longer, when you do manage to kill it (they aren't that much more rugged, but some components are more reliable, such as the USB interface chip), which you seem adept at, you would be far more upset than if you'd killed a clone.
So I would suggest invest in one Genuine one for special projects, and to support Arduino (if no one buys Genuine boards there will be no Arduino), and a pile of clones that you can experiment and learn with. Blow them up at will, and when you are happy with your project transfer it over to the genuine board for showing off to people.

I agree, although I think also for learning it might be better to use cheaper ones than burning real ones (although they have more protection). So far I burnt one and that was a genuine one (after putting it in a case and used a 12V adapter).

That is fine if you are going to treat them as a disposable item. Use it a few times and throw it away. Personally I have two Uno R2 boards that I have had for many years and treated them like crud. They will work well.

Actually I do, at least for now, until I'm getting more confidence in my electronics knowledge ... of course I try to be regularly safe. But it's always a trade off - buying a decent product which breaks less often or a 'cheap one' which breaks easily.

Aren't there a little more expensive (say 10$) ones that are more secure. One mentioned Ruggeduino

Ruggeduino is OTT protected (ruggedized) for industrial applications.

I don't think even a supposedly superior "genuine" board would have protection on the I/O pins for instance, at least any of the popular standard ones. At most, they might be using a regulator that has better overcurrent protection. And it shouldn't be too hard to put a better regulator on a cheap Chinese board, and save a lot of money by avoiding boards where the price is 20% substance and 80% brand image.

@MattiVirkkunen The genuine Uno has a decent PTC on it. One has to question the quality (and thus efficacy) of the PTC (if there even is one) on a Chinese clone. Also you only have to cough in the same room as it and the CH340G dies. All adds up to far more fragility than a genuine one - and none of it is to do with the MCU.

This is generally good advice, but keep in mind, there are exceptions. My first Arduino was a Chinese clone (cost about £3 and came with a USB cable too) but it has managed to outlive two genuine ones, even though I usually try risky things on it first.

@AleksandurMurfitt The USB cable on it probably has so little metal in the power wires it acts like a resistor limiting the current and protecting everything ;)

This would be a better answer in the opposite order. Someone who isn't following the basic rules can, and often will, fry a board within 30 seconds of taking it out of the box, no matter how "genuine" it is. There aren't all that many protections in the design — and speaking of regulators, aren't they still using those little SOT-223 ones that get blistering hot when you draw rated current at rated input voltage? There are also clones out there that have noticeably better builds.

I disagree with buying a genuine one. I mean sure if you've got the money, go for it, but unless your goal is to support Arduino, just go to eBay and buy a Chinese-made Arduino. I get mine from eBay. The trick is to find the good ones. Start by limiting the search to your local country and setting Price Low > High. Find the ones with the DIP socket chip as they're usually better-made (not sure why), then find the cheapest one from a reputable seller (I'm in Australia, so I look for sellers that use solid English and take their own photos - my favourite seller is LearCNC, for instance).

@Majenko I've been using clones with CH340G chips for years, am not particularly careful with them, and have never had a related failure. I see several suggestions online that their internal power management is flaky and that they should therefore be used with an external regulator, but checking the clone boards I have that seems to be the way it has been done.  As to the PTC, I'm not sure how to test it, but there definitely is a component labelled as one on the boards I have.  All in all, I've had nothing but good experiences with clone Arduinos, so I'm really not sure what the issue is.

No need to be so racist. I'd rather buy Chinese electronics than Italian electronics - The Chinese knows what they are doing and have a huge industry.

Your comment that you would rather buy Chinese than Italian is racist itself. @Majenko - it might be better to say "cheap clones" rather than insult a particular country.

Sure - a lot of them are coming out of Malaysia and Vietnam now anyway.

Besides, China make all of my PCBs...

Measurements to prevent breaking an Arduino (or AVR in general):
Precautions

Always remove the USB or adapter plug when you make a change in the circuit.
Check all wires before you switch it on.
Remove or make sure (temporary) loose wires/jumpers do not touch other components or the Arduino (better take them out or 'park' them somewhere else in the breadboard.

Preventing wanted changes resulting in shortcuts

Check again the wires/jumpers you just changed/added.
Make sure no other components/wires/jumpers are touching the Arduino or the breadboard (components).
Clean your desk (if you have space), so if something metal falls/moves, it does not hurt your Arduino.
When changing a shield, always check all wiring to and from it, to your Arduino and the components on the shield itself if needed.

Preventing component shortcuts or overpowering

If you have a wire from a pin to GND or a pin to VSS, always make sure there is either a resistor, or you know why a resistor is not needed. This can also damage directly your Arduino.
Make sure that every component does not get more power than it can handle.
More specific: If you have components using 3.3V, make sure they don't get 5V.
If you have components using 3.3V, make sure they don't get 5V.

Preventing too much heat

Do not just put an Arduino in some case/enclosure ... heat may destroy it, so check before there is enough cooling, add a fan, heatsink or make holes in the enclosure.
If you connect any power source other than USB, check again if it does not generate unnecessary much heat. Unused voltage will generate much heat.

Preventing static electricity

Do not touch components when not needed
If you touch components, make sure you are discharged (touch a radiator, use a wrist band, use an ESD mat, touch grounded wire).

Preventing trivial mistakes

Do not keep drinks next to your Arduino or breadboard (or if you, keep it on the other side).
Watch out for heavy cables not dragging your Arduino from the table/desk ... a USB cable can easily drag an Arduino down.
Watch out when you change cables, not to pull your Arduino from the table/desk.
Keep animals (and people too, to your own judgement) away from your electronics project.

I've been very scared when accidentally used a shield while a different-purpose program is loaded in the arduino. Like PWM program on a display or using gsm library incompatible with a gsm module I am using. Can this also be an issue?

Yes I will add it ... if a sketch is putting 0V or 5V on a pin than several things can happen under the chapter Preventing wanted changes resulting in shortcuts

Can't tell if this was intentional, but I like the "two rules of Fight Club" approach to your advice about supplying 5V to 3.3V components.

Always use a series resistor when connecting anything to your IO pins. In many cases you will need one anyway (like driving a LED or a BJT), and in other cases it will not hurt (like driving MOSFET gates or UART lines). A 100 Ohm resistor will limit the current to 50 mA (keeping it within the safe range), while having little effect on your circuit in most cases.

I have used a current limiter (a cheap LM317 will do) occasionally, though even 100mA will burn your devices. It is good practice to limit current.
Generally don't wire a live circuit. Pull caps from the breadboard as well. Eventually you can disregard this, as you become more adept. I burned 4 arduino clones in the first few months.

You can't use an LM317 unless you have a substantially higher voltage power input.  And it won't provide any protection against ESD type damage, which is more likely at issue here.


text:
Arduino and big servo
My dad told me, if i can mount some servo (to control 4 way ventil of heating) to his arduino-controlled home. But there is a problem... The servo does not have a normal 3 cables but 6 and I have no idea how to control. So i start some research about it and i found web site of manufacturer. There was also a Datasheet, but i dont understand it :D. So here is a link to the Manufacture´s web: http://www.mutmeccanica.com/prodottomutmeccanica.php?p=207
And link to datasheet: http://www.mutmeccanica.com/download_file.php?file=downloads/scheda_V70.pdf
And I have a question: Is any hope to connect this to arduino? Is there some shield for it?

I can see only 4 or 5 pin in that datasheet, not 6 pin.

In the Arduino world, a servo motor is a RC servo motor. It runs at 5V or 6V and most of them can rotate 180°.
In an industrial environment or with the central heating in a house, the valves are often 24V AC. The most common voltages are 12V and 24V, and most of them with work with DC as well.
Sometimes the term "servo" is used for them, that is for example for a controller for valves with multiple positions.
To control them with an Arduino, the easiest way is with a number of relais.
Some intelligent valve controllers have an input signal. That is the one that you have.
The link to that datasheet is for a valve controller for 24V or 230V AC mains voltage. It has inputs to control it. Depending on the type, the input signal can be 0...5V, to 10V or to 20mA. Which one do you have ?
When that valve is in a central heating, it is possible to cause damage. First of all the central heating is tuned to the house. The valves work together with the pump, and not every system has a automatic overpressure-loop-valve.


text:
Two nRF24L01 radios per Arduino
Due to the results of my previous post (Slower nRF24L01 round trip delay than expected) I found out that it will be quite difficult to reach my latency requirements.
I am thinking about using my own protocol (instead of the 6-1 Multiceiver protocol), but that would involve getting some kind of 'clocked' receive and send times for devices, which will not make it simple probably. The time to change from reading to writing is less than expected (startListening takes max 350 us and stopListening 450 us). However, if I need to do this ever 5 ms and making sure no devices are reading/sending to others, that's quite a bit of downtime.
So I was thinking, would it be a good (or stupid) idea to use TWO nRF24L01's per Arduino, one by default in reading mode, the other on writing mode (thus having bidirectional communication) and using two different channels. This means I never have to switch between reading and writing and can read/write simultaneously without message colliding.
(note: later I want to use multiple Arduinos and one STM32 device).
Does anyone see problems in this idea?
Requirement goals:

Latency: less than 10 ms to send it from device A to B, process it (excluded, takes a few ms) and send back from B to A (or in some cases B to C). Less than 10 ms is better.
Amount of messages: can be theoretically hundreds per second, in practice max 100 (from various devices, but all go through a processor-device).
Payload per message: 16 bytes probably, most are shorter, some are longer but I can split or combine them if needed.
Range: about 10 meters max, but in a music/band stage environments
Channels: I will not use the WIFI channels, but a range of others, also (professional) wireless mics do not work on 2.4 GHz, so I don't expect too many problems.

About channels: I don't expect any problems. I should have enough channels between 2.484 and 2.525 GHz. This gives me about 40 channels for 1 mbps or 20channels for 2 mbps to chose from.

sources:

2.484 GHz: WIFI Channels, first table with red/green items
2.525 GHz: Datasheet, paragraph 6.3.

What is your overall wireless communications goal? Bandwidth, latency, etc? NRF24L01 might be 2 Mbps (bitrate) but my guess is that 1-2 KBps is somewhat the limit. They are fine/designed for short and less frequent messages such as from a wireless mouse, e.g. 20 ms update frequency, 16-32 byte payload. Also you might want to try changing channel to avoid noise (message drops) due to WiFi.

@MikaelPatel I improved my answer, I think 1-2 KBps would be sufficient, 20 ms is way too long for my needs, payload can vary.
I thought I wouldn't have problems with WIFI, I could do an occasional channel check though.

@MikaelPatel from 2.484  to 2.525GHz. I should have enough channels (sources: https://en.wikipedia.org/wiki/List_of_WLAN_channels#Most_countries, first table with red/green items,  2.525: https://www.nordicsemi.com/chi/content/download/2730/34105/file/nRF24L01_Product_Specification_v2_0.pdf paragraph 6.3. This gives me about 40 channels for 1 mbps or 20channels for 2 mbps to chose from.

I can see no reason not to use two nRFs concurrently. You may want to turn off auto-ACK and use Enhanced ShockBurst mode though to get better throughput.

@Majenko ... that sounds good ... I was already planning to switch off auto-Ack (actually all ACK) and implement the 'ACK' myself. I have to check into Enhanced ShockBurst (if that is the 6-1 Multiceiver idea I will use it).

@Majenko ... I checked into it and I thought that was the only way (using Enhanced Shockburst). Actually I'm using http://tmrh20.github.io/RF24/index.html which highlikely makes use of that. I will disable ACKs/retries and handle those myself.

@Downvoter, can you instead of downvoting all my posts, explain WHY you downvoted, so I may improve the post.

At 2 Mbps, a 32-byte packet (40 bytes with preamble, addresses, CRC) will be approx 160 microseconds long.  The round-trip time is likely to be much longer, since the microcontroller or radio will need additional time delays for auto-retry, sending and receiving the response packet, PLL lock, reading the data registers, etc.  In my experience a 2 ms round trip is possible, and the best way to do that is make use of the nRF built-in features:
-- IRQ interrupt: interrupts = fast
-- Enhanced Shockburst: this automatically handles lost packets and failed transmissions.  You can't get that capability any faster via the microcontroller coding.
On top of this, there is scope to use fast SPI libraries (or use SPDR/SPCR registers directly) to transfer data to and from the radio module.  If speed is your goal, don't rely on plug-and-play libraries that others have written.  Read the data sheets carefully and minimize unnecessary delays within the Arduino code.

I deviated my project slightly, so I will not use nRF's for the time being, and if so, probably on STM32, not Arduino, but good to know it's better to use the builtin way.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino Uno + Sim808: Using HTTP client for GPRS GSM
My problem is that I do not want to use AT commands everywhere to get/post data to my web server because it is brainstorming with all the delay and anything. I want to use library like gsm.h or something similar. Is there simple libraries which I can use to do the HTTP/HTTPS request (get/post) to my web server?
This code is my attempt with gsm.h, but it does not work. I suppose it only works with Arduino + Telefonica GSM/GPRS shield, not Sim808:
/*
 Web client

This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and
prints it to the Serial monitor.

Circuit:
* GSM shield attached to an Arduino
* SIM card with a data plan

created 8 Mar 2012
by Tom Igoe

http://www.arduino.cc/en/Tutorial/GSMExamplesWebClient

*/

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

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

    Serial.println("Starting Arduino web client.");
    // connection state
    boolean notConnected = true;

    // After starting the modem with GSM.begin()
    // attach the shield to the GPRS network with the APN, login and password
    while (notConnected) {
       if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
       (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
          notConnected = false;
       } else {
          Serial.println("Not connected");
          delay(1000);
       }
    }

    Serial.println("connecting...");

    // if you get a connection, report back via serial:
    if (client.connect(server, port)) {
       Serial.println("connected");
       // Make a HTTP request:
       client.print("GET ");
       client.print(path);
       client.println(" HTTP/1.1");
       client.print("Host: ");
       client.println(server);
       client.println("Connection: close");
       client.println();
    } else {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
    }
}

void loop() {
     // if there are incoming bytes available
     // from the server, read them and print them:
     if (client.available()) {
        char c = client.read();
        Serial.print(c);
     }

     // if the server's disconnected, stop the client:
     if (!client.available() && !client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();

        // do nothing forevermore:
        for (;;)
        ;
     }
 }

Is there GSM/GPRS library that I can use with Sim808?

What does Google tell you?

Start Arduino IDE, open the Library manager, search for SIM800 and there is 3 libraries available there that you can install. The advantage is that this libraries is kept up to date and when a new version is available you will get a notice to upgrade.
There is a HTTP PUT/GET library "HttpClient" that can be installed the same way as above.
Or
If you googlem using "sim800 library arduino" you will find several libraries like:
https://cristiansteib.github.io/Sim800l
or on github:
https://github.com/search?l=Arduino&q=sim800&type=Repositories&utf8=%E2%9C%93
And as I understand it the 808 is GSM/GPRS + GPS, so the GPS features isn't normally covered by these libraries.


text:
Is this assignment valid or needs casting?
I have this assignment and while i don't get any error not even warning from the compiler.
uint16_t Buffer[40000];

for (int n=0; n<40000 ; n++){
Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n);
}

The Buffer is an unsigned short but as you can see inside there are float values inside.
The program does not work as expected.
Also i have another case where i am not sure if i need casting as this time, the final value is a float value.
int intVal;
float floatVal;

floatVal = intVal - intVal*Buffer[intVal];

Is this valid? Does it need casting? Or there is not reason to declare floatVal as float?

what exactly do you expect from the program to do?

it is a real time audio manipulation application

this is irrelevant.
What do you expect after executing your first snippet, to be the contents of Buffer?

The first one has wrong parenthesis, and casting is correct, however everything between 0 and 0.9999999999 results into a 0 in uint16_t variable.

Thanks! So i will experiment by just leaving the cos part!

What board are you trying to run that on?

There aren't many Arduinos that have 80 KB of RAM - please specify which one you are trying this on.

The Arduino line is not noted for its ability to do real-time audio manipulation. That's not its target market.

I am using Arduino DUE

First part:
uint16_t Buffer[40000];

for (int n=0; n<40000 ; n++){
  Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n);
}

Buffer[n] will be filled with an uint16_t and implicit casting to an uint16_t will be used. I suggest you do such implicit castings explicitly (so add (uint16_t) ... if you want).
However, if you do not want this, either define the Buffer as float, or at least add + 0.5 to give better roundings (if that is improving, depends on your situation, but mathematically it is better).
thus:
static const uint8_t BUFFER_SIZE = 40000;
uint16_t Buffer[BUFFER_SIZE];

for (int n=0; n<BUFFER_SIZE; n++)
{
  Buffer[n] = (int) (0.99 * cos(((2.0*PI)/BUFFER_SIZE)*n));
}

The next one:
int intVal;
float floatVal;

floatVal = intVal - intVal*Buffer[intVal];

This is also 'compiler-correct', and an int value can be more easier converted to a float. You will not lose digits. However, to make it clear an explicit cast with (int) ... is better.
Thus:
int intVal;
float floatVal = (float) (intVal - intVal*Buffer[intVal]);

c will perform implied casts for standard data types, normally without issuing any warnings.
This can catch you out at times.
So if you try to store a float into an int then it will be rounded down to the next integer. Since floats sometimes have rounding errors this can result in the value being 1 less than expected. e.g. 5 / 2.5 should give 2.0 but due to rounding may result in 1.99999999999. When saved as an int that would then give a value of 1.
If you want to round to the nearest integer then first add 0.5.
While the casts are implied and so not technically needed it can sometimes be a good idea to still include them explicitly just to make it clearer in the code that values are going to get rounded down.
The other thing to keep in mind is how variable types are promoted by the implied casts.
e.g. consider the following two lines:
float x = 3 + 2/4.0;
float x = 3.0 + 2/4;
In the first the calculation it is: int + int / double = int + double = double
In the second it is: double + int / int = double + int = double
So both result in a double that is then converted to a float (arduino is a little non-standard here, doubles are just floats anyway).
However the resulting values will be different. The first one will give
the expected 3.5 while the second one will give 3.0 because 2/4 is an integer calculation and will have a value of 0. In order to get the correct value either the 2 or the 4 must be cast to a float or double before the division operation takes place.
For your specific questions:
Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n); is perfectly valid, all calculations will be performed as doubles and the end result cast to an int however you may get rounding issues as mentioned above. Changing the line to Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n) + 0.5); will round to the nearest integer which is probably what you want.
For the second question, floatVal = intVal - intVal*Buffer[intVal]; there is no need for a cast, the value will be calculated as an int and then there is an implied cast to a float. However I'm not sure what the point of using a float is here since the result is always going to be an integer, using a float will only slow things down.


text:
Make arduino board controler for watering system with power bank
I am trying to build an off-grid automatic watering system, and I was thinking of many options and the most reliable one that I found is to use a power bank which is charged by a solar panel.
So, I have a solar panel that outputs 5V, and I can charge a standard power bank with it. In addition to this, I bought a USB pump which I can also power with the power bank and controlled using an Arduino board. The problem is that the power bank doesn't support charging and discharging at the same time, and I thought that I could use an Arduino board to control this, but I have no knowledge on this. Therefore, I need help.
Is it possible to have a system like the one sketched below, where the Arduino board controls the input/output of the power bank?

The black path is my current path, but I was wondering if I could do the red path so that I can have both chargings from the solar panel and discharge due to the pump and Arduino board.

Is it possible? Yes.
Is it easy? Maybe.
A relay shield or similar would allow you to break the power connection from the solar panel to the power bank input, wait 5 seconds and then connect the power bank output to the pump.
Once you are done with the pump you could disconnect power from it and reconnect the charging power.
That is all fairly straight forward, maybe a dozen lines of code and some very simple wiring.
The issue is where does the arduino get power from? Or more accurately how does the arduino maintain power during the transitions between different power sources. How much of an issue this is depends a lot on how quickly the power pack transitions from charging to outputting and back and how you want the system to behave overnight or other times when there pump is idle but there isn't much sun light.
Also have you done a power budget? How much power does your pump take and how much power does your solar panel output under normal usage? Based on those two how long per day can you run the pump for assuming an ~80% efficient battery pack.

You should be able to solve it with two diodes, preferably Schotty diodes, they have a low forward drop voltage.

Simple, but I'm not sure a 5v solar cell itself can run the pump...

Well if the voltage from the solar panel drops below the voltage from the power bank, then will the pump/arduino be get its energy from the power bank.


text:
How to send a number to Arduino via Python over serial?
I call an API in Python and it gives as output as a single digit and an Arduino program receives this number over serial and displays it on a 7-segment display.
I wrote a different program in which Arduino sends the data and a Python program receives it. That worked but the following program is not working. What is the problem?
I am using Python 3 and Arduino Uno.
Python program:
import serial ,requests, json, time
arduino = serial.Serial('COM1', 9600, timeout=.1)
time.sleep(1)
response = requests.get("https://traffic.cit.api.here.com/traffic/6.1/flow.json?bbox=12.9808%2C77.5759%3B12.9803%2C77.5767&app_id=zbvY0tdRs089c3ZTKqWR&app_code=pxAtGksNBgVD9V5XF5nEzA",)
#CALLING API
response.content.decode("utf-8")
data = response.json()
text = str(data) #CONVERSION TO STRING
l = len(text)
for i in range(0,l): #Taking out the number
    if text[i] == 'J':
        j = text[i + 5]
        print (j)
        arduino.write(j) #writing over serial
        break

Arduino program:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int h=9;
int rx_byte = 0;

void setup() {
  Serial.begin(9600);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(h, OUTPUT);
  digitalWrite(h, 0);  // start with the "dot" off
}

void loop() {
  if (Serial.available() > 0) {
    rx_byte = Serial.read(); //reading serial
    switch (rx_byte) {
    case 0:
      zero();
      break;
    case 1:
      one();
      break;
    case 2:
      two();
      break;
    case 3:
      three();
      break;
    case 4:
      four();
      break;
    case 5:
      five();
      break;
    case 6:
      six();
      break;
    case 7:
      seven();
      break;
    case 8:
      eight();
      break;
    case 9:
      nine();
      break;
    }
  }
}

// write '9'

void eight() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 1);
  digitalWrite(e, 1);
  digitalWrite(f, 1);
  digitalWrite(g, 1);

}
void seven() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 0);
  digitalWrite(e, 0);
  digitalWrite(f, 0);
  digitalWrite(g, 0);

}
void six() {
  digitalWrite(a, 1);
  digitalWrite(b, 0);
  digitalWrite(c, 1);
  digitalWrite(d, 1);
  digitalWrite(e, 1);
  digitalWrite(f, 1);
  digitalWrite(g, 1);
}
void five() {
  digitalWrite(a, 1);
  digitalWrite(b, 0);
  digitalWrite(c, 1);
  digitalWrite(d, 1);
  digitalWrite(e, 0);
  digitalWrite(f, 1);
  digitalWrite(g, 1);

}
void four() {
  digitalWrite(a, 0);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 0);
  digitalWrite(e, 0);
  digitalWrite(f, 1);
  digitalWrite(g, 1);
}
void three() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 1);
  digitalWrite(e, 0);
  digitalWrite(f, 0);
  digitalWrite(g, 1);

}
void two() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 0);
  digitalWrite(d, 1);
  digitalWrite(e, 1);
  digitalWrite(f, 0);
  digitalWrite(g, 1);
}
void one() {
  digitalWrite(a, 0);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 0);
  digitalWrite(e, 0);
  digitalWrite(f, 0);
  digitalWrite(g, 0);

}
void zero() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 1);
  digitalWrite(e, 1);
  digitalWrite(f, 1);
  digitalWrite(g, 0);

}
void nine() {
  digitalWrite(a, 1);
  digitalWrite(b, 1);
  digitalWrite(c, 1);
  digitalWrite(d, 0);
  digitalWrite(e, 0);
  digitalWrite(f, 1);
  digitalWrite(g, 1);

}

I am quite new to programming. Please help.

The python code
j = text[i + 5]
print (j)
arduino.write(j)

Is sending a single text character between '0' and '9', ascii values 48 to 58.
The c code
rx_byte = Serial.read(); //reading serial
switch (rx_byte) {
  case 0:

is looking for absolute values between 0 and 9.
There are two easy options to fix this, option 1 change the case statement to look for the correct values:
rx_byte = Serial.read(); //reading serial
switch (rx_byte) {
  case '0':

or option 2, rely on the fact that the ascii for the numbers is always 48 more than the number represented and subtract that:
rx_byte = Serial.read() - '0'; //reading serial
switch (rx_byte) {
  case 0:

-'0' and -48 would have exactly the same effect here only by using '0' it makes it clear we are offsetting by the ascii value of a 0 rather than by some other randomly created number. It also saves you having to remember what the correct value is for 0.
Generally since you are using the value in a case statement I'd recommend the first option, it's a little more intuitive and avoids an extra calculation that can look a little odd if you are new to programming.
The reason I mentioned the second option is that this is the method you would use if you wanted to use the rx_byte value as the index in an array for any reason.

I think you are sending ASCII values 0 - 9 over serial.  This is a bad idea, because they can be interpreted as control codes, always send printable characters.  So in this case send '0' to '9'.
Also you could make you code much smaller if you used arrays.
For instance
int pins[8] = {2,3,4,5,6,7,8,9};
int TheData [8][8] =
{
    {1,1,1,1,1,1,0,0}, // 0
    {0,1,1,0,0,0,0,0}, // 1
    // etc
};
void write (int number)
{
    for (int i = 0; i < 7; i++)
    {
       digitalWrite (pins[i], TheData[number][i]);
    }
}

I'll let you figure out how to reduce setup to less than 3 lines :)


text:
I'm getting watchdog timer resets in NodeMCU. How can I permanently disable or stop that?
I'm using NodeMCU for my project. At first it works fine, but after some days it is resetting frequently because of the watchdog timer. I have used the Esp.wdtfeed() method also. But it is not working. Can you please tell me what the problem exactly with or any solution? Here is my code:

void setup(void) {
  ESP.wdtDisable();
  ESP.wdtEnable(WDTO_8S);
  Serial.begin(9600);
  int n = WiFi.scanNetworks();
  Serial.println("");
  if (n == 0)
    Serial.println("no networks found");
  else {
    for(int i=0;i<n;i++) {
      if(WiFi.SSID(i)==ssid1) {
        WiFi.begin(ssid1,password1);
        ssid=ssid1;
      } else if(WiFi.SSID(i)==ssid2) {
        WiFi.begin(ssid2,password2);
        ssid=ssid2;
      } else if(WiFi.SSID(i)==ssid3) {
        WiFi.begin(ssid3,password3);
        ssid=ssid3;
      }
    }
  }
  display.init();
  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawStringMaxWidth(15,15, 128,"Display started");
  display.display();
  // Wait for connection
  display.clear();
  int j=0;
  while(j<10) {
    display.drawStringMaxWidth(15,15, 128,"connected to");
    display.drawStringMaxWidth(15,32, 128,ssid);
    display.display();
    display.clear();
    delay(1000);
    j++;
  }
  display.drawStringMaxWidth(15,32, 128,"");
  display.display();
  Serial.print("Connected to ");
  display.clear();
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  if (mdns.begin("esp8266WebForm", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  server.onNotFound(handleNotFound);
  server.begin();
  Serial.print("Connect to http://esp8266WebForm.local or http://");
  Serial.println(WiFi.localIP());
  server.on("/", getvalues);
  pinMode(buzzPin,OUTPUT);
  pinMode(but,INPUT);
}

void loop(void) {
  ESP.wdtFeed();
  if((WiFi.status()== WL_DISCONNECTED)||(WiFi.status()==WL_CONNECTION_LOST)) {
    display.drawStringMaxWidth(15,15, 128,"disconnected");
    display.display();
    int n = WiFi.scanNetworks();
    Serial.println("");
    if (n == 0)
      Serial.println("no networks found");
    else {
      for(int i=0;i<n;i++) {
        if(WiFi.SSID(i)==ssid1) {
          WiFi.begin(ssid1,password1);
          ssid=ssid1;
        } else if(WiFi.SSID(i)==ssid2) {
          WiFi.begin(ssid2,password2);
          ssid=ssid2;
        } else if(WiFi.SSID(i)==ssid3) {
          WiFi.begin(ssid3,password3);
          ssid=ssid3;
        }
      }
      int j=0;
      display.clear();
      while(j<10) {
        display.drawStringMaxWidth(15,15, 128,"connected to");
        display.drawStringMaxWidth(15,32, 128,ssid);
        display.display();
        display.clear();
        delay(1000);
        j++;
      }
      display.clear();
      display.drawStringMaxWidth(15,32, 128,"");
      display.display();
    }
  }
  getvalues();
  delay(20000);
}

Likely, you will get some humerus comments (like do you work for a certain car company).  Seriously, it sounds like the watch dog has found a problem with your code or hardware.  Rather than defeating the watch dog, most people here will suggest you find the cause (why your code has failed to "kick the dog").

Could you post the error output from the console?

here my way to find the bug first
1.comment out the watchdog from the code.
2.debug the code flow and find it get struck. Debugging in the sense put "Serial.print()" in between your code where you feel stuck but here don't disable your watchdog.

After long time I have seen this question and thought of answering as I found the issue at that time itself, But not posted here.
After debugging for long time, I got to know that there is a string i am initializing with the data fetched from a site which has been overflown beyond the memory of NodeMCU. due to which it has thrown watchdog exception, So please do memory management properly as NodeMCU cannot do data processing and all.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How to convert numbers from Serial port input to HEX String?
I am trying to read digits (number from 0 to 255) from Serial port, convert them to HEX String and send them using SoftwareSerial as HEX.
For example:
when I send '60' trough the serial port, the SoftwareSerial will send '3C'
currently I am using the following code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 4); // RX, TX

String inputString     = "";
boolean stringComplete = false;

int HexInt = 0;
String HexString = "00";

void setup() {
  Serial.begin(115200);
  mySerial.begin(38400);
  inputString.reserve(200);
  delay(500);
  Serial.println("");
  mySerial.println("");
}

void loop() {
  serialEvent();
  if(stringComplete) {
    HexInt = inputString.toInt();
    HexString = String(HexInt,HEX);
    if (HexInt<16) HexString = "0" + HexString ;
    HexString.toUpperCase();

    mySerial.println(HexString);

    Serial.println(inputString); //debug
    stringComplete = false;
    inputString = "";
  }

}

void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    if (inChar == '\n') continue;
    if (inChar == '\r') {
      stringComplete = true;
      if (inputString == "") inputString = "NULL";
      inputString.toUpperCase();
      continue;
    }
    inputString += inChar;
  }
}

My question is:
Is there a more elegant / effective way to perform the same outcome?

You have the number. It's made up of two nibbles, each representing 4 bits (1 hex character).
If you want to do a manual conversion take the first nibble (AND with 240) add it's value to "0" then do the same for the lower nibble (AND with 15).
OR
What I would do is use:
char HexString[3];
sprintf(HexString,"%02X",HexInt);

since you're not dealing with floats, you're good to go.
OR
edit: I recalled a printf function that we put together once before, I don't know if it would work with SoftwareSerial, so you might have to play around with it a bit, but as a 3rd option, you could try the following. I don't have access to an Arduino or compiler at the moment, otherwise I'd have a play with this right now.
Before your setup:
// Function that printf and related will use to print
int serial_putchar(char c, FILE* f) {
    if (c == '\n') serial_putchar('\r', f);
    return Serial.write(c) == 1? 0 : 1;
}

FILE serial_stdout;

In your setup, add:
// Set up stdout
fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);
stdout = &serial_stdout;

in your loop, change your assignment to:
HexString = printf("%02X",HexInt);

from: https://arduino.stackexchange.com/a/480/304

It should be char HexString[3];, you need space for the null terminator at the end of the string. And depending on the source of the data input it may make sense to either use snprintf or verify that the value is never outside the expected range. It pays to always be paranoid about buffer overflows.

I usually have to think about these, but running a quick test in gcc confirms for a value of 0x05, HexString[0]='0', HexString[1]='5',HexString[2]=0.

Exactly, an array that is 3 long not the 2 long that you are allocating.

yes. you're right... edited :)

thank you very much for the quick respond.. I tried using the Second solution but I have a different issue now. I am actually trying to sent the HexString + another String like this mySerial.println("GR+" + HexString); and I get an error regarding char and string cannot be added together.

did you solve that? If not you should ask a new question and post a link here so I can catch it. It depends, what does HexString now contain? guessing by the error it's a char since "GR+" is a string. In the mean time and since it's just the .println() you're having a problem with here, just use multiple .print() and a .println() to achieve the same thing

@Madivad this is exactly how I solved it - I use print("GR+") followed by a println(HexString). thank you!


text:
5 inch TFT LCD for Arduino
I want to use a 5 inch 800x480 TFT display (touch not needed) with an Arduino (mega, uno or due). I'm thinking of buying this display: link (buydisplay.com). How can I connect this ?
I have also seen some pricier screens with serial i2c connection., but I don't understand the difference between this and using a shield?
Do anyone have any advice for displays to order and/or shields for Arduino ? Preferably a solution that I can reproduce by my self later for mass-production by doing be own circuit board.
Thanks in advance!

You need a driver board to run it. SSD1963 based ones are popular and are often included on the screen, especially the 7" ones on eBay.
Arduinos cannot drive a display directly. Small TFT screens often include the driver chip on them in the form of a Chip On Glass (CoG). That can't be done with the larger screens due to the sheer amount of memory needed to store the frame buffer. So an external chip has to be used, or a microcontroller with built in TFT interface.
Note that even with an SSD1963 (or equivalent - see the ones BuyDisplay sell are based on the RA8875) interfacing the Arduino to the TFT screen results will most likely be somewhat disappointing. Especially if you are interfacing using SPI or I2C which will create a bottleneck. Best is to interface with a 16-bit "8080" interface (16 data bits, read, write, chip select, reset and D/C), however that takes a lot of IO pins, and ideally a proper parallel interface to drive it quickly. And you want a lot of RAM for manipulating the data you want to display...

Ok but I can not use it with the raw display and arduino due?

No, that does not have a TFT interface in it. Generally you want a SoC, such as is used on the Raspberry Pi or Beaglebone Black, for that kind of thing.

ok, the problem is that i want to avoid OS based devices and only use micro controllers that i can build by my self with EagleCAD.

So you will need a display with a driver chip - and that means spending more money.

and what about this driver? https://www.adafruit.com/product/1590

okay so basically this kit will work nicely with a Due i guess: http://www.buydisplay.com/default/display-5-inch-tft-arduino-touch-shield-ssd1963-for-mega-due ?

Ideal, yes. And should be well supported by most graphics libraries too.

Ok, one last question: Does it matter if I use a Due or Uno/mega with this as the driver has its own chip and RAM memory that run in parallel ? Thanks again

The Uno will struggle. Also you won't be able to run in 16 bit parallel, only 8 bit parallel, and that will both slow things down and use most of your Uno pins. Better use a Due.


text:
Roadblock using template functions
As part of a larger project, I'm trying to create a simple template function that will take an array and a value, both of the same type, and fill the array with the value. I'm running into the error quoted below:
"specializing member '::Fill_With' requires 'template<>' syntax"
Below is the offending code fragment:
// Simple function to fill an array with a specified value.
template <class T> void Fill_With(T target_array, T value){
    int Array_Size = sizeof(target_array) / sizeof(T);
    for(int l = 0; l < Array_Size; ++l){
        target_array[l] = value;
    }
}

int array1[4] = {1,2,3,4}, k = 0;
Fill_With<int>(array1, k);

I've read numerous other forum posts on the error message, but haven't quite been able to figure out what I'm missing. I've read that I need to include a blank "template<>" header before the function declaration but that didn't seem to solve the issue.
What am I doing wrong? Thanks!

See this SO question: How to write a template function that takes an array and an int specifying array size

Let's start by getting rid of the templates, as they make things more confusing. In the following, I replaced T with int.
void Fill_With(int target_array, int value){
    int Array_Size = sizeof(target_array) / sizeof(int);
    for(int l = 0; l < Array_Size; ++l){
        target_array[l] = value;
    }
}

Let's try it out! I pasted this into the Arduino IDE and compiled it. Here is the output:
sketch_aug01a/sketch_aug01a.ino: In function 'void Fill_With(int, int)':
sketch_aug01a:4: error: invalid types 'int[int]' for array subscript
         target_array[l] = value;
                       ^
exit status 1
invalid types 'int[int]' for array subscript

This is telling us that we're trying to subscript (that's the term for the [] syntax) a variable of type int with a variable of type int. In C++, a pointer to the start of an array has type int *, not int. Let's fix the type of target_array in the function signature:
void Fill_With(int *target_array, int value){

It compiles, but if you ran it you would quickly run into a bug:

When given an expression, the sizeof operator will return the number of bytes in the type of the expression. The type of the expression target_array is int *, so sizeof(target_array) == sizeof(int *). On 32-bit systems, sizeof(int *) == 32/8 == 4.
When given a type, the sizeof operator returns the number of bytes in the type. So sizeof(int) gives the number of bytes in an int, which is guaranteed to be at least 2 bytes (16 bits), but is usually 4 or 8 (it depends on the system).

Together, this means that Array_Size ends up being some small number like 0 or 1, regardless of the contents of target_array. To fix this, you can instead pass in the length of the array as a parameter:
void Fill_With(int *target_array, int array_size, int value){
    for(int l = 0; l < array_size; ++l){
        target_array[l] = value;
    }
}

int array1[4] = {1,2,3,4}, k = 0;
Fill_With(array1, 4, k);

Now you can put the templates back in:
template <class T> void Fill_With(T *target_array, int array_size, T value){
    for(int l = 0; l < array_size; ++l){
        target_array[l] = value;
    }
}

int array1[4] = {1,2,3,4}, k = 0;
Fill_With<int>(array1, 4, k);

By the way, C++ already has this function built in. It's called std::fill. Here's how to use it:
#include <algorithm>

int array1[4] = {1,2,3,4}, k = 0;
std::fill(array1, array1 + 4, k);

Thanks a ton for the detailed explanation. I'm still pretty noobish so the breakdown was great.
FYI, after some tinkering and research, it does not appear that  or std::fill are supported by Arduino, which is kind of a bummer. Thankfully I can just create the template function the correct way.


text:
Connect ESP8266 ESP-12 with 2 arduinos
I understand how to connect one ESP-12 to an Arduino, but it's possible to make the ESP-12 connect to two arduinos? I found a lot of information about the gpio as txd-rdx but not at the inverse.
Is possible to connect pins 21 & 22 to one arduino and 7 & 16 to another one? What condiderations must I have to?

You can use softserial and use any io pins to connect the two arduinos via serial.

What advantage would sharing give you?  Is it worth the hassle?  I can't think of a reason why it isn't possible.


text:
Using 2 GY521(mpu6050)s with Arduino Uno R3
I am working on creating a motion sensor based on an Arduino and MPU6050 interface. I'd like to retorfit my code to be able to read 2 mpu6050 devices. Besides defining a 0x69 address and setting AD0 to high on one and AD0 to low on the other, what additional changes to I need to make to my code? I posted my original code below. Thanks in advance!
//Basic code to setup and read raw values from mpu6050
//matt_m 7-9-2017

#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU6050 0x68 //Device address
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address

//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s

int16_t  AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

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

void loop() {
  read_mpu6050();
  Serial.println(AcX);  //value to display
}

//setup MPU6050
void angle_setup()
{
  Wire.begin();
  delay (100);
  writeTo(MPU6050, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU6050, ACCEL_CONFIG, accSens << 3); // Specifying output scaling
  of accelerometer
  writeTo(MPU6050, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling
  of gyroscope
  delay (100);
}

void read_mpu6050()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU6050);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050, 14, true);  // request a total of 14 registers
  AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);
  Wire.write(toAddress);
  Wire.write(val);
  Wire.endTransmission();
 }

*edit: This below is the code with my best guess of how to implement 2 sensors, alas, my the output on my serial monitor keeps spitting out erraneous -1s and 0s
#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU60501 0x68 //Device address #1
#define MPU60502 0x69 //Device address #2
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address

//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s

int16_t  AcX1, AcY1, AcZ1, Tmp1, GyX1, GyY1, GyZ1;
int16_t  AcX2, AcY2, AcZ2, Tmp2, GyX2, GyY2, GyZ2;
void setup() {
 pinMode(0, OUTPUT);
 digitalWrite(0, HIGH);
 pinMode(1, OUTPUT);
 digitalWrite(1,LOW);
 Serial.begin(115200);
 angle_setup1();
 angle_setup2();
}

void loop() {
  read_mpu60501();
  Serial.println(AcX1);  //value to display
  read_mpu60502();
  Serial.println(AcX2);  //value to display

}

//setup MPU60501
void angle_setup1()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output
scaling of accelerometer
  writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output
scaling of gyroscope
  delay (100);
}

void read_mpu60501()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60501);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
  AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

//setup MPU60502
void angle_setup2()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60502, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60502, ACCEL_CONFIG, accSens << 3); // Specifying output
scaling of accelerometer
  writeTo(MPU60502, GYRO_CONFIG, gyroSens << 3); // Specifying output
scaling of gyroscope
  delay (100);
 }
void read_mpu60502()
 {
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60502);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60502, 14, true);  // request a total of 14 registers
  AcX2 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY2 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ2 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp2 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX2 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY2 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ2 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);
  Wire.write(toAddress);
  Wire.write(val);
  Wire.endTransmission();
}

`

You have Wire.begin() twice. I think it might work, but it is not nice programming. Your code might work, but having the same code twice makes it very hard to detect a bug. A good programmer uses code that does a certain job just once. You can use function with the I2C address as parameter or a class for the MPU-6050 (as @CodeGorilla already wrote).

When ever you start looking at multiples of an object you should think of classes and structures to do things.
If you wrote a class:
class MPU6050
{
public:
    // Class constructor
    MPU6050 (const byte& address = 0x68)
      :m_Address(address)
    {
    }

    // Class destructor
    ~MPU6050()
    {}

    //setup MPU60501
    void angle_setup (void)
    {
      // Wire.begin();              // This should be called in main setup.
      delay (100);
      writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
      writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output scaling of accelerometer
      writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling of gyroscope
      delay (100);
    }

    void read_mpu6050(void)
    {
      // read raw accel/gyro measurements from device
      Wire.beginTransmission(MPU60501);
      Wire.write(0x3B);                  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
      AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
      AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
      AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
      Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
      GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44(GYRO_XOUT_L)
      GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46   (GYRO_YOUT_L)
      GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48   (GYRO_ZOUT_L)
    }

    // Data member that could be private and have access functions, but...
    int16_t     AcX1;
    int16_t     AcY1;
    int16_t     AcZ1;
    int16_t     Tmp1;
    int16_t     GyX1;
    int16_t     GyY1;
    int16_t     GyZ1;

private:
    byte m_Address;
};

You could then have any number of sensors by going:
MPU6050  SensorOne;  // Address is optional and defaults to 68.
MPU6050  SensorTwo (0x69);

To access the data or functions in them:
SensorOne.angle_setup();
Serial.println(SensorOne.AcX1);

You could put the sensor in an array and then use loops everywhere, but there isn't much of a saving for two instances.


text:
Arduino + SIM808: How to get only the JSON object response without the header?
I have been successfully getting the response from my web server. The problem is I get the whole package with header and content/body:
Recv: 325 bytes: HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Wed, 02 Aug 2017 03:26:37 GMT
Connection: close
Content-Length: 18

1501644397698.2585

I want to only assign this 1501644397698.2585 to my double variable. How can I do this?
This is the code which sends and prints the response:
Serial.println("waiting to fetch...");
sim808.send(http_cmd, sizeof(http_cmd)-1);
while (true) {
  int ret = sim808.recv(buffer, sizeof(buffer)-1);
  if (ret <= 0) {
    Serial.println("fetch over...");
    break;
  }
  buffer[ret] = '\0';
  Serial.print("Recv: ");
  Serial.print(ret);
  Serial.print(" bytes: ");
  Serial.println(buffer);
  break;
}

You need to receive the whole header and them trim what you don't want. The easiest way of doing this is scanning the header string for a new line (\n) character. From the start of the string to the new line gives you a line of the header. If the length of this substring is < 1 then look for the next line. Now scan between the start and the new line and see if you see a colon (:), if you do then this line is part of the header, look for the next new line. Otherwise use strtod() to convert the data to a double.
It should be something like this (not compiled, not tested):
char* response = ".........";
char* pStartOfLine = response;
char* pEndOfLine = response;
bool bFoundData = false;
while (!bFoundData && pEndOfLine)
{
  while (pEndOfLine != NULL && *pEndOfLine != '\n')
    pEndOfLine++;
  if (pEndOfLine && pEndOFLine != pStartOfLine)
  {
    char* pStartOfData = pStartOfLine;
    while (pStartOfLine != pEndOfLine && *pStartOfLine != ':')
      pStartOfLine++;
    if (*pStartOfLine != ':')
    {
      theData = strtod (pStartOfData, NULL);
      bFoundData = true;
    }
  }
}

If it's in a separate function then you could just return rather than use the Boolean.
The order of the lines in the header are not guaranteed, but will always be in the same order from the same device with the same software, so as a cheat you could look for 'Content-Length: 18\r\n' and then just take the next non-blank line after that, but this is a more hacky way of doing it.