text:
12V but what Ampere?
So if my arduino will draw around 800mA @5V and the dc-dc buck converter around 266mA @5V plus solenoid 1.2A @12V, is it a good idea to get 12V 4A (48W) power supply? Since Filip Franik told me that it is a good practice to get 2 times the current I need just in case. Then what will happen to the current that are no in use?

Good practice is to calculate your needs and multiply them by 2 "just in case" So if you need 1.5A find a power supply that has a 3A max.a So you will need one that's around 36W (3A * 12V)

do not use the arduino as a power supply ... it tends to become an expensive fuse

I am using arduino for relay module, lcd, buzzer and keypad. Not using it as a power supply, I am trying to make the 12V the power supply for solenoid and arduino.

So you want to use the 5V voltage regulator on the Arduino serve as the supply for your 5V components, and feed the 5V regulator from the 12V supply that powers your solenoid?
The problem with that plan is heat. The voltage regulator on the Arduino is a poorly heat-sinked (heat-sunk?) "linear" regulator. A linear voltage regulator is basically a solid state circuit that converts excess voltage to heat.
The higher the supply voltage you provide to the voltage regulator, the more heat it generates for a given current load.
If you feed 12V into the Arduino's voltage regulator, it needs to reduce the voltage from 12V to 5V. 12V - 5V is 7V. So it will convert 7V to heat. You're only drawing ≈220 mA. Total power that will be converted to heat is 7V*0.22A, or around 1.54 watts of power. You should budget for at least 50% more current than you think you'll need, so lets use 330 mA. 7.0*0.33 is about 2.3 watts.
From a little research I did, it sounds like a typical Arduino voltage regulator can dissipate around 1 watt of heat. You're well over that limit even at your low ≈220mA number, so you need a solution that won't overheat your Arduino's voltage regulator.
If you were to instead supply the Arduino's voltage regulator with 7.5V, it would have a lot less work to do. That's a voltage drop of 2.5V. So for a 0.33 max current draw, that would be 2.5*0.33, or about 0.83 watts. That would be under the 1 watt ceiling. However, it sounds like your project is based on a 12V supply.
You could instead use an external switching voltage regulator to reduce 12V to 5V. (search for "boost voltage regulator".) Those are much more efficient, and don't generate nearly as much heat. You could then feed regulated 5V directly into the USB input on your Arduino, as well as supplying it to your other 5V components.

I have decided to choose the 12V 1.5A (18W) supply connected to 12V 1.2A solenoid and a DC-DC Step Down Buck Converter, stepping down from 12V to 7V, that will cause the current to increase from 1.5A to 2.5A for the Arduino.
AMS1117 5.0V SMD device (0.8A Adjustable/Fixed Low Dropout Linear Regulator) Max Input Voltage is 18V, Current limit is around 1.5A - 1.6A,
My current is around 2.5A minus off 1.5A, what will happen to the 1A?

I read a article, it says since there is no maximum current rating for the power supply connected to Arduino, the Arduino will draw as much current as it needs (and the voltage regulator can cope with). So its fine?

I don't understand what you are describing.

I totally forgot about DC-DC Step Down Buck Converter Output Current: Rated current 2A, maximum 3A (Additional heat sink is required). So from what I currently know buck converter will not create 2.5A just like that.

I am describing about the the ampere since buck converter steps down voltage (while stepping up current) from its input (supply) to its output (load).

Your various comments are VERY hard to follow. Please edit your question to state clearly what you plan to do. What you SHOULD do is to drive the 12V solenoid directly from the 12V supply. Then feed 12V into your buck converter, which is rated for up to 2A. I'm assuming you have selected a buck converter with a 5V output. you'd then feed that 5V into the USB port on your Arduino, along with using it to supply your other 5V components. The buck converter will only draw a very small amount of current from the 12V supply, and will not generate much heat at all.

If my supply increase from 12V 1.5A to 4A. My arduino will draw around 800mA @5V (571mA @7V) plus solenoid 1.2A @12V, is it a good idea to get 12V 4A (48W) power supply? Since Filip Franik told me that it is a good practice to get 2 times the current I need just in case.
I know there is the efficiency of the converter is calculated by dividing the output power (Pout) by its input power (Pin) and then times the input current to get output current.
So for example 7V divide 12V is around 58.3% x 4A = 2.33A. Even if the solenoid takes 1.2A @12V, the current left is 2.8A, so the current is 1.63A, @ 7V. If arduino current draw what it needs and as long as it doesn't draw more than 2A, I think it is sufficient and safe.


text:
Update button state in Blynk app through the code
I'm using Blynk along with a WeMos D1 R2 and i can change modes through an ON/OFF button.
I can succesfully change mode and make my application go from mode 1 (irrigation) to mode 2 (Fertilization), but through the code i manage to switch from mode 2 to mode 1(after my code does what it is meant to do).
However, i cannot make the button show up as being in mode 1 again, if the application is working properly in mode 1. Any ideas on how to update button condition?
My code follows(below the code you can see the app and the button Using the V1 virtual pin):
void setup()
{
  Serial.begin(9600);             // opens serial port, sets data rate to 9600 bps
  Blynk.begin(auth, ssid, pass);
  pinMode(Relay1, OUTPUT);        // Setup Relay pin as output pin
  pinMode(Relay2, OUTPUT);        // Setup Relay pin as output pin
//pinMode(led_pin, OUTPUT);
  pinMode(sensor_pin, INPUT);
  digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, LOW);
  digitalWrite(Relay1,HIGH);
  digitalWrite(Relay2,HIGH);

}

BLYNK_READ(V8)
{
  Blynk.virtualWrite(8,level);    // virtualpin 8 distance
}

BLYNK_WRITE(V1)
{
  pinValue = param.asInt();
}

BLYNK_READ(V5)
{
  Blynk.virtualWrite(5,RH);       // virtualpin 8 distance
}

BLYNK_READ(V6)
{
  Blynk.virtualWrite(6,temp);     // virtualpin 8 distance
}

void loop()
{
  Blynk.run();
  timer.run();
  if (pinValue==0)
  {
    // some code here
  }
  else //(digitalRead(sensor_pin) == 1)
  {
    // some other code
  }}

else {
  // a lot of code here
  pinValue=0;                     // here i set pinValue to 0 again in order to return to mode1
}
}
BLYNK_READ(V1)
{
  Blynk.virtualWrite(1,pinValue); // virtualpin 1 state
}

//End of program

BLYNK_READ() is documented as:

BLYNK_READ(vPIN)
BLYNK_READ defines a function that is called when device is requested to send it’s current value of Virtual Pin to the server.

That means it is called when the app or the Blynk server requests a state from the hardware/sketch, such as when the app first connects or reconnects to the Blynk server, or when the hardware reconnects to the Blynk server due to some network problem.
But if you just want to update the virtual pin V1 at an arbitrary time in your sketch, just call:
Blynk.virtualWrite(V1, pinValue);

at the point in your code where you want to "change" the button's current state. Not in the BLYNK_READ() function, but in your main code, such as:
[...]
else {
  // a lot of code here
  pinValue=0; //here i set pinValue to 0 again in order to return to mode1
  Blynk.virtualWrite(V1, pinMode);
}
[...]

source: Stack Exchange

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

sort: votes


text:
how to config the Arduino ADC'S input on A0 instead of use default?
I am try to build this AC-DC meter, the code original used default A3 as input, how can change the input on A0?
the link:
https://simple-circuit.com/arduino-autoranging-ac-dc-voltmeter-with-trms/
Thanks for help
Adam

/**************************************************************************
*
* Arduino autoranging AC/DC voltmeter.
* Voltage and frequency are printed on 1602 LCD screen.
* This is a free software with NO WARRANTY - Use it at your own risk!
* https://simple-circuit.com/
*
*************************************************************************/

#include <LiquidCrystal.h>   // include Arduino LCD library
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

// define autoranging channel pins
#define CH0  2
#define CH1  3
#define CH2  4
#define CH3  5

const uint16_t Time_Out = 50000,  // time out in microseconds
              Periods  = 10;     // number of periods of measurement (for AC voltage only)

// variables
byte ch_number;
const uint16_t res_table[4] = {2444, 244, 94, 47},  // voltage divider resistances in tenths kOhms
              total_res = 22444;                   // total resistance in tenths kOhms
uint16_t current_res;
volatile byte per;

void setup(void)
{
 pinMode(CH0, OUTPUT);
 pinMode(CH1, OUTPUT);
 pinMode(CH2, OUTPUT);
 pinMode(CH3, OUTPUT);

 lcd.begin(16, 2);     // set up the LCD's number of columns and rows
 lcd.setCursor(1, 0);
 lcd.print("Voltage:");

 ch_number = 0;
 ch_select(ch_number);

 // ADC and analog comparator configuration
 ADMUX  = 0x03;
 ADCSRA = 0x87;
 ADCSRB = (0 << ACME);  // select AIN1 as comparator negative input
 ACSR   = 0x13;         // turn on analog comparator

}

// analog comparator ISR
ISR (ANALOG_COMP_vect)
{
 byte count = 0;
 for(byte i = 0; i < 50; i++) {
   if ( ACSR & 0x20 )
     count++;
 }

 if(count > 48)
   per++;
}

// main loop
void loop()
{
 bool dc_flag = 0; // DC voltage flag bit
 int32_t sum = 0;  // sum of all readings
 uint16_t n = 0;   // number of readings (samples)

 ACSR = (1 << ACI);   // clear analog comparator interrupt flag
 ACSR = (1 << ACIE);  // enable analog comparator interrupt

 uint32_t current_m = micros();  // save current millis
 byte current_per = per;         // save current period number
 while ( (current_per == per) && (micros() - current_m < Time_Out) ) ;

 if( micros() - current_m >= Time_Out ) {  // if there's time out event ==> voltage signal is DC
   dc_flag = 1;
   for (byte i = 0; i < 200; i++) {
     ADCSRA |= 1 << ADSC;   // start conversion
     while(ADCSRA & 0x40);  // wait for conversion complete
     int16_t an = (int16_t)(ADCL | (uint16_t)ADCH << 8) - 511;
     sum += an;
     n++;         // increment number of readings
     delay(1);
   }
 }

 else {   // here, voltage signal is AC
   current_m = micros();  // save current millis()
   per = 0;
   while ( (per < Periods) && (micros() - current_m < (uint32_t)Time_Out * Periods) ) {
     ADCSRA |= 1 << ADSC;   // start conversion
     while(ADCSRA & 0x40);  // wait for conversion complete
     int32_t an = (int16_t)(ADCL | (uint16_t)ADCH << 8) - 511;
     sum += sq(an);  // sq: square
     n++;            // increment number of readings
   }
 }

 ACSR = (0 << ACIE);  // disable analog comparator interrupt
 uint32_t total_time = micros() - current_m;  // used to claculate frequency

 // voltage calculation
 float v;
 if(dc_flag)   // if voltage signal is DC
   v = (4 * sum)/n;   // calculate Arduino analog channel DC voltage in milli-Volts

 else  // here voltage signal is AC
   v = 4 * sqrt(sum/n);   // calculate Arduino analog channel RMS voltage in milli-Volts

 // claculate actual (input) voltage in milli-Volts (apply voltage divider equation)
 v = v * (float)total_res/current_res;
 v /= 1000;  // get voltage in Volts

 uint16_t v_abs = abs(int16_t(v));
 if( (v_abs >= 10 && ch_number == 0) || (v_abs >= 100 && ch_number == 1) || (v_abs >= 250 && ch_number == 2) ) {
   ch_number++;
   ch_select(ch_number);
   delay(10);
   return;
 }

 if( (v_abs < 220 && ch_number == 3) || (v_abs < 80 && ch_number == 2) || (v_abs < 8 && ch_number == 1) ) {
   ch_number--;
   ch_select(ch_number);
   delay(10);
   return;
 }

 char _buffer[8];
 lcd.setCursor(0, 1);
 if( v < 0)
   lcd.print('-');
 else
   lcd.print(' ');
 if(v_abs < 10)
   sprintf( _buffer, "%01u.%02u", v_abs, abs((int16_t)(v * 100)) % 100 );
 else if( v_abs < 100)
   sprintf( _buffer, "%02u.%01u", v_abs, abs((int16_t)(v * 10)) % 10 );
 else
   sprintf( _buffer, "%03u ", v_abs );

 lcd.print(_buffer);
 if(dc_flag)
   lcd.print("VDC        ");
 else {
   lcd.print("VAC ");
   // calculate signal frequency in Hz
   uint32_t period_time = total_time/Periods;
   float freq = 1000000.0/period_time;
   sprintf( _buffer, "%02u.%02uHz", (uint16_t)freq % 100, (uint16_t)(freq * 100) % 100 );
   lcd.print(_buffer);
 }

 delay(500);    // wait half a second

}

void ch_select(byte n) {
 switch(n) {
   case 0:
     digitalWrite(CH0, HIGH);
     digitalWrite(CH1, LOW);
     digitalWrite(CH2, LOW);
     digitalWrite(CH3, LOW);
     break;
   case 1:
     digitalWrite(CH0, LOW);
     digitalWrite(CH1, HIGH);
     digitalWrite(CH2, LOW);
     digitalWrite(CH3, LOW);
     break;
   case 2:
     digitalWrite(CH0, LOW);
     digitalWrite(CH1, LOW);
     digitalWrite(CH2, HIGH);
     digitalWrite(CH3, LOW);
     break;
   case 3:
     digitalWrite(CH0, LOW);
     digitalWrite(CH1, LOW);
     digitalWrite(CH2, LOW);
     digitalWrite(CH3, HIGH);
 }
 current_res = res_table[n];
}

// end of code.

The input to the ADC is selected by the four least-significant bits of
the “ADC Multiplexer Selection Register”, aka ADMUX. It is set to
analog input 3 by this line of code:
ADMUX  = 0x03;

Change this line to ADMUX = 0; and the ADC will read pin A0.

Your code is to hard to read, it is just a blob of characters on my screen but you have a pretty picture of the arduino. Change your code to use A0 instead of A3. Change your physical connection from A3 to A0 and you are all set. I miss read the code you posted.
It is a tricky circuit and he did all of the the registers directly, making it extremely hard to follow. I do not know the register set well enough to speak knowledgeable about what he is doing. The Optocouplers short out parts of the input divider network which he selects in his code. This is how he does the ranging. The optocouplers are drawn in reverse with the output on the left and the input on the right. Try this link to Nick Gammon's site: https://www.gammon.com.au/adc Also try this one: https://www.arduino.cc/en/Reference/PortManipulation

Thanks. Can you tell how to post a code better? There is not a A3, in the code, cause of it is default. that's why I don't how to change.

I have never done so at this point I will not try to explain it. There are many others that do a better job then I can.    ADMUX  = 0x03; Is one of the statements I believe you need to change it to   ADMUX  = 0x00; Let us know how you did? I chased the circuit back to simple circuits where somebody asked the same question. There answer was close to mine. "  If you need to change A3 to A0 you must change the analog pin definition in the code"

perfect ! charged ADMUX = 0x03 as ADMUX = 0x00, it works. Thank you.

Actually, charged ADMUX = 0x03 as ADMUX = 0x02, A2 as input; but charged ADMUX = 0x03 as ADMUX = 0x01, A1-A7 non of as input works! WHY?

Did you move the connection to A0? Also check any references to ADMUX.

Yes, I moved the input to relative pin and checked the above results. I didn't change any thing else, Don't know how to check the references to ADMUX?

The Optocouplers short out parts of the input divider network -- Er... no. They select different taps in the divider network to read the voltage from.

Thanks. I used this solution to MEGA2560, got the same result, but how to define the A5,A6,A8 on MEGA2560? I tried  some number like 0100, 0110 no GOOD.

@oldbin you should read the datasheet for the chip. It tells you what all the registers are and what the different values mean.

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


text:
Complier overwrote bootloader doing a non-programmer upload
Got this when uploading (no programmer) to a MkrZero.
I had downloaded the board's toolset via the IDE earlier, and uploading smaller sketches worked fine.  On a larger, more complex project, got this:
Sketch uses 31000 bytes (11%) of program storage space. Maximum is 262144 bytes.
Atmel SMART device 0x10010005 found
Device       : ATSAMD21G18A
Chip ID      : 10010005
Version      : v2.0 [Arduino:XYZ] Dec 20 2016 15:36:46
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : none
Security     : false
Boot Flash   : true
BOD          : false
BOR          : false
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.800 seconds

Write 31336 bytes to flash (490 pages)

[===                           ] 13% (64/490 pages)
[=======                       ] 26% (128/490 pages)
[===========                   ] 39% (192/490 pages)
[===============               ] 52% (256/490 pages)
[===================           ] 65% (320/490 pages)
[=======================       ] 78% (384/490 pages)
[===========================   ] 91% (448/490 pages)
[==============================] 100% (490/490 pages)
done in 0.234 seconds

Verify 31336 bytes of flash with checksum.
Verify successful
done in 0.075 seconds
CPU reset.

It sounds like it reset the chip completely... and Windows no longer sees a COM port from it via USB.
I've tried:
* The click and double-click on the board's reset button, including at the start of a new upload of a simple sketch
* Restarting the Windows machine
* Looking at device manager to see if any COM ports show up, even temporarily
* Same cable, same computer, different MKRZero - works
Main question:  What could there be in the project to have caused the compiler/loader to do this?    This is the 2nd time this project has triggered a reflash.   It does use the EEPROM API by A. Christian, but I've been able to use that before without this result.
2nd: Any other ways to recover the board?
Thank you for any guidance.

Hmm... Now getting a similar result on a small test-the-led-only sketch, on a brand-new just-out-of-the-box MkrZero.    But, that one seems to still be healthy from a running and native USB connection POV.   So, what causes this FAST_CHIP_ERASE?

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


text:
AVR-GCC can't call function located on fixed address
I wrote the following code:
#include <avr/io.h>

__attribute__((noinline, section(".app_start"))) void app_start() //app_start section starts at 0xFA0
{
    //register_packet_dispatch(packet_received);
    PORTB = 0xFF;
}

__attribute__ ((noinline)) void call_app()
{
    asm ("call 0xFA0\nret");
    //app_start();
}

int main()
{
    DDRB = 0xFF;
    //call_app();
    app_start();
    while(1){}
}

What I compiled with:
avr-gcc -Wl,--section-start=.reg_dispatch=0xdac -Wl,--section-start=.app_start=0xFA0 -mmcu=atmega328p -Os -o ubb.o ub_bootloader.cpp -DF_CPU=16000000

Which tries to simulate a host application that tries to call a relocated client application, begins from the 4000 address (0xFA0). If it would work, it's light up the LED wired to the arduino's 13. pin. But why app_start won't be called?
I've also inspected the output assemlby:
avr-objcopy -j .text -j .data -O ihex ubb.o ubb.hex

00000fa0 <_Z9app_startv>:
 fa0:   8f ef           ldi r24, 0xFF   ; 255
 fa2:   85 b9           out 0x05, r24   ; 5
 fa4:   08 95           ret

00000080 <main>:
  80:   8f ef           ldi r24, 0xFF   ; 255
  82:   84 b9           out 0x04, r24   ; 4
  84:   0e 94 d0 07     call    0xfa0   ; 0xfa0 <_Z9app_startv>
  88:   ff cf           rjmp    .-2         ; 0x88 <main+0x8>

Everything seems correct, why it isn't working at all?
Of course, if i remove the "noinline" attribute, it works. But that's a mirage, the compiler inlines the content of the function, but when I build this into an application, the code after the 0xFA0 address will be rewritten by the host application.

Note: app_start won't be called even if i call directly (calling app_start() shown in comment, instead of asm "call 0xFA0")

You mean -o ubb.elf?

but the version in question with app_start called from main works?

No, calling app_start directly from the main also doesn't work.

ubb.o: .elf and .o are just file endings file ubb.o says: ubb.o: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, not stripped.

Your program works fine on my Uno.

I've tried this code with arduino and it worked (i taught, of course, i can't add the "-Wl,--section-start=.app_start=0xFA0" flag to the compilation process so the function not gonna be moved to other section)
So i set the arudino IDE to show every command from the compilation to the end of the upload process.
The problem lies in the usage of avr-objdump, whose i found somewhere and used witouth overview the CLI switches.
I've also made a mistake when i wrote the question. To disassemble the object file, the right command is:
avr-objdump -S --disassemble  ubb.o > ubb.asm

THe command i've used to create hex file:
avr-objcopy -j .text -j .data -O ihex ubb.o ubb.hex

The working one (extracted from arduino):
avr-objcopy -O ihex -R .eeprom ubb.o ubb.hex

-j means keep only the given section(s)
while
-R means, remove only the given section(s)


text:
Atmega collecting and relaying interrupt calls
I like to collect all possible interrupt and relay them to an alternative handler interrupt table what the user can set.
In order to do this i have to:
   1) collect all/any interrup request
   2) identify where is the interruption came from
   3) relay the call to another table the user pointed.
If you familiar with interrupts you know if you registers a single function to all interrupt handler there's no way to idenfity the source of the interrupt.
But registering unique interrupt handler that carries the information of the source and calls another function to dispatch call, for each interrupt is a code space wasting. Eg.: the atmega328 has 24 interrupt handlers. Each of the is compiled with the avr-gcc consumes 76 bytes.

But i have and idea how it is possible to register one handler function and identify the source:
00000000 <__vectors>:
   0:   0c 94 34 00     jmp 0x68    ; 0x68 <__ctors_end>
   4:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
   8:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
   c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>

If i define an interrupt handler (even if it can fit the 4 byte space) a jmp instruction is placed. If it can be replaced to eg.: call 0xa2 (which can fit in 4 bytes), is can be used to identify the interrupt source address.
Because call stores the return address, the function started at 0xa2 can read back that address and therefor idenfity the caller. Then add an extra pop (pop the stack address accumulated by the call at the interrup table) and reti (to return as like from an interrupt handler) after the function body.
If this can work theorically, to achieve this only one question remains:
How can i replace the jmp instructions to call in interrupt table?

The interrupt vector table is provided by the C runtime. It is
not normally intended to be overridden by user code. You can, however,
do it, if you replace the whole C run time by your own, and compile your
sketch with the -nostartfiles option.
I have played this game once I was trying to accurately assess interrupt
latencies. See the details in this answer (the answer is long,
but you can go right to the last section).

The answer i've accepted is the proper answer for the problem i asked.
However replacing the C runtime requires to attach and maintain a lot of crt.S files oiginally related to the GCC. To avoid this i "slept several times over this prolem" and came out another solution.
After compiling the host application that have to redirect the interrupt calls
(script source). I wrote a utility that rewrites every interrupt jumps at the beginning of the ihex (source) with an offset to the target application.
Ok this solution doesn't collect and identify and relay the incoming interrupts, just relay them. As far as there's no target application, nothing enables these interrupts and cause fault. This solution also doesn't use extra code space.


text:
I keep on getting a stray '\302' in program error.How do I fix it.This is in arduino uno
#include <LiquidCrystal.h>

int trigPin = 13;  //sensor's trigger pin connected to pin 13
int echoPin = 7;  //sensor's echo pin connected to pin 11
float pingTime;  //time for the ping to hit the target and back
float ss;  //we will calculate the speed of sound
float td = 13; //target distance.

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

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);  //TRIG AS OUTPUT
  pinMode(echoPin,INPUT);  //EHO AS AN INPUT

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.println(ss);

}

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

  digitalWrite(trigPin,LOW);  //set trig pin low.
  delayMicroseconds(2000);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin,LOW);
  pingTime = pulseIn(echoPin,HIGH);  //measure ping time traveltime in microseconds.
  ss= 2*td / pingTime;  //gives us speed in inches per microseconds.
  ss=ss/63360*1000000*3600;  //gives us speed in miles per hour.
  Serial.print("The speed of sound is ");
  Serial.print(ss);
  Serial.println(" miles per hour");

  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink(0);
  delay(3000);

}

Your program doesn't even begin to compile. Maybe you should worry more about where you are defining things first?

And I see no \302 in that program. Are you actually showing us the right program here?

The variable lcd will be out of scope in loop.

Please add more details. What have you tried? What was the result.

The culprits are the no-break spaces (U+00A0) you sometimes use in your
indentation. Each of them, when encoded in UTF-8, is represented by the
pair of bytes 0xc2 0xa0 (or 0302 0240 in octal). You should indent
with regular spaces (U+0020) instead.
Specifically, you have no-break spaces as the first characters of each
of the following 8 lines:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.println(ss);
[...]
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink(0);
delay(3000);

Just try to removes extra spaces that are outside the scopes (curly braces { and }) and it'll work fine.

Beware when you copy code from sites which have formatead fonts in their content. As you copy and paste these font-formatead codes, chances are that you copy the font's formats as well. Once you paste these formatead fonts on your code, the text editor from the Arduino IDE will not recognize the special characters used on the font's formatting; thus, it will not show them on your screen. However, the compiler will read them and will strive to compile them as if they were part of your code. Since the compiler does not "understand" these special characters, it will warn you about their existence by identifying them as "stray" pieces of code. This is why some code-related sites, such as GitHub, gives you the opportunity of copying RAW CODE, so you do not copy the formatead fonts that some developers use to showcase their much appreciated contributions. I sincerely hope this works for you. Best regards.

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


text:
Gate opener code help - should be working
Can anyone see any errors in my code that would affect the opening command? Upon first power up the open command (remoteA) works fine.
After that the opening command does what its supposed to except it only momentarily fires "digitalWrite (power, LOW)" command.  It should be set LOW for the same amount of time as "digitalWrite (openGate, LOW)", but it doesnt.
Strange thing is, the close command code is almost identical and it always works as it should, no problems.
Any suggestions? (hopefully the code pastes in here ok, its acting weird)
/*
 *  Swing Gate Opener with 2Ch remote, gate lock, motor, buzzer, amp monitor
and two independent limit switches
 *
 *  By Darren Clarke
 *
 */
int current = A0;  // monitor motor current
int buzzer = 3;  // operation buzzer
int power = 5;  // 24v power on/off
int remoteOpen = 6;  // remote button A to digital pin 6
int remoteClose = 7;  // remote button B to digital pin 7
int openGate = 8;  // open gate to motor on digital pin 8
int closeGate = 9;  // close gate to motor on digital pin 9
int gateLock = 10;  // gate lock connected to digital pin 10

// variables
int openRelay = 0;  // variable to store the motor direction
int closeRelay = 0;  // variable for previous motor direction
int remoteA = 0;  // variable for remote A condition
int remoteB = 0;  // variable for remote B condition
int lock = 0;  // varialbe for gate lock
int mA = 0;  // variable for motor current
unsigned long previousMillisA = 0;
unsigned long previousMillisB = 0;
unsigned long currentMillisA = 0;
unsigned long currentMillisB = 0;

void setup() {
    // put your setup code here, to run once:
    pinMode(buzzer, OUTPUT);   // sets the digital pin 4 as output
    pinMode(power, OUTPUT);   // sets the digital pin 5 as output
    pinMode(remoteOpen, INPUT);   // sets the digital pin 6 as input
    pinMode(remoteClose, INPUT);   // sets the digital pin 7 as input
    pinMode(openGate, OUTPUT);   // sets the digital pin 8 as output
    pinMode(closeGate, OUTPUT);   // sets the digital pin 9 as output
    pinMode(gateLock, OUTPUT);   // sets the digital pin 10 as output
    digitalWrite(closeGate, HIGH);   // sets relay to open
    digitalWrite(openGate, HIGH);   // sets relay to open
    digitalWrite(power, HIGH);   // sets relay to open
    digitalWrite(gateLock, HIGH);   // sets relay to open
    analogWrite(buzzer, 0);   // sets buzzer off
    Serial.begin(9600);
}

void loop() {
    // put your main code here, to run repeatedly:
    remoteA = digitalRead(remoteOpen);   // read remote A input
    remoteB = digitalRead(remoteClose);   // read remote B input
    openRelay = digitalRead(openGate);   // read state of openGate
    closeRelay = digitalRead(closeGate);   // read state of closeGate
    lock = digitalRead(gateLock);   // read state of gate lock
    mA = analogRead(current);   // read value of motor current
    currentMillisA = millis();
    currentMillisB = millis();
    Serial.print("aIn ");
    Serial.print(remoteA);
    Serial.print(", bIn ");
    Serial.print(remoteB);
    Serial.print(", Open ");
    Serial.print(openRelay);
    Serial.print(", Close ");
    Serial.print(closeRelay);
    Serial.print(", Lock ");
    Serial.print(lock);
    Serial.print(", mA ");
    Serial.print(mA);
    Serial.print(", cur ");
    Serial.print(currentMillisA);
    Serial.print(", prev ");
    Serial.print(previousMillisA);
    Serial.println(" ");

// to open the gate
    if ((remoteA == HIGH) && (remoteB == LOW)) {
        delay(500);   // time for gate direction reversal
        digitalWrite(power, HIGH);   // stops previous movement
        digitalWrite(closeGate, HIGH);   // Stop gate open command
        analogWrite(buzzer, 100);   // starts buzzer
        digitalWrite(gateLock, LOW);   // energize lock open (unlock state)
        delay(500);   // time for lock to open
        digitalWrite(openGate, LOW);   // actuate gate open
        digitalWrite(power, LOW);   //  supplies 24v power
        previousMillisA = millis();  // set time references
        currentMillisA = millis();  // set time references
    }

// to stop open command
    if ((closeRelay == HIGH) && (currentMillisA - previousMillisA) >= 6000) {
        digitalWrite(gateLock, HIGH);   // denergize lock (locked state)
        digitalWrite(openGate, HIGH);   // stop open relay to motor after open
        digitalWrite(power, HIGH);   // remove 24v power
        analogWrite(buzzer, 0);
    }

// to close the gate
    if ((remoteB == HIGH) && (remoteA == LOW)) {
        delay(500);   // time for gate direction reversal
        digitalWrite(power, HIGH);   // stops previous movement
        digitalWrite(gateLock, HIGH);   // de-energize lock on quick reverse
        digitalWrite(openGate, HIGH);   // Stop gate close command
        analogWrite(buzzer, 100);   // starts buzzer
        digitalWrite(closeGate, LOW);   // actuate gate close
        digitalWrite(power, LOW);   // supplies 24v power
        previousMillisB = millis();  // set time references
        currentMillisB = millis();  // set time references
    }

// to stop close command
    if ((openRelay == HIGH) && (currentMillisB - previousMillisB) >= 6000) {
        digitalWrite(closeGate, HIGH);   // stop close relay to motor
        digitalWrite(power, HIGH);   // remove 24v power
        analogWrite(buzzer, 0);
    }

    delay(100);
}

Ok, i figured it out.
Thanks all for your help.
It only happens on the A channel because its first in the series of the code.  The turn off command after the timer isnt specific enough.  The if conditions are met on the B channel so it keeps turning the power off immediately.
I just need be more specific in my if command or make another tweek.
Thanks guys,  your suggestions caused me to do much more digging and code adjustments.
Its working like a peach now.
Thanks.


text:
Which is RX and TX pin of the HM-10 module?
i recently bought hm-10 ble module which works using cc2541 ti SOC but problem is there are many ports the the bluetooth module but the seller has not mentioned which is rx and tx pins so...
I wanted to connnect it with Arduino uno and use AT commands but now i am stuck can anyone in this community help me finding which pin is Tx and Rx and the data sheet of the module is difficult to find on the net .....

http://www.electrodragon.com/w/EY-08 might help

Seems like the link is broken. Here is another https://github.com/nickswalker/ble-dev-kit/wiki/HM-10-Pinout

That's not an HM-10 but an EY-08. It's the same chip, but it's been provided in a different footprint (and maybe with different firmware installed).
Pin P03 is TX and pin P02 is RX.
The AT command set, pinouts, and examples for wiring it are detailed here (Thanks to Mikael Patel for finding that link).


text:
Powering Motor doesnt work from Digital Pin, but works on 5V power
I am building a little car project, and I have come across an issue that has made me go mental.
I have a single motor (3V-5V), that on direct 3.3V & 5V output works fine. However, when I connect this to a digital port, it for some reason doesn't power. Of course, I first thought it was not supplying correct power, so I got myself a voltage meter and tried that. 3.3V outputs, well 3.3V, all fine. The digital port outputs 4-5V (when it is coded to). So here is my question: Why aren't my motors powering/turning?

Power is made up of two values, not one. Besides the voltage there is the current (P=VI), and it's the current you are lacking.
A motor needs a large amount of current to start turning (called the stall current) and a digital I/O pin can only supply a relatively small amount (absolute maximum 40mA, recommended maximum 25mA). The power pins though can supply many hundreds of mA.
You should never try and power a motor directly from an I/O pin since you risk damaging the I/O pin.  Instead you should use the I/O pin to control an NPN transistor or N-channel FET, which is then used to switch the power (actually the ground connection) to the motor from one of the power pins.
Here is a good tutorial: http://www.circuitstoday.com/pwm-generation-and-control-using-arduino

authors: Николай Николаевич


text:
Where to start?
I am totally new to Arduino and I'm a real beginner with electronics and robotics. I would like to know where to start, knowing that my ultimate goal is to build an autonomous robot (I know that I will not be able to do this project before learning a lot of things). I am a developer so I have no problem with C and C++, actually I am using C++ at work.
Thanks

After typing my answer, I wouldn't be too surprised if someone tries to close your question as "too broad". You probably need to focus it a bit to guard against this possibility. See, for example: Getting started

I would start with a lot of small projects, each designed to give you confidence over one small aspect. For example:

Detect variations in light with an LDR
Operate a motor (there are various types of motors) - including controlling one with a MOSFET or BJT transistor
Blink LEDs
Connect something with a fancier interface (eg. I2C or SPI) and get the hang of "talking" to a more sophisticated interface chip (you'll probably need this for things like balancing)
Try distance detection. Eg. with bouncing light or sound off an obstacle
Communicate between two Arduinos - get used to communications protocols, reliability, packet loss, etc.
Get used to detecting switch presses, either individual ones, or a keypad (or both)
Look into reverse polarity protection
Look into detecting low voltages on your batteries
Try radio communications (probably need to send your robot instructions) - there are various different ways of doing that
Possibly experiment with motor-driver boards (eg. H-bridges) which you may need for driving wheels
Investigate reading continuous values (eg. potentiometers, rotary encoders)
Investigate read-outs (eg. 7-segment LED displays, or LCD displays)
Investigate generating sounds (beeps, tunes)

You could take a look at my radio controlled car project. I look into some of those things there, and describe how I handled them.

I would do these things initially on the bench. Don't try to assemble something fancy until you have some experience with how the individual parts work.

What an answer!

well... you probably should try this as well.... http://www.allitebooks.com/?s=arduino there's good way to start with.

It's sounds silly, but just get an UNO, a breadboard, wires, 1 resistor (220 ohm) and an LED.
Wire up a LED circuit, and program the Arduino to flash the LED.
(There's a million examples of this all over the internet).
Without getting into any sort of heavy circuits or complex programming, you'll have a quick stress-free introduction to Arduino.
This will teach you:

using a breadboard
wiring digital ports on the Arduino
polarity of components (LED yes, Resistor no)
using the Arduino IDE
uploading to the board

This is a great jumping-in point because it's reasonably fool-proof.
Sure you can eventually be PID-controlling the balance of a 2-wheel robot.  But build yourself a working foundation of good knowledge first.

Personally I think the best way to start is hands on with a small robot. I mean the kind that have a couple of wheels, are circular and only a few inches in diameter. You can add many kinds of sensors or actuators as you learn. You get to see it move and hold it and pick it up.
The idea is to start with basic LED control and then get motors turning, sensors on, and then improvements and upgrades.
If you're ok at coding then electronics may be the bottle neck. Get a good book is my advice. As far has hardware the EEVBLOG guy Dave gives a good run down on what he recommends here.
Just start.


text:
Increment in switch statement not working
No matter how I rearrange this, the increment compare always returns false....
I have even taken it out of the if, and put it in its own if:
int buttonFSM(button *ptrButton)
{
    int i;
    i = digitalRead(ptrButton->pin);
    switch(ptrButton->buttonState)
    {
    case SW_UP:
        if(i==0 && ++ptrButton->debounceTics == DBNC_TICS) //swtich went down
        {
            ptrButton->buttonState = SW_DOWN;
            ptrButton->debounceTics = 0;
            return SW_TRANS_UD;
        }
        ptrButton->debounceTics = 0;
        return SW_UP;
    case SW_DOWN:
        if(i==1 && ++ptrButton->debounceTics == DBNC_TICS) //switch is back up
        {
            ptrButton->buttonState = SW_UP;
            ptrButton->debounceTics = 0;
            return SW_TRANS_DU;
        }
        ptrButton->debounceTics = 0;
        return SW_DOWN;
    }
}

I get the impression that ++ptrButton->debounceTics needs some bracketing. I fear the compiler is reading it as (++ptrButton)->debTic and you actually mean ++(ptrButton->debTics). You are increasing ptrButton's value, i.e. where it should point to, not the value of what it points to. I would also add some brackets to break up the if statement conditions, although I think that's more my preference than a syntax requirement: if((i==0) && (++(ptrButton->debounceTics) == DBNC_TICS)).

I'd go further and say that side effects like this in the expression statement  should be avoided for example:
ptrButton->debounceTics = ptrButton->debounceTics + 1; if (... expressions ...)

@Kolban The intention of the code is unclear, so it may be a requirement that it's written like this. Short circuit evaluation means that if i!=0 (or 1 in the second if statement), debounceTics will not be incremented.

Looks to me like the path where the if doesn't happen are getting you. You don't show what DBNC_TICS is set to, but I'm assuming it's > 1.
ptrButton->debounceTics will never be greater than 1 because you always:
    ptrButton->debounceTics = 0;

-1: the code is clearly a subroutine from loop() (or another function) so you cannot make assumptions on what debounceTics's treatment ought to be inside this function.

Why is this marked down? This is the correct explanation.

@CharlieHanson No assumptions - it's always being set to 0.

The error is due to wrong expectations on operators precedence:
++ and -> have the same precedence, so they are evaluated left to right.
See http://en.cppreference.com/w/c/language/operator_precedence .
Overall, the lack of parenthesis makes the readability poor.
The code can be improved by dropping the switch and simply checking that the current value is equal to the previous value through the duration of the sampling period.
Then read the value and decide if it's high or low.
But even this might be a poor choice, because it simply samples the value periodically and can miss changes that are not intercepted by the sampling.
Depending on the application, it might be preferrable (certainly it is more precise) to use interrupts on both edges (rising and falling) and a timeout: reset the timer at every interrupt. If the timer expires undisturbed, use the level read at the last interrupt.

  if(i==0 && ++ptrButton->debounceTics == DBNC_TICS) //swtich went down
    {
        ptrButton->buttonState = SW_DOWN;
        ptrButton->debounceTics = 0;
        return SW_TRANS_UD;
    }
    ptrButton->debounceTics = 0;

I'm going to agree with user3877595 but explain why, as his/her answer got a downvote.
DBNC_TICS has to be > 1, right? Otherwise what is the point?
We want to debounce after "x" ticks, and let's assume that the number of ticks is initially zero.
If DBNC_TICS is == 1 then this is always true:
++ptrButton->debounceTics == DBNC_TICS

Therefore that test is useless.
If DBNC_TICS > 1 then it will not execute the "if" block and execute this instead:
    ptrButton->debounceTics = 0;

So ptrButton->debounceTics is back to zero, and we are back to square 1.
Therefore the test will always be false.

No matter how I rearrange this, the increment compare always returns false....

As stated in the question.


text:
How to generate Chirp Signal using Arduino
i would like to generate Chirp Signal (Frequency Sweep) using Arduino. i have searched a lot in internet but didn't find anything.
Basically, any parameters is also ok. But the concept is what i am searching for.
The signal will be sent to the DAC of the Arduino board.
Edit
I would like to generate sine wave signal from 3kHz up to 100kHz sweep frequency with amplitude peak to peak 1.5 volt.
thanks for your support.

That's a potentially complex subject. Providing more detail about what you are trying to do and why will help you to get better answers (or any answers). I assume you mean chirp in the DSP sense -  swept-frequency cosine signal with unity amplitude and continuous phase. OR you could mean simply a frequency swept signal - as people sometimes use the term. Or you may be talking about crickets :-).So ...?

(1) What frequency range, and what sweep rate, do you want? (2) Why do you want it? ie, what is it for?  (3) What "DAC module" do you mean?  Some shield?  [Please edit your question to answer these items, rather than answering in comments.]

If you're ok with starting with square wave signals, this can be done on an Arduino.
You need to do the following:

Configure a 16-bit Timer to CTC mode
Select the right prescaling
Add a RC low pass filter to the output and voltage divider

Configure a 16-bit Timer to CTC mode
Assuming I'm using Timer 1 and OCR1A:
TCCR1A |= (1<<COM1A0); // Toggle OC1A on match
TCCR1B |= (1<<WGM12); // Clear to Compare mode
TCCR1B |= (1<<CS10); // No prescale

Select the right prescaling
In case you're wondering, prescales are used when the MCU clock is much faster than the output you desire.
Without prescaling, the highest frequency is 16MHz/2 = 8MHz, and the lowest frequency would be 8MHz / 2^16 = 122Hz . Which covers the range of frequencies that we want.
Setting OCR1A value to 80 gives you a frequency of 100kHz
Setting OCR1A value to 2667 gives you a frequency of 2.9996kHz
You can then control the chirp like so:
// Linear rise in wave period
int x = 10;
for (int x=80; x < 2668; ++x){
  OCR1A = x;
  delay(10); // 10ms delay
}

Add a RC low pass filter to the output and voltage divider
Making the perfect sine waves may be too troublesome, so we'll resort to the poor man's sine wave.
Here's the poor man's implementation by TI (still require quite a few parts.)
Personally, I'm cheap so I'd go for the RLC approach. ;-)

Recommend to use a VCO PLL as external hardware device to get the wanted variable-frequency signal. The DAC output from Arduino can control the voltage to external VCO PLL module. Here is the link for an app note for VCO PLL from Vectron.
http://www.vectron.com/products/vcxo/vcxo.pdf
Hope it helps.

Since you mentioned SINE wave, I think you're seeking a SWEEP signal.  A chirp is a much more complex sound.
To get a sine wave sweep, you probably want a sine function that doesn't use up most of the Arduino executable space.
You can use one of the compact sin(theta) functions that leverage a simple table of values. Just pull the code you need from the cordic.c here: https://people.sc.fsu.edu/~jburkardt/c_src/cordic/cordic.html. C runs in Arduino sketches almost out of the box. You may or may not need some things from the cordic.h. That's why I said "almost". The cordic_prb.c test file has a function test002() that shows you how to call the sine function.
Letting theta = t * (t + k), you will get your sweep, with your instantaneous frequency, f = 2 * pi * (t + k).  You will need to calculate the correct k and set t_max to end your loop.  This can be obtained from the above formula and your f_min of 3kHz and f_max of 100kHz.
You can use a linear translation to get the sample in the range of values that you want: s = s_center + s_peak * sin(theta) / 2, but you will need to calculate your s_ave and s_peak from your center voltage, V_center, and your peak to peak voltage, V_peak.  So there are two translations.  This second one depends on the Voltage range of your Arduino board DAC.
Record your sample and voltage range for the board and then Work backward from Voltage range to V_center and V_peak to s_center and s_peak to your two coefficients to multiply and add to your sin(theta) result.
It's just a little algebra and some integration of some code, and you've got your SWEEP generator.
Also remember that boards like the Uno and Mega do not have a real D-to-A converter, so they will only give you a rectangular wave that has digital noise over the primary harmonic that approximates your sweep.  Use the Due to avoid lots of digital noise. That's the down side of the pulse width modulation of the lower end Arduino chips.
Either way, you may want to attenuate higher frequencies from any type of D-to-A conversion with a simple passive (RC) or active (op amp) low pass filter.


text:
Aduino 7 segment dice project
I am struggling with the code that I should write for my project. I finished my breadboard but I have never learnt programming before so I cannot write the program for the dice.
My project is to make the dice output random numbers when the button is pressed.
This is what I have completed already. I just want to know how to complete the program to make it work for my arduino.

This is the code so far:
int leda = 2;
int ledb = 3;
int ledc = 4;
int ledd = 5;
int lede = 6;
int ledf = 7;
int ledg = 8;
int ledh = 9;
int leda1 = A0;
int ledb1 = A1;
int ledc1 = A2;
int ledd1 = A3;
int lede1 = A4;
int ledf1 = A5;
int ledg1 = A6;
int ledh1 = A7;

void setup()
{
    Serial.begin(9600);
    pinMode(leda, OUTPUT);
    pinMode(ledb, OUTPUT);
    pinMode(ledc, OUTPUT);
    pinMode(ledd, OUTPUT);
    pinMode(lede, OUTPUT);
    pinMode(ledf, OUTPUT);
    pinMode(ledg, OUTPUT);
    pinMode(ledh, OUTPUT);
    pinMode(leda1, OUTPUT);
    pinMode(ledb1, OUTPUT);
    pinMode(ledc1, OUTPUT);
    pinMode(ledd1, OUTPUT);
    pinMode(lede1, OUTPUT);
    pinMode(ledf1, OUTPUT);
    pinMode(ledg1, OUTPUT);
    pinMode(ledh1, OUTPUT);

    pinMode(12, INPUT);

    digitalWrite(12, HIGH);
}

if (number == 1)
{
    digitalWrite(2, HIGH);
    digitalWrite(7, HIGH);
}

else if (number == 2)
{
    digitalWrite(3, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    delay(200);
}
else if (number == 3)
{
    digitalWrite(3,HIGH);
    digitalWrite(2,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    delay(200);
}

else if (number == 4)
{
    // do number 4
}

else if (number == 5)
{
    // do number 5
}

// ... etc
// Additional 'numbers' have been removed for brevity

Proper formatting, come on! It's a pain to add four spaces to the front of each line (I'm not being sarcastic, it really is!) but nobody likes reading it when it's like this. I'll edit it this time...

This looks horribly repetitive. See Controlling 7 segment LED display from Arduino for an example program that does work, and my comment to the same post for a more compact way of writing all this.

@chaaarlie2 It's not a pain - just highlight it and press the { } button above the editor.

Don't forget you need to turn off the segments you no longer need on when you change from one number to another...

@Majenko: I didn't know that (or, rather, I think I forgot it); I'm horribly embarrassed.

@chaaarlie2 To be fair, the icon's not exactly very meaningful - easy to overlook it.

@Majenko ALL THOSE HOURS OF SPACEBAR-PRESSING I'LL NEVER GET BACK.

About random numbers
What you are trying to achieve is actually not that easy. An Arduino is
basically a computer, and as any computer, it is designed to execute
instructions in a very deterministic fashion. Computers are not good
at randomness and, unless fitted with dedicated hardware, they cannot
generate random numbers. Given this, you are left with two options:

pseudo-random number generators
entropy gathering

The first is the easiest:
int first_dice  = random(1, 7);  // 1 (inclusive) to 7 (exclusive)
int second_dice = random(1, 7);

and voilà! You have two random-looking numbers. They are random-looking
in the sense that you will find no obvious pattern in any sequence of
numbers you draw. However, if you reset your Arduino, either with the
reset button or by power-cycling it, it will give you the exact same
sequence as in the first run. Thus, pseudo-randomness in useless unless
you commit to never unpower your circuit. It is a good starting point,
however, if your main goal is to get started with Arduino programming.
Entropy gathering means getting some randomness from outside the
Arduino: you would connect it to some source of randomness and perform
some measurement that has unpredictable outcome. A human being is a good
source of randomness: if you require the user to press a button before
displaying the dice value, the timing of the button press is a good
random source. The micros() function can be used to get the current
time with 4 µs resolution, which is more than enough for this
purpose. Entropy gathering is usually used in tandem with pseudo-random
number generators, as a way to seed them, like this:
wait_for_the_user_to_press_a_button();
randomSeed(micros());
int first_dice =  random(1, 7);
int second_dice = random(1, 7);

If you cannot have human interaction, you could try to get some
electromagnetic noise by performing an analogRead() on a floating pin.
Ideally you would connect that pin to an analog noise source. See the
first comment to this answer for more information on this option.
About arrays and loops
You should definitely try to find a good tutorial about arrays and
loops. Whenever you find yourself writing tons of almost-identical lines
of code, you should wonder whether you can replace that repetition with
a loop. For example, for displaying the digit 1, you may write:
if (number == 1) {
    digitalWrite(leda,  LOW);
    digitalWrite(ledb, HIGH);
    digitalWrite(ledc, HIGH);
    digitalWrite(ledd,  LOW);
    digitalWrite(lede,  LOW);
    digitalWrite(ledf,  LOW);
    digitalWrite(ledg,  LOW);
}

(I am using the "canonical" A–G letter assignments, and yes, you should
also take care of setting to LOW the segments you want to be off).
This code is an obvious candidate for being replaced by a loop:
if (number == 1) {
    for (int segment = 0; segment < 7; segment++)
        digitalWrite(leds[segment], digit1[segment]);
}

This requires that you first define the following arrays:
//                A     B     C     D     E     F     G
int leds[]   = {  2,    3,    4,    5,    6,    7,    8 };
int digit1[] = { LOW, HIGH, HIGH,  LOW,  LOW,  LOW,  LOW};

This logic can be pushed one level further by using a two-dimensional
array (an array of arrays): instead of defining six arrays digit1,
digit2... digit6, you create an array of arrays like this:
int digits[][7] = {
         /*          A     B     C     D     E     F     G  */
         /* 1 */  { LOW, HIGH, HIGH,  LOW,  LOW,  LOW,  LOW},
         /* 2 */  {HIGH, HIGH,  LOW, HIGH, HIGH,  LOW, HIGH},
         ...
};

and you use digits[number] instead of digit1, etc. This way you get
rid of the whole if () ... else if () chain, replaced by:
for (int segment = 0; segment < 7; segment++)
    digitalWrite(leds[segment], digits[number-1][segment]);

Take care though that in C++ arrays are indexed from zero, which is why
you need to use number-1 as the index in digits. If you have more
than one die (which is your case), you can also put their pin
assignments in a two-dimensional array. Then all the dice updating code
would be wrapped inside a loop indexed by the die number. Putting all
this together you end up with something like this:
// Pin assignments.
int leds[][7] = {
   /*                A     B     C     D     E     F     G  */
   /* 1st die */  {  2,    3,    4,    5,    6,    7,    8 },
   /* 2nd die */  { A0,   A1,   A2,   A3,   A4,   A5,   A6 }
};

// 7-segment "font".
int digits[][7] = {
         /*          A     B     C     D     E     F     G  */
         /* 1 */  { LOW, HIGH, HIGH,  LOW,  LOW,  LOW,  LOW},
         /* 2 */  {HIGH, HIGH,  LOW, HIGH, HIGH,  LOW, HIGH},
         /* 3 */  {HIGH, HIGH, HIGH, HIGH,  LOW,  LOW, HIGH},
         /* 4 */  { LOW, HIGH, HIGH,  LOW,  LOW, HIGH, HIGH},
         /* 5 */  {HIGH,  LOW, HIGH, HIGH,  LOW, HIGH, HIGH},
         /* 6 */  {HIGH,  LOW, HIGH, HIGH, HIGH, HIGH, HIGH}
};

void setup()
{
    for (int die = 0; die < 2; die++) {
        for (int segment = 0; segment < 7; segment++) {
            pinMode(leds[die][segment], OUTPUT);
        }
    }
}

void loop() {
    for (int die = 0; die < 2; die++) {
        int number = random(1, 7);
        for (int segment = 0; segment < 7; segment++)
            digitalWrite(leds[die][segment], digits[number][segment]);
    }
    delay(200);
}

This is still lacking the entropy gathering phase discussed above.

Connecting the analogue input to the collector of a run-of-the-mill transistor, with the emitter grounded and base open helps to make a noisy input. There's actually plenty of information about random noise generation techniques for this purpose on the internet.

I made it so at least it compiles. It should loop through the numbers.
As for the circuit; you really should add a resistor to every segment, instead of just one the the common cathode. Otherwise the brightness will be different if more segments are on.
int number = 1;
int number1 = 1;

int leda = 2;
int ledb = 3;
int ledc = 4;
int ledd = 5;
int lede = 6;
int ledf = 7;
int ledg = 8;
int ledh = 9;

int leda1 = A0;
int ledb1 = A1;
int ledc1 = A2;
int ledd1 = A3;
int lede1 = A4;
int ledf1 = A5;
int ledg1 = A6;
int ledh1 = A7;

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

    pinMode(leda, OUTPUT);
    pinMode(ledb, OUTPUT);
    pinMode(ledc, OUTPUT);
    pinMode(ledd, OUTPUT);
    pinMode(lede, OUTPUT);
    pinMode(ledf, OUTPUT);
    pinMode(ledg, OUTPUT);
    pinMode(ledh, OUTPUT);

    pinMode(leda1, OUTPUT);
    pinMode(ledb1, OUTPUT);
    pinMode(ledc1, OUTPUT);
    pinMode(ledd1, OUTPUT);
    pinMode(lede1, OUTPUT);
    pinMode(ledf1, OUTPUT);
    pinMode(ledg1, OUTPUT);
    pinMode(ledh1, OUTPUT);

    pinMode(12, INPUT);
    digitalWrite(12, HIGH);
}
void loop() {

    // turn off all leds
    digitalWrite(leda, LOW);
    digitalWrite(ledb, LOW);
    digitalWrite(ledc, LOW);
    digitalWrite(ledd, LOW);
    digitalWrite(lede, LOW);
    digitalWrite(ledf, LOW);
    digitalWrite(ledg, LOW);
    digitalWrite(ledh, LOW);

    digitalWrite(leda1, LOW);
    digitalWrite(ledb1, LOW);
    digitalWrite(ledc1, LOW);
    digitalWrite(ledd1, LOW);
    digitalWrite(lede1, LOW);
    digitalWrite(ledf1, LOW);
    digitalWrite(ledg1, LOW);
    digitalWrite(ledh1, LOW);

    if (number == 1)
    {
        digitalWrite(leda, HIGH);
        digitalWrite(ledf, HIGH);
        delay(200);
    }
    else if (number == 2)
    {
        digitalWrite(ledb, HIGH);
        digitalWrite(leda, HIGH);
        digitalWrite(ledd, HIGH);
        digitalWrite(ledh, HIGH);
        digitalWrite(ledg, HIGH);
        delay(200);
    }
    else if (number == 3)
    {
        digitalWrite(ledb,HIGH);
        digitalWrite(leda,HIGH);
        digitalWrite(ledd,HIGH);
        digitalWrite(ledf,HIGH);
        digitalWrite(ledg,HIGH);
        delay(200);
    }
    else if (number == 4)
    {
        digitalWrite(ledc,HIGH);
        digitalWrite(ledd,HIGH);
        digitalWrite(leda,HIGH);
        digitalWrite(ledf,HIGH);
        delay(200);
    }
    else if (number == 5)
    {
        digitalWrite(ledb,HIGH);
        digitalWrite(ledc,HIGH);
        digitalWrite(ledd,HIGH);
        digitalWrite(ledf,HIGH);
        digitalWrite(ledg,HIGH);
        delay(200);
    }
    else if (number == 6)
    {
        digitalWrite(ledb,HIGH);
        digitalWrite(ledc,HIGH);
        digitalWrite(ledd,HIGH);
        digitalWrite(ledf,HIGH);
        digitalWrite(ledg,HIGH);
        digitalWrite(ledh,HIGH);
        delay(200);
    }

    if (number1 == 1)
    {
        digitalWrite(A4, HIGH);
        digitalWrite(A1, HIGH);
        delay(200);
    }
    else if (number1 == 2)
    {
        digitalWrite(A5, HIGH);
        digitalWrite(A4, HIGH);
        digitalWrite(A7, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A2, HIGH);
        delay(200);
    }
    else if (number1 == 3)
    {
        digitalWrite(A5,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A7,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        delay(200);
    }
    else if (number1 == 4)
    {
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        digitalWrite(A4,HIGH);
        digitalWrite(A2,HIGH);
        delay(200);
    }
    else if (number1 == 5)
    {
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        delay(200);
    }
    else if (number1 == 6)
    {
        digitalWrite(A5,HIGH);
        digitalWrite(A6,HIGH);
        digitalWrite(A7,HIGH);
        digitalWrite(A0,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,HIGH);
        delay(200);
    }

    number = (number%6) + 1;//show next number the next loop
}


text:
Insane heat development with ESP8266
I have a ESP8266 on a Wemos D1 mini board. Simple "Rainbow with FastLED" animation. Shouldn't do much but the board gets so hot I can't touch it and it drains a 2500mAh battery in less than an hour.
Any idea what I'm doing wrong? Especially as a comparable micropython implementation just doesn't get that hot and the same battery keeps for about 5 hrs...
Here's the code

#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"
#include <EEPROM.h>

// How many leds in your strip?
#define NUM_LEDS 60
#define DATA_PIN 13
#define CLOCK_PIN 14
#define COLOR_ORDER RGB
int starthue = 0;
int incrementer = 255/NUM_LEDS;
CRGB leds[NUM_LEDS*2];
int address = 0;
int max_modes = 4;
int colormode;

void setup() {
  Serial.begin(9600);
  // put your setup code here, to run once:
  FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS*2);
    EEPROM.begin(512);
  colormode = EEPROM.read(address);
  Serial.println(colormode);
  int new_mode = (colormode == max_modes) ? 1 : ++colormode;
  Serial.println(new_mode);
  new_mode = (colormode == 0) ? 1: new_mode;
  Serial.println(new_mode);
  EEPROM.write(address, new_mode);
  EEPROM.commit();
  EEPROM.end();
}

void rainbow_mid(int howfast) {
  while (true) {
    fill_rainbow(leds, NUM_LEDS, starthue, incrementer);
    for (int i =0; i< NUM_LEDS; i++) {
      leds[NUM_LEDS-i-1] = leds[i];
      leds[NUM_LEDS*2-i-1] = leds[i];
    }
    FastLED.show();
    delay(howfast);
    starthue++;
  }
}

void rainbow(int howfast) {
  while (true) {
    fill_rainbow(leds, NUM_LEDS, starthue, incrementer);
    //addGlitter(80);
    for (int i =0; i< NUM_LEDS; i++) {
      //leds[NUM_LEDS-i-1] = leds[i];
      leds[NUM_LEDS*2-i-1] = leds[i];
    }
    FastLED.show();
    delay(howfast);
    starthue++;
  }

}

void loop() {
  switch(colormode) {
    case 1: rainbow_mid(10); break;
    case 2: rainbow_mid(50); break;
    case 3: rainbow(10); break;
    case 4: rainbow(50); break;
  }

}

Same board, same connections in both cases?

The problem does not lie in your code, but in the connections. 60 RGB LEDs can draw about 20mA360 = 3.6A (all LEDs in full white). Showing a rainbow will draw less current, but as Tirdad wrote in his answer, that will still be too much for the onboard regulator. How have you connected everything? How have you connected the battery?

the heat is from the supply lines of board.
it's not the chip itself, as if it gets hot like that the chip should be destroyed.
it seems you have connected 60 LEDs strip to the board and you provide it's supply from the board's supply line. so the lines get hot, and the board gets hot too.
so the heat is not from the chip. its from power supply tracks on the PCB.
use another power source for the LED strip.


text:
Turn on LEDS one after another
I am trying to turn on LEDs one after the other so that I can start at one end and slowly turn the LEDs until it reaches the middle of the strip. The code works coming from the end of the LED strip, but not when coming from the start of the strip. From the start of the strip, it just turns on all the LEDs up until the midpoint.

int midpoint = 30;
int R = 255;
int G = 0;
int B = 0;
for(int j = 0; j<midpoint; j++){
     //starting from the end, filling towards the middle
        for(int k = NUM_LEDS-j; k < NUM_LEDS; k++){
           leds[k] = CRGB (R, G, B);
        }
//there's some other code here in the interim
FastLED.show();
delay(20);
     //starting from the beginning, filling towards the middle
     //this is the section of code that doesn't work correctly
        for(int l = j - 1; l < midpoint; l++){
           leds[l] = CRGB (R, G, B);
           }
//more interim code
FastLED.show();
delay(20);
}

which number does the for loop start with now? .... change it so that it coun ts in the opposite direction

Ooo I just thought about how l is increasing through the loop instead of decreasing. I solved it by changing it to for(int l = j; l < midpoint & l > -1; l--)

If you have solved it, you can post an answer to your own question. If you don't, the question will stay here, unanswered.

You should fix your indentation. It's very hard to tell what code is inside the outer j loop since some of that code isn't indented.

You need to add more explanation. What framework you're using, and how the leds array relates to your FastLED.show() function. Does it show the LEDs that are in your leds array? What turns the LEDs off again?

Okay so i figured it out. The problem is that the for loop is starting at 0 and counting all the way up to the midpoint. What I wanted is for it to light all the LEDs that are at j and below. So I changed it to iterate down instead of up. Here's the new loop:
for(int l = j; l < midpoint & l > -1; l--){
   leds[l] = CRGB (R, G, B);
}

The extra qualifier l > -1 is to make sure that it doesn't try to go below leds[0]

l >= 0 is more natural than l > -1, the compiler will probably optimise it to the same thing.

+1 for taking the time to post the solution to your problem. Most new members don't do that.


text:
How to add calibration to a humidity contoller using UNO and DHT22 sensor?
I am using a setup that helps controlling humidity in an enclosure used to store a humidity sensitive product.   My original posting is here.
I'm using a NANO and a DHT22 temperature/humidity sensor to acquire information on the actual condition in the enclosure; I am also using a 75% RH calibration kit to check the accuracy oh the humidity reading by the UNO and I found the value 9 percentage points higher than the kit's calibration value.   Right now, until I find a solution to calibrate the unit, I have set my setpoint 9 points higher to compensate for the error.
Any ideas on how to tackle this issue would be highly appreciated.
At the moment I can read the DHT sensor and show the humidity value on the LCD like this:
[...]
  int chk = DHT.read22(DHT22_PIN);
  lastcheck = millis();

  lcd.setCursor(0, 0);
  lcd.print("Humidity: ");
  lcd.setCursor(13, 0);
  lcd.print(DHT.humidity);
[...]

@Thomas_Weller,
I'm running tests with your calibration routine and other code changes; I'm using your arbitrary values for testing purposes only; the compensation algorithm works, as sampled below, however the LCD output is the actual DHT22 reading, not compensated.
I am testing with a different sensor, whose output is 9% below the actual RH value.
Here's a sample of the serial output:
DHT value: 58
Compensated to: 55
DHT value: 59
Compensated to: 56
DHT value: 60
Compensated to: 57
DHT value: 61
Compensated to: 58
DHT value: 62
Compensated to: 59
DHT value: 63
Compensated to: 60
DHT value: 64
Compensated to: 60

setpoint = 72
DHT read = 66.80%
displ + backlights off
humidifier ON, fan OFF
setpoint = 72
displ + backlights off
humidifier ON, fan OFF
setpoint = 72
displ + backlights off
humidifier ON, fan OFF
setpoint = 72
DHT read = 66.80%
displ + backlights off
humidifier ON, fan OFF
setpoint = 72
displ + backlights off
humidifier ON, fan OFF
setpoint = 72
displ + backlights off
humidifier ON, fan OFF

You need more data points for an effective calibration. You currently have no idea if the error is linear, absolute or something else.

@StarCat, thanks, I am aware of that and I'm working on it.

To get better calibration, you need more calibration points. In the example below, I use 8 measurement points.
Given 8 humidity calibration bags for 20, 30, 40, 50, 60, 70, 75 and 80%.
int calvalues[] = {20, 30, 40, 50, 60, 70, 75, 80};

You would take several samples with the DHT sensor and build a table using the averages:
int dhtvalues[] = {15, 28, 39, 51, 63, 75, 84, 89};

As you can see, the DHT is below the real values in the lower range and above the real values in the upper range. But it could also be the opposite way.
You can then write this function:
#define COMPENSATION_POINTS 8

int compensate(int sensor_value)
{
  for(int index=1; index<COMPENSATION_POINTS; index++)
  {
    if (dhtvalues[index]>sensor_value)
    {
      int dhtLow = dhtvalues[index-1];
      int dhtHigh = dhtvalues[index];
      int calLow = calvalues[index-1];
      int calHigh = calvalues[index];

      return map(sensor_value, dhtLow, dhtHigh, calLow, calHigh);
    }
  }
}

which does linear interpolation for all the values that fall somewhere in between.
Here's some test code, which goes through the values in the expected range.
void setup() {
  Serial.begin(9600);
  for(int hum=15; hum<=89; hum++)
  {
    Serial.print("DHT value: ");
    Serial.println(hum);
    Serial.print("Compensated to: ");
    Serial.println(compensate(hum));
  }
}

void loop() {
  delay(1000);
}

Output:
DHT value: 15
Compensated to: 20
DHT value: 16
Compensated to: 20
DHT value: 17
Compensated to: 21
DHT value: 18
Compensated to: 22
...
DHT value: 87
Compensated to: 78
DHT value: 88
Compensated to: 79
DHT value: 89
Compensated to: 79

Applied to your case:
[...]
  int chk = DHT.read22(DHT22_PIN);
  lastcheck = millis();

  lcd.setCursor(0, 0);
  lcd.print("Humidity: ");
  lcd.setCursor(13, 0);
  int compensated = compensate(DHT.humidity);   // <- new line
  lcd.print(compensated);                       // <- changed line
[...]

Good answer (voted). How did you measure the sensor's response at 20, 30, 40, 50, 60, 70, 75, 80 RH? Do you have a setup with water containing various salts to create those humidity levels? And shouldn't you also measure the response at a range of different temps, since the error probably varies with temperature?

@DuncanC: you're probably right. That should be a 2D table.

@Thomas_Weller, I ran tests and my original question was edited with what I found; please comment, thanks.


text:
Best way to send I2C commands between Arduino and ESP32
I made a board with an Arduino nano and a ESP32 Dev kit. I connected them via I2C with voltage adaptation. I'm using arduino IDE and the related library Wire.h.
I send messages as ascii chars or native bytes from the ESP32 (master) to the Arduino (slave) and all work fine.
I have to take a decision now. I have to implement a simple protocol to send command to the Arduino, in order to ask it do some tasks or in order to ask it to send some data to the esp32 (e.g. the speed of a motor or the state of some sensors and so on).
What I would ask is your suggestion if the simple protocol has to be managed as native bytes (the natural way I2C work) or as string (managed by mean of an array).
I try to explain.
In case of bytes I could send for example FF 0E14 01 to ask arduino to start the motor=FF at the speed=0E14 and direction=01. So the specific command is coded in the first byte.
What I miss is the need or not for a delimiter like "<" and ">" as used in case of string. In case of exchange of native bytes the value of "<" is "busy" in an integer and couldn't be distinguish by the parser. So what delimiter could I use?
On the other hand in case of strings I don't like the necessity to convert number "213" or "1529" in the relative integer. In case of the previous command I could send the string
""
having in mind the first char as command and for this specific command "S" ("S" for example) parsing the following chars until the "," and convert it in a integer and last char as direction (as byte or as char the test is the same).
I don't know... what way do you suggest and in case of native bytes what delimiters?
Thanks.

That‘s quite opinion based. To me it seems like you‘ve already figured out the pros and cons of i2c. I personally don’t recommend using a string-like protocol on i2c and stick with the common i2c protocol. You don‘t need start/stop bytes in this case

First, using a byte-value based protocol is the standard with I2C. There is no real reason to go to ASCII encoded data (The reason for doing this with Serial (UART) is normally, that the message is human readable at the PC. This is normally not the case with I2C, since only computers like the Raspberry Pi even have I2C interfaces).
About delimiters: They are only really needed for asynchronous data transfers (as UART)(to frame a full packet/message) or maybe, if you have an unknown transmission size. Both is not the case for I2C (it is a synchronous interface, that already implements transmission packages/message). You can look at the datasheet of any I2C sensor. The standard communication protocol is a command send by the master, then sending/receiving a specific number of bytes with a specific protocol, that defines, which bytes contains which information. Here you don't need a delimiter, because you already know, in what format the data will be send.

Let's take an example from your question: You want the Arduino to report the speed of your motor to the ESP. You implement the first byte of every master write transmission as a command, for example the decimal value 10 as command to report the motor speed. Then you terminate the master write transmission and request 1 byte from the Arduino (since you already know, that the motor speed has 1 byte). The Arduino knows through the command, that it should send the motor speed byte, and the ESP knows, that the byte received will be the 1 byte motor speed.
Now we define the command 11 to report the motor speed and the 3 bytes sensor value. The ESP sends 11 and then requests 4 bytes, as it knows, that the message will be 4 bytes long. The Arduino sends the data and the ESP knows, that the first byte will be the motor speed and the following 3 bytes the sensor value. No delimiter is needed, since the structure of your data is already defined through the implementation of your protocol. Start or end markers for a message are not needed, since I2C already works with distinct message/packets of data (a transmission is started with a START condition on the bus and ended with a STOP condition).

This solution is used for most I2C devices, since it is easier to implement at a low level. At the first glance for us humans it seems easier to use ASCII encoded and thus human readable data. But as you already mentioned, this makes it more complex for microcontrollers (writing parsers for ASCII data is more complex than using binary data on a fixed protocol). Keep in mind, that I2C means "Inter Integrated Circuit", so communication between integrated circuits, not communication between an integrated circuit and a human.
But in the end it is up to you to decide, which protocol you want to use.

As you might not know the concept yet: A Finite State Machine (FSM) is a good way to implement such a communication protocol on both sides. You define a state variable and based on this variable only the corresponding code is executed. You can change the state by changing the state variable.
For example on the Arduino (receiver side): First state could be the command state, where the Arduino waits for an I2C transmission. If a transmission was received, it will read it's first byte. Depending on this byte it will go into a different state, for example into the "Send motor speed" state. There it will prepare everything to send the motor speed to the master, should the master request data from the Arduino.
How to implement a FSM in detail is covered in many tutorials on the web and also in many questions on this side. You can see my answer to this question, where I explained this in more detail.

I appreciate all the details chrisl. I can't vote your answer as I am with low reputations yet. I will proceed as you suggested.

The only concern is about the position of the parser or finite state machine. Since the function "void receiveEvent(int howMany)" is called as an ISR routine following an interrupt, it should be as small as possible. So I shouldn't write the parser inside it. How to deal with this problem? Another question is: could I use the howMany number of byte to understand the correct length of the incoming current packet of byte? Thanks.

If the processing of the message would be too long for an ISR, the normal way is to buffer the message in an extra buffer and set a flag inside the ISR. This flag get's polled inside loop() and the processing is done there, when the flag is set.

Yes, the parameter howMany is the number of data bytes from the transmission, e.g. the number of bytes being received.

You can accept my answer, if you think it is correct. You don't need reputation for that. And you are the only one, that can accept an answer, since you asked this question.

Before giving pointers to your question; First I will start to recommend to avoid using i2C for these kind of things and recommend UART (Serial) which is much better for communication between multiple mcu's.
The UART) Serial Gives you a stack (memory of received data) meaning that you receive data when processing other functions and act on them in arduinos' own time. UART is more then fast enough for things like this and enables longer distances then few cm, its more resilient to interference
UART (Serial) uses fewer ports and most ports can be converted into Software Serial
You will find many libraries which deal with communication even encryption over Serial If you use write() rather then print you don't have to convert the data.if you use correct input on your arduino, you can even read the data as it comes from your PC and much more
Anyway, to your question Most of the data communications tend to have a starting byte and the ending byte to package the pocket among common ones is 00-Start and 0xFF as end.Now assuming that we only have one slave and single priority level etc we don't need to be too much of smartasess for package header... next I would define Process as it will let you chose the function that then can receive then next details as variables.
This option means that you will have to number the operations from 1 not 0Major benefit is that as different function may take different number of variables (for example one only states on off, while other states vector distance) you will not have to decide on a packet length, but simply deal with any number of variables (within reason)

As you can‘t use all numbers between 0-255 on uart (at least you need a stop byte) you‘ll always have to convert data to a char array representation. Also asynchronous is not always an advantage as it makes a parser necessary

I don't get many of your points against I2C. The I2C libraries have a "stack" (which is actually a FIFO buffer, not a stack) just like the Serial library. I2C uses 2 pins just like UART. Libaries for encryption normally handle the data itself; over which interface the data is send is irrelevant for them. write() sends binary data for both interfaces; no difference here. I don't see, why you would need start and end bytes for an I2C transmission (as it already has a START and an END condition; it is already send in a packet). Serial is good for comm between 2 MCU's. More is rather difficult

Also I don't understand everything after "Now assuming that". I just don't get the point, what you want to say there. Can you please explain, what the core point there is?


text:
Is it possible to add an additional board on Arduino Web Editor (create.arduino.cc)?
I'm using a board that can be programmed via Arduino IDE (a NodeMCU with ESP8266) and I've configured the Windows client successfully. I've added an additional board through "Preferences" menu by specifying its configuration url, following manufacturer's directions.
Now, I'm quite happy with the web editor, the one at create.arduino.cc, and I'd like to use it with this board too. Is there any way to configure additional boards?

No, there isn't.
The web editor is completely closed. It's a service run by Arduino, and as such it will only support Arduino's own boards.
Two reasons:

Why should they spend the time, effort and money adding support for other people's products?
It adds value to their products to encourage you to use real Ardiuno hardware.

Business is business, after all.

Got it, makes sense. The border is a bit blurred to me, sorry: seeing that feature on the client IDE made me wonder if the same was available on the web counterpart.

Here's a statement from an Arduino employee to the contrary: http://forum.arduino.cc/index.php?topic=361376.msg2741262#msg2741262 "we will support 3rd party HW in the future". On the other hand that statement was made over 1.5 years ago. I think there are security challenges to this since they will need to allow 3rd party applications to run on their server. I also wouldn't say "completely closed" since there are open source components but certainly a lot of it is closed. Interestingly there is another comment in that thread indicating there was a consideration of making it open.


text:
Outputs/inputs to Multiple Arduinos in Arduino IDE at once
I apologize if this information could be easily accessed, but I'm new to Arduino and did multiple searches.  I'm currently able to write to one Arduino Trinket in Arduino IDE using digitalWrite. However, I'll have to be reading from two different Arduino Trinkets with analogRead.  An important part of this is that I must be able to access both devices at the same time.  I saw during research that other people were able to use two different Arduino IDE instances, but I don't think this will work for me.  I'll more than likely soon be purchasing 2 Arduino ItsyBitsy's or nano's for the serial USB communication.  Let me know if this would make the issue easier.  I appreciate any help!

Thanks for the response, Juraj!  I have a better idea of the theory and terminology now, but I'm still not sure how to go about doing the operations I mentioned in Arduino IDE or any other IDE.  Would PlatformIO work better?

To collect data from multiple Arduinos at the same time you will likely have to use the Arduino IDE only for writing and uploading code one at a time, but something else for collecting data from both at once.  If you need to graph it you might look into Processing or Numpy or Matlab or whatever strikes your fancy.

Also asked at: http://forum.arduino.cc/index.php?topic=530546 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.

I'm currently attempting to do what I described in platformio with 2 Uno Arduinos following this https://xcorr.net/2016/12/13/multi-arduino-projects-with-platformio/ vaguely.

Arduino IDE is editor and builder. Your sketch runs on microcontroller and the microcotroller doesn't need the IDE to run it. The Serial prints from microcontroller go to com port from which any Terminal app can show them, not only the Serial Monitor build-in in IDE.
Connect both arduinos of same type to computer. They will have different ports. Upload your sketch to the first one, then change the port setting in IDE and upload to second arduino.
Serial Monitor can show you the output of arduino connected to the selected port. Switch port in Tools menu and reopen Serial Monitor to see the output of the second arduino.
To display booth at once, there are some options with different difficulty level:

use two instances of a terminal program like PuTTY Terminal Emulator to show the output
connect the TX pins of arduinos together
send data from one arduino to the second and let the second process them

Once again thanks for the response.  Following this there's still an issue of having to change the port in the IDE.  I should've been clearer about this in my questionm but I need to be comparing the voltages from the arduinos at the same time as they are read in.

and why two arduinos for that? one arduino can read two voltages

Thanks for the quick response.  I'm doing a project that involves pressure sensors on the soles of a user's feet.  It seems that the first option would be most appropriate in this case right?

it depends on the setup of the hardware. how long can be the cable between sensor and arduino? what is the end setup? only to show the values on a computer?

For now, the cable length doesn't matter.  No, there will be some comparisons and math operations to analyze posture

I would recommend to use only one arduino on a belt


text:
Arduino ISP external power
I want to program an atmega328p-pu via my arduino uno as ISP in a circuit.
I omitted my connected sensors, LCD, etc in the schematic to keep it simple.

When I power the circuit via a 5V power supply (left) I get
avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x000000 (retrying)

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

avrdude: Device signature = 0x000000 (retrying)

An error occurred while uploading the sketch
Reading | ################################################## | 100% 0.02s

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

avrdude done.  Thank you.

When powering off the circuit and connecting 5V and GND from the arduino to the power and gnd lines in my circuit everything works fine.
I connect 5V and GND from the arduino via pin headers I added to the 5V and GND rails in my circuit to power external sensors etc.
Is there a reason I apparently have to use power from the arduino?

Even with an external supply, you must connect the ground.  If it still doesn't work, perhaps your external supply is not 5 volts DC, or is noisy.  Also keep in mind that the specifications prohibit applying signal voltages to unpowered ICs - so it's going to be a little tricky to startup an external supply at the same time as the internal one without violating that.  If you have to start the external supply first since most signals are outputs from the programmer, and the 10K reset resistor is large enough not to challenge the programmer ATmega's protection diodes.

https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/

@ChrisStratton The external supply was powered first. But both you and majenko correctly pointed out, that my mistake was not sharing grounds. Does anyone want to make an answer out of that? Otherwise I'll answer myself to not leave the question open although the issue is solved.

Even with an external supply, you must still have a common ground reference between the ATmega being programmed, and the Arduino/ATmega doing the programming.  According to your comment this was the critical issue.
Also keep in mind that the specifications of most ICs including the ATmega prohibit applying signal voltages when the chip itself is unpowered.  To stay within that specification, you would need to turn on the external supply first, and insure that all of the pins were in their high impedance state and not driving the programmer's ATmega when it is unpowered.
Your pullup resistor on the target's reset would weakly drive pin 10 on the programmer, but a 10K resistor should limit the current to within what the protection diode on the corresponding ATmega pin can tolerate (even such a weak current can however cause problems with clean startup, though the ATmega is less sensitive than some other devices).
If you can't be sure power is going to be applied correctly, putting 1K (maybe even 2.2K) series resistors between the two chips can help a little, but there's a balance between keeping the signals strong enough to work well, and keeping illicit currents weak enough to avoid stress.


text:
Can't re-write Arduino Pro Mini
I am just getting started with arduino, but I am having an issue with some 3.3V, 8Mhz Arduino Pro Minis. I am using a SparkFun FT232RL USB to Serial breakout (https://www.sparkfun.com/products/12731) to communicate with the board, using Windows 7 and the Arduino IDE.
The Pro Minis were blank when I got them, I am able to upload a single program (Blink), which runs successfully, but I am unable to upload subsequent programs. I get the error:
avrdude: stk500_recv(): programmer is not responding

Any idea what might be going on?

How is the breakout connected to the Pro Mini?

Do you have auto reset hooked up?   If not and you are manually resetting, I found that activating verbose mode in the IDE makes the timing of pushing reset and hitting upload more forgiving.  Also make sure you have the correct baud rate for the upload, which might be different than for a 5v 16 MHz board.

The breakout is connected via Tx/Rx, GND, and VCC pins in the programming area at the edge of the pro mini. I have set the board to 3.3 8Mhz in the arduino IDE, i'll try hitting the manual reset again

Connect the DTR pin from the FT232 to the Promini as well, that will allow the software autoreset to work. Promini has a 0.1uF cap between the DTR pin and Reset already.