text:
Unexplainable int behavior in encoder/LED project
I am trying to use a rotary encoder to cycle through the brightest versions of R, G & B. And it works! Red goes to blue just fine. Then G happens. For some reason, the int for green goes completely haywire. And it does this the same way on two Arduinos.
So my question is this: why would two, identically assigned variables treat ++ completely differently? After hours (and hours and hours) of looking, I'm completely out of possible answers.
#include <Encoder.h>
#include <FastLED.h>

/* Encoder */
Encoder myEnc(2, 3);
const int swPin = 4 ;
long oldPosition  = -999;

/* LEDs */
#define LED_PIN     7
#define NUM_LEDS    150
CRGB leds[NUM_LEDS];

/* RGB Loop */
volatile int cycle = 1;
volatile int brightness = 0;
volatile int r = 127;
volatile int g = 0;
volatile int b = 0;

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

void loop() {
  // Read from rotary encoder.
  long newPosition = myEnc.read();

  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition); /* Sends elsewhere */
  }

  /* Will eventually move this inside the above if
   * statement so the color shift is controlled by
   * a rotary encoder.  Down here for debugging.
   */
  delay(50);
  updateColor( );
}

void updateColor(  ) {

  Serial.println(" "); // For readability.

  if ( brightness >= 127 ) {
    brightness = 1;
    if ( cycle > 6 ) {
      cycle = 1;
    } else {
      cycle++;
    }
  } else {
    brightness++;
  }

  if ( cycle == 1) {
    b++;
  }
  else if ( cycle == 2) { /* rb --> b */
    r--;
  }
  else if ( cycle == 3) { /* b --> bg */
    g++;
  }
  else if ( cycle == 4) { /* bg --> g */
    b--;
  }
  else if ( cycle == 5) { /* g --> rg */
    r++;
  }
  else if ( cycle == 6) { /* g --> rg */
    g--;
  }
  else {
    Serial.print("==================== ");
  }

  /* Debugging */
  Serial.print("brightness:");
  Serial.print(brightness);
  Serial.print("   cycle:");
  Serial.print(cycle);
  Serial.print("   r:");
  Serial.print(r);
  Serial.print(" g:");
  Serial.print(g); // goes completely bonkers
  Serial.print(" b:");
  Serial.print(b);
  Serial.println(" ");

  for (int i = 0; i <= NUM_LEDS; i++) {
    leds[i].setRGB( r, g, b );
  }

  FastLED.show();

}

spits out the following in the serial monitor :
brightness:1   cycle:1   r:127 g:0 b:1

brightness:2   cycle:1   r:127 g:127 b:2

brightness:3   cycle:1   r:127 g:32639 b:3

brightness:4   cycle:1   r:127 g:32639 b:4

brightness:5   cycle:1   r:127 g:32639 b:5

brightness:6   cycle:1   r:127 g:32639 b:6

Red and blue are doing exactly what I want. Green is off on Mars.
Any/all help would be enormously appreciated.  Thanks in advance.

127 = 0x7F, 32639 = 0x7F7F.

I can't yet comment so therefore here.
Could you try casting the rgb printouts to uint8_t? It could be that it goes out of bounds or something? I don't see anything wrong with the code so maybe it could be that some pointer is changing the value of g?

I do not see a relation between the encoder and the r,g,b values. Or between the encoder and your rgb problem. BTW: rgb values are byte, not int

laffan, we don't see the problem. It could be a compiler or optimization bug (not likely, but it is possible) or a bug in a library that overwrites memory. You have to try a number of things. Start with an example, and slowly change that in the direction of your sketch. The setRGB is a inline function that has uint8_t as parameters. I think there is no need to make the variables volatile.

Thank you all!
@Jot I think you're on to something. I'm not sure what you're on to, but that at least explains the number. Looks like I need to learn some more about hexidecimals.  And good to know re: that variable volatility (I was grasping at straws.)
Tarik Welling - I'm afraid this hobbiest hasn't gotten to pointers yet, but I'll take a look.
DataFiddler - The new/old position thing is the rotary encoder part (see comments) which works, incredibly. Thanks for the byte tip.

couple of things to try ..... comment out the FastLed code ..... exchange the b++ and the g--  in the if blocks

Here:
CRGB leds[NUM_LEDS];

you are defining an array of NUM_LEDS objects of the CRGB type.
Valid indices for this array range from 0 to NUM_LEDS-1.
Here:
for (int i = 0; i <= NUM_LEDS; i++) {
  leds[i].setRGB( r, g, b );
}

you are accessing the array elements at indices 0 to NUM_LEDS. The
last iteration is an out-of-bounds access, which is causing memory
corruption. You should instead write
for (int i = 0; i < NUM_LEDS; i++) ...

Thank you so much @edgar-bonet - I don't think I ever would have figured that out.


text:
Setup Firmata for PC-less usage
I want to use an Arduino Uno with Firmata as a standalone datalogger for recording analog signals. I will use power banks to power the Arduino. How is it possible to setup Firmata pins once with PC and use that battery powered in PC-less situation?

how do you want to use Firmata without computer? Arduino with Firmata is a slave that can do nothing without commands from master

source: Stack Exchange

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

sort: votes


text:
Exception Handling with the Arduino IDE
I'm using a port of the STL found here and trying to debug with a simple try{...}catch{...} loop. When compiling with the Arduino IDE, I get the error message

exception handling disabled, use -fexceptions to enable.

I'm not quite sure what this means. Can the Arduino simply not support exceptions? Or is -fexceptions a compiler flag I can enable?

It's just disabled and if you want to use it, you have to provide -fexceptions flag to the compiler.

Great, thanks for the help!

As you have already found out, add -fexceptions to the compiler flags. This can be done by modifying the platform.txt of your Arduino IDE installation.
See https://github.com/arduino/ArduinoCore-avr/blob/master/platform.txt#L28. There is -fno-exceptions defined, so you have to remove that, too.

Perfect, this is the (complete) answer I was looking for.

Arduino is a very limited platform, and handling exceptions requires quite a bit of hidden code to properly unwind the stack wherever the exception occurs.
So the default is to turn it off and teach users to not use exceptions in arduino and instead other type of error handling.

The default is not to use STL neither.

It's not just the default; Arduino has no built-in support for the STL.

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


text:
Code compilation errors for 101 - no errors with Uno
I asked this question before a few days ago about undefined references errors to custom library functions. By accident I found that the code compiled fine when the board target was set to an Uno, not the Intel Curie 101 that I was indending to use (and what is was set to when the errors appear) Can anyone explain why you would get undefined reference errors that are board specific?
Disclaimer - I haven't got access to the hardware I need to test at the moment so I don't know for certain that the code works on an Uno.
Edit:
I have tested the compilation for a few board targets as below

Uno - no errors
Mega / Mega 2560 - no errors
Leonardo - no errors
Due - no errors
101 - undefined reference as detailed in linked question

Additionally, moving the libaries into the sketch folder rather then having them in the Arduino libaries folder stops compilation errors. Is there a difference in how the 101 links to included files?

why did you create a new question instead of updating the original question with this new information?

I made a new question as in my mind this is a different issue to the previous question. The original post was more asking for code advice as that's what I believed the issue was - where as this is now more about the behaviour of Arduino in general. For someone who has the same problems that I have encountered about baord specific compilation errors then this would be a more helpful question would it not?

if the other question gets deleted, then this one becomes broken .... your question should stand on its own

it is unclear what your question actually is .... the Uno and the Curie use different microcontrollers, therefore the libraries are different

@jsotola: The OP's question is about their own library.

error.h is not a good name for a library. Some cores or compilers (the Curie one included) have an "error.h" file within them.


text:
Serial monitor shows repeated CIPSEND and CIPCLOSE
I'm trying to build a heart rate monitor using ESP-01. The code compiles and uploads well but once uploaded, in the serial monitor it shows the following. It keeps repeat CIPSEND and CIPCLOSE over and over.
What could cause this?
Could it be faulty hardware or is it a problem with the code?
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80

A problem with the code.

The code is at the end of the webpage. I dont know if theres anything wrong with the code. Could it be faulty hardware?    https://www.how2electronics.com/pulse-rate-monitoring-over-internet-using-thingspeak/

the code on that web page is improperly formatted ... it is a really bad example to beginner programmers ..... i would not be surprised if it contains bugs

The reason that you are seeing those messages on the serial monitor is because the code is telling it to print those messages on the serial monitor.
Every time a message is sent to the ESP8266 it is also sent (for debugging purposes) to the Serial.


text:
Arduino UNO R3 clone acting as Arduino Nano
I just got a bunch of Arduino Uno R3 (ATmega328P + CH340).In arduino IDE when i'm selecting board as Arduino UNO then i'am getting this error
avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM7
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xaf
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xaf

But, When i'm selecting Arduino Nano it's working fine. How to fix it?

why do you feel that something needs to be fixed? .... are you having problems compiling sketches? .... upvote for investigating and finding a workaround

burn the Uno bootloader

@jsotola https://arduino.stackexchange.com/questions/65321/usbasp-arduino-uno-bootloader-flash-error-win-10

@Juraj  https://arduino.stackexchange.com/questions/65321/usbasp-arduino-uno-bootloader-flash-error-win-10

@Juraj i have selected  target board type in Tools menu, on linux arvdude cli i'am getting same error

@Juraj I received the UNO with Nano Bootloader so i am trying to flashing it


text:
SG90 servo motor not working
I tried to test a servo motor for a project using this simple circuit but the motor won't move. I've used this before with the same setup and code and it worked, but now suddenly nothing works, even tried a different servo motor.
I have tried changing arduinos, changing signal pins , changing servos but nothing works. I had got them to work only a few days back but now suddenly i cant and i dont know where im going wrong.
here is my circuit :- image of circuit
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(9);
}
void loop()
{
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
 delay(15);
}
for (pos = 180; pos >= 0; pos -= 1)
{
 myservo.write(pos);
delay(15);
}
}

you are like the guy that thinks of replacing an engine in an automobile before he thinks to check if there is any gas in the tank ...... have you checked the voltages on the power supply?

There's nothing wrong with your code. Check your wiring:

Servo brown  -> Gnd
Servo red    -> +5v (not +3v)
Servo Orange -> pin 9
Connections at the servo-connector and at the Arduino are electrically sound
Try swapping the 3 jumper wires (the only parts you didn't say you'd swapped)


text:
Schematic with Atmega32U4 and WS2812 Led (Smiley Shape). Does it work?
I'm new here and I'm a newbie in electronics. Since 1 year I'm playing around with Arduino (different types) and now I want to build my own thing: a smiley with WS2812D-F5 RGB leds. But I'm not sure if I did any misstakes. Is it possible that an expert in electronics can check my schematic? That would be very kind, nice and cool :)
Functions: The switch SW1 is connected on D8 (PB4) and if pushed the smiley changes from sad to happy. pushed again it changes again and so on.
Because the WS2812 leds needs a lot of current, I have added some different possibilities to power the whole thing: 1x DC jack connected on a voltage regulator that output 5V fixed and two pins for a LiPo 3.7V that ist connected too on the voltage regulator. I dont know if it works if the LiPo has only 3.7V.
Well.. then I added a power switch, micro usb, FTDI and SPI connection. If one fails to burn the bootloader or to upload a sketch, I have more possibilities to do that ;)
Yeah I think thats it. If I forgot something, just ask me. Thanks a lot!
Kind regards.
Greetings from Switzerland
delf

Edit 15.5.19 18:00
Ok, I just changed the schematic based upon your great advices :) Thanks a lot to everyone. I changed/added the regulator. Current output=3A (each one). Should  be enough. But I'm not sure if I can divide the current in that way.
What do you think? :)
Greetings to everyone :)

Be sure that every component, that lies between the power supply and the LEDs, is capable of giving the needed current. Also the supply has to provide enough current

A 7805 as a regulator on a circuit that needs about 4A...?!  OUCH. I think not.

Majenko already replied to the most important part (the power management); I'd like to just give a few advice. The LiPo battery connector cannot work that way, since the 7805 needs at least 6-6.5V to work. Moreover you shouldn't connect it in parallel to a 12V supply. The very first time you forget it connected and you also connect the 12V... well, there are a lot of videos of batteries exploding... Finally try to be "cleaner" when drawing the circuit; avoid too many intersecting lines since they are confusing (for instance look at the reset line). Finally SW1 is useless (you cannot control it

Which method and/or programmer are you using to burn the bootloader?

@frarugi87
SW1 has only the function to check if the signal is high to change the shape of the smiley. That should work or did I forgot something? Finally I forgot something important: the max amount of running LED's = ~50. I just add a newer version in a few minutes with the layout of the pcb

@Gerben
I dont know. At the moment I'm in the planing stage. The bootloader task comes later ;)

@swimhive yes, but when SW1 is not pressed it should go to a known state. usually you connect a resistor to either VCC or GND, and the switch to the other, so the node can "go" to the other state when the button is not pressed. These are called respectively pull-up resistors or pull-down. The micro you are using has integrated pull-up resistors, so you can either 1) connect the SW1 to ground, enable the internal pull-up and search for a LOW state or 2) leave the SW1 connected this way, and add a pull-down resistor. Usually people tend to use solution 1 (less components)

On the FTDI header you need to swap the TX and RX pins. The TX of the FTDI should connect the the RX of the Arduino, and vice-versa.
Also, on the FTDI header, the USBVCC pin is connected directly to the 5V pin. I would want to connect my PC to that header if external power is applied to your board. If you're never going to use that pin to power the board, you could leave it disconnected. The same applies to the USB port.
I'd have the LiPo connector bypass the regulator, as all it does is drop the voltage even lower. A LiPo is around 4.2V when full. The 3.7V is only it's nominal voltage.
D1 is in a weird location. If you want to use it to prevent reverse polarity, move it between the jack, and the input of the voltage regulator.

Thanks a lot for your advice :) I just did a few changes. But I'm not sure if I can split the current in that way and how to power the VBus. Is it possible to connect the VBus pin with the output pin from the "regulator2"?
Kind regards

It seems the VBUS pin is an input pin, used to detect if USB is plugged in. So you could wire the 5V from the USB port directly to the VBUS pin. And no connect it to the 5V from the regulator. Leave the Vcc from the FTDI header disconnected.

No. That circuit will not work.
The moment you turn on more than a few of the LEDs the regulator will go into meltdown. No matter how powerful your power supply is, that regulator is the bottleneck and will overheat the moment you try and light your smiley face.
The regulator (a venerable 7805 - I mean, come on, that's from the ark. There's far better modern regulators now...) is rated for a maximum of 1A. That is with very good heatsinking and thermal management, and an input voltage only slightly above 5V + the dropout voltage.  Your circuit can draw up to about 4A. That's 4x what the regulator is rated for when it's at its most optimim - probably 6x to 8x what your arrangement would be able to provide.
For this kind of circuit you need a switching regulator. One that can provide many many times the current of a linear regulator like the 7805 (or the more modern LM1117-5.0).  You need one that will provide at least 4A, and ideally a little more for some extra headroom. So you're looking at 5A.
With a decent efficiency you could then run the whole thing from a 12V input with 2.5A minimum current. Assuming 85% efficiency:

12V @ 2.5A = 30W
85% of 30W = 25.5W
25.5W @ 5V = 5.1A

So a 12V, 2.5A supply being fed into a 5V, 5A switching regulator with at least 85% efficiency will allow your circuit to operate more reliably.
You also need to take care with your PCB layout (assuming you are designing this for building on a PCB). Switching regulators take a certain amount of care when laying them out. You should refer to the recommended PCB layout in the datasheet for your chosen regulator and stick as closely to that as you can.
Also handling larger currents requires more thought put into your traces.  This site has a handy trace width calculator.
As an example: for a 5A trace over a distance of 5cm with (standard) 1oz copper your trace should be at least 2.77mm wide. That will give a 10C temperature rise in the trace at room temperaure (25C to 35C).

Hi :)
Thanks a lot for your help! like I said: I'm a newbie :) can you recommend a voltage regulator? I only find linear voltage regulators that provide 3.3V and 5A. But I need 5V :-/
Thanks a lot for the usefull informations. But.. the rest of the circuit works?
About the traces on the pcb: only the VCC and the GND trace should be ~3mm wide or am I wrong?
Thanks a lot for your kind help :)
Greetings and keep smiling ;)

@swimhive personally I'd go with larger traces, or even planes. I suggest you to try to minimize the amount of current in a single point (for instance use a sort of "tree" connection rather than a sequential one).

Certainly for the ground you want a solid pour rather than traces. Then route the power traces first, and only afterwards worry about the signals.

@swimhive As a newbie I wouldn't suggest designing your own switching regulator circuit just yet. Take a look at external modules, such as UBEC modules for model aircraft etc.

@Majenko
Yes you are right. But I have to :( There is one thing that I dont understand. My Arduino Due can drive 50 pieces WS2812B leds. One single led uses max 60mA (20mA for each color). If every led is white it consumes 60mA each. Total=3000mA. The regulator on the DUE is a LM2734Y and has a max. current output 1A. But it works.. how?

You are probably over-stressing the regulator. How hot is it getting? Is the output voltage dropping?

@Majenko I'm not sure if the output voltage is dropping. It's a shield. I cant access the regulator while running the led, because he's covered.


text:
Help with Bluetooth shield
Hey guys I have this Bluetooth shield

Does anybody know how I can get it to connect to Arduino?
I can't find any guides on it.
I have this serial program that I want to use to turn on a led.
but I can't seem to enter AT mode, or get any indication that besides it connecting to my Mac it's receiving or transmitting any signals.
Anybody got any tips for tutorials/tips for tests for a MAC OSX user?
UPDATE: here is a better foto

I'm trying to run this Arduino code. that uses a 1 to turn a led on and a 0 to turn it off. I want to send these 1's and 0's through a Mac program called Bluterm. I connect it to the HC-05 BUT it doesn't send me anything back. (THE LED IS GREEN, IT'S CONNECTED ON MAC AND ON BLUTERM)
Here is my Arduino code:

int led = 13;
int value = 0;

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

}

void loop() {
  if (Serial.available() > 0) {
    value = Serial.read();
    delay(5);

    if (value == '1') {
      digitalWrite(led, HIGH);
      Serial.println("LED IS ON");

    }

    if (value == '0') {
      digitalWrite(led, LOW);
      Serial.println("LED IS OFF");

    }

  }
  }

UPDATE 2: Here is the code from the PDF that was shipped with my shield:

unsigned int timeout=0; unsigned char state=0;
ISR(TIMER2_OVF_vect) {
TCNT2 = 0; timeout++;
if (timeout>61) {
state=1;
timeout=0; }
}
void init_timer2(void) {
//Timer2 Service
TCCR2A |= (1 << WGM21) | (1 << WGM20);
TCCR2B |= 0x07; // by clk/1024
ASSR |= (0<<AS2); // Use internal clock - external clock not used in Arduino
TIMSK2 |= 0x01; TCNT2 = 0; sei();
}
void setup() {
//Timer2 Overflow Interrupt Enable
Serial.begin(9600);
pinMode(2,INPUT); pinMode(13,OUTPUT); attachInterrupt(0,cleantime,FALLING); init_timer2();
}
void loop() {
switch(state) {
case 0:
digitalWrite(13,LOW); break;

case 1: digitalWrite(13,HIGH); Serial.print("Hellow BT"); break;
} }
void cleantime() {
timeout=0;
state=0; }

Anybody can help me decipher this code? none of this looks familiar to me
thanks guys,
juriaan
UPDATE 3:

UPDATE 4

Comments are not for extended discussion; this conversation has been moved to chat.

Look, much as I think we would all like to help you, this isn't a forum, where you take post after post to troubleshoot. The intent of the site is to answer specific problems, in such a way that other people may benefit from the answer. If you want to interactively problem-solve the Arduino Forum may be a better fit for you. Just to help you out, someone on the Arduino Forum seems to be asking a similar question.

Perhaps you could chat with them and work together to find a solution?

You need to understand the basics before you try running code to "do things":

The shield can run in two modes: AT command mode, which is used to configure it, and Transparent UART mode, which is used to communicate.
Communication with the Arduino is done through UART serial, and the pins used for that communication are selected using the big bank of jumpers.
Nothing will happen until you have configured the shield using AT commands.

To progress you really need the manual for the shield. This should be available from wherever you purchased it.  That will detail:

What the positions of the jumpers mean
What the AT command set of the module is
What the baud rate is which you need to use to communicate

And if it's any good:

Example code

Once you have at least the first set of those bits of information you can write some software for the Arduino which will pass anything received on Serial through to the bluetooth shield, and anything received from the bluetooth shield back through to Serial.  You can then use the serial monitor in the IDE to interact with the shield and configure it in the way you need it.
Once you know how to configure it you can then write some better software for the Arduino that does any startup configuration you need and then operates on the data coming in through Transparent UART mode.

The only thing of information I have from them is: https://hackerstore.nl/PDFs/BTShield.pdf . It tels me about BAUD rate of 9600. But nothing on the usage of the pins, I have mailed the retailer for more information


text:
arduino yun sysupgrade 'platform_check_image' failed
https://www.arduino.cc/en/Tutorial/YunSysupgrade
when i run the following command. i get this error.
run-sysupgrade /mnt/sda1/openwrt-ar71xx-generic-yun-16M-squashfs-sysupgrade.bin
Image metadata not found
Invalid image type.
Image check 'platform_check_image' failed.

via webinterface its the same problem
i have a freshly unboxed arduino yun rev2
i really don't want to use the go updater since i still have 2 years of warranty.
https://www.arduino.cc/en/Guide/YunUpdater

Hint: The SD card should be inserted with Yun powered off, then once the card is in, power up the Yun.

@MikaelPatel didn't work. same problem.

Check that the SD is mounted ls /mnt/sda1/

@MikaelPatel it is. the bin shows up.

Check the size and contents of the file against the original. How did you download?


text:
ESP32 IR remote
my board is a firebeetle esp32 that I am using as an IR remote.
After using the Ken Shirrif IRremote library for about 6 months successfully, then the time came to change a few things on the web front end. This has been a disaster.
I tried to recompile my working code that the board is currently using and got errors everywhere I turned.
So i switched libraries to this one;
https://github.com/ExploreEmbedded/Arduino-IRremote
Now it does compile successfully, with the only change between the two libraries was to pull out the pin I defined for IR tx in the Ken Shirriff library. For example; previously my code looked like this to work with the old library.

IRsend irsend(33);

Now it looks like this;
IRsend irsend;

As stated, it does compile; only issue is that IR doesn't work. It says in the library that pin 5 is defined as the tx pin for the ESP32 in boarddefs. Snip from boarddefs where I believe pin 5 is defining IR tx.
// ESP32 has it own timer API and does not use these macros, but to avoid ifdef'ing
// them out in the common code, they are defined to no-op. This allows the code to compile
// (which it wouldn't otherwise) but irsend will not work until ESP32 specific code is written
// for that -- merlin
// As a warning, sending timing specific code from an ESP32 can be challenging if you need 100%
// reliability because the arduino code may be interrupted and cause your sent waveform to be the
// wrong length. This is specifically an issue for neopixels which require 800Khz resolution.
// IR may just work as is with the common code since it's lower frequency, but if not, the other
// way to do this on ESP32 is using the RMT built in driver like in this incomplete library below
// https://github.com/ExploreEmbedded/ESP32_RMT
#elif defined(IR_TIMER_USE_ESP32)
#define TIMER_CHANNEL       1
#define TIMER_LENGHT        8 //8-bit Timer
#define TIMER_PWM_PIN      5
#define TIMER_ENABLE_PWM    ledcAttachPin(TIMER_PWM_PIN, TIMER_CHANNEL);
#define TIMER_DISABLE_PWM   ledcDetachPin(TIMER_PWM_PIN);
#define TIMER_RESET
#define TIMER_ENABLE_INTR
#define TIMER_DISABLE_INTR
#define TIMER_INTR_NAME

//---------------------------------------------------------
// Unknown Timer
//
#else
#   error "Internal code configuration error, no known IR_USE_TIMER# defined\n"
#endif

#endif // ! boarddefs_h

I know it says that IR with the ESP32 will not work, but it said the same thing for several libraries that i've used that do work, most notably the one by Ken; which appears to have moved here.
https://github.com/z3t0/Arduino-IRremote
Quick example of my code;
#include "IRremote.h"
  IRsend irsend;
int khz = 38;
String input;
  String tv;
void changehdmi() {
if (Server.args() > 0 ) {
  for ( uint8_t i = 0; i < Server.args(); i++ ) {
    if (Server.argName(i) == "input") {
      input = String(Server.arg(i));
      Serial.println("input is " + input);
    }
    if (Server.argName(i) == "tv") {
      tv = String(Server.arg(i));
      Serial.println("tv is " + tv);
    }

  }
}
if (input == "1" && tv == "1") {
  unsigned int irSignal[] = {9000, 4450, 600, 550, 550, 550, 600, 550, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1650, 600, 1650, 550, 1700, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550}; // NEC FF906F
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}
else if (input == "2" && tv == "1") {
  unsigned int irSignal[] = {9000, 4500, 550, 550, 600, 550, 550, 550, 550, 600, 550, 550, 600, 550, 550, 550, 550, 550, 600, 1650, 600, 1700, 500, 1700, 600, 1700, 500, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 550, 550, 1700, 550, 1700, 550, 1700, 550, 550, 550, 550, 600, 550, 550, 550, 600, 1700, 500, 600, 550, 550, 600, 500, 600, 1650, 600, 1650, 600, 1650, 550}; // NEC FFB847
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}

Has anyone gotten this to work recently? The libraries that are available seem to have lost support for this functionality.

For the ESP32, you should really check out IRremoteESP8266, which also works on your board, and is frequently updated, very widely used, and lets you use any compatible GPIO pin easily.
Here's a sample of a simple IR send demo:
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define IR_PIN 4

IRsend irsend(IR_PIN);  // Set the GPIO to be used to sending the message.

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

void loop() {
  Serial.println("NEC");
  irsend.sendNEC(0x00FFE01FUL);
  delay(2000);
}

This example will send an NEC code very 2 seconds. The library also has extensive support for other formats, as well as raw.
If you want to be extra safe, the creator of the project menions here that GPIO 4 and 18 are safe, but I know for a fact that many other ESP32 pins are okay to use as well.


text:
LM393 Speed sensor - Counting pulses
I'm trying to calculate de rotation speed of a dc motor.
I'm using the sensor shown in the picture and a slotted disk attached to the motor. The results I was getting made no sense and after several tests I realised the following:
Most of the times I manually blocked or unblocked the sensor, two pulses were counted. That would mean that for each tooth of the slotted disk, up to four pulses were counted instead of one.
Bellow is a test code. I count pulses on the interrupt handler and reset the counter when calculating the motor speed.
Am I doing something wrong or is the sensor suffering from bouncing signals?
int encoderCounter = 0;
int encoderDiscSlots = 21;

int encoderPin = 19;

void encoderIncrementISR()
{
  encoderCounter++;
}

double calculateMotorSpeed(int interval)
{
  Serial.print("enc ");
  Serial.println(encoderCounter);
  double rpm = (encoderCounter*1.0/encoderDiscSlots)*60000/interval;

  encoderCounter = 0;
  return rpm;
}

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

  pinMode(encoderPin, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(encoderPin), encoderIncrementISR, RISING);
}

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

  delay(1000);
  double rpm = calculateMotorSpeed(1000);
  Serial.print("rpm ");
  Serial.println(rpm);
}

The sensor uses the LM393 IC from TI, a spec sheet can be found here

the picture does not tell us anything about the sensor, other than validating the type of the sensor .... please add a link to the datasheet in you question above

@jsotola added aditional sensor information to the question.

I've done some more search on the interwebs and found someone (in Spanish) describing the same problem. That person owns an oscilloscope and could confirm that there is some bouncing on the data signal both going up and down.
The hardware solution presented is to place a 100 nF capacitor between the signal pin and ground.
I've tried it and it works.


text:
Trouble running two NEMA 17's with a joystick
So I'm trying to make a motorized dobsonian telescope using two NEMA 17 motors with Easy Driver boards. I want to control the x and y axis with a joystick. I found a code that ran one with a joystick and I tried to modify it by copying the loop and adding the y-axis. Well only the X-axis moves and it only turns CCW.
Can someone run over this and see if they see the issue that I can't? Thank you
/*This program is designed to control two nema 17 boards with easy driver board with a joystick on a Nano.
My specific use is to control the X and Y axis of a homemade telescope

considered open source, feel free to do whatever with it.
*/

#define step_pinX 3                                                             // Pin 3 connected to Steps pin on EasyDriver       X-AXIS
#define dir_pinX 2                                                              // Pin 2 connected to Direction pin                 X-AXIS
#define MS1X 5                                                                  // Pin 5 connected to MS1 pin                       X-AXIS
#define MS2X 4                                                                  // Pin 4 connected to MS2 pin                       X-AXIS
#define SLEEPX 6                                                                // Pin 6 connected to SLEEP pin                     X-AXIS
#define step_pinY 7                                                             // Pin 7 connected to Steps pin on EasyDriver         Y-AXIS
#define dir_pinY 8                                                              // Pin 8 connected to Direction pin                   Y-AXIS
#define MS1Y 9                                                                  // Pin 9 connected to MS1 pin                         Y-AXIS
#define MS2Y 10                                                                 // Pin 10 connected to MS2 pin                        Y-AXIS
#define SLEEPY 11                                                               // Pin 11 connected to SLEEP pin                      Y-AXIS
#define XPin A0                                                                // Pin A0 connected to joystick x axis              x-AXIS
#define YPin A1                                                                // Pin A1 connected to joystick y axis                Y-AXIS
#define JoySwitch 12                                                            // Pin 12 connected to joystick button
#define Limit01 22                                                              // Pin 22 connected to limit switch
#define Limit02 23                                                              // Pin 23 connected to limit switch

int stepSpeed = 10;                                                            // speed of stepper motor

void setup() {
   pinMode(MS1X, OUTPUT);
   pinMode(MS2X, OUTPUT);
   pinMode(dir_pinX, OUTPUT);
   pinMode(step_pinX, OUTPUT);
   pinMode(SLEEPX, OUTPUT);
   pinMode(MS1Y, OUTPUT);
   pinMode(MS2Y, OUTPUT);
   pinMode(dir_pinY, OUTPUT);
   pinMode(step_pinY, OUTPUT);
   pinMode(SLEEPY, OUTPUT);

   pinMode(Limit01, INPUT);
   pinMode(Limit02, INPUT);

   pinMode(JoySwitch,INPUT_PULLUP);

   digitalWrite(SLEEPX, HIGH);                                                  // Wake up EasyDriver
   delay(5);                                                                    // Wait for EasyDriver wake up
   digitalWrite(SLEEPY, HIGH);                                                  // Wake up EasyDriver
   delay(5);                                                                    // Wait for EasyDriver wake up

/* Configure type of Steps on EasyDriver:
// MS1X MS2X MS1Y MS2Y
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/

   digitalWrite(MS1X, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS2X, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS1Y, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS2Y, LOW);                                                      // Configures to Full Steps

}

void loop() {
  if (!digitalRead(JoySwitch)) {                                                 // Check joystick switch position
  delay(500);                                                                    // delay for debouncing
  switch (stepSpeed) {                                                          // Check current value of step_speed and change it
    case 1:
    stepSpeed=10;                                                               // slow speed
    break;
    case 3:
    stepSpeed=1;                                                                // fast speed
    break;
    case 10:
    stepSpeed=3;                                                                // medium speed
    break;
  }
  }

  if (analogRead(XPin)> 712){                                                     //if joystick is moved left
    if (!digitalRead(Limit01))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinX, LOW);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinX, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinX, LOW);
      delay(stepSpeed);
    }
  }

if (analogRead(XPin) < 312){                                                     //if joystick is moved left
    if (!digitalRead(Limit02))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinX, HIGH);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinX, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinX, LOW);
      delay(stepSpeed);

    }
    }
    if (analogRead(YPin)> 712){                                                     //if joystick is moved left
    if (!digitalRead(Limit01))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinY, LOW);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinY, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinY, LOW);
      delay(stepSpeed);
    }
  }

if (analogRead(YPin) < 312){                                                     //if joystick is moved left
    if (!digitalRead(Limit02))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinY, HIGH);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinY, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinY, LOW);
      delay(stepSpeed);

    }
    }

}

how many limit switches do you have? ... you are reading the same switch with X and Y code

you code has unnecessary convolution .... if(!digitalRead(Limit02))  {}   else { .... } is same as if(digitalRead(Limit02))  { .... }


text:
High speed rotary encoder with Arduino MEGA
I'm trying to develop length measuring system and I'm using a industrial rotary encoder as the sensor.
A have decided to use an Arduino external interrupt for connect the encoder. But, Encoder will rotate very fast. I need to calculate PPR(Pulse per revolution) of the encoder according to maximum interrupt frequency of Arduino MEGA.
So, What is the maximum interrupt frequency of Arduino MEGA?

it depends on the program that you are running

Using the atmega's counter module might be the way to go


text:
ADS1115, ZMPT101b and Arduino Uno listing program for AC measurement
I got problem in my result where my ADC read cannot give the biggest and the lowest ADC Value if I am using ADS1115. meanwhile, when I am not using ADS1115 I can get the biggest and the lowest ADC Value using a listing program that I use before. Thank u, need for help.

]

why did you post pictures of the code? .... how do you expect anyone to run the program and test it?

what do you need help with? .... you did not ask any questions.

@jsotola no, i post the pictures of the code to ask if anything wrong in my code. my question is, why i cant get biggest and lowest value of my ADC if i using ADS1115? the value is just same the biggest and the lowest.

The practice on this SE is to post code as text (e.g. so that others may copy/paste and help you by providing correct code), not as images.

is the ADS1115 fast enough to measure AC? are you using some sort of RC filter and bridge?

The ZMPT101b is a transformer which converts voltage. You can read the output with analog pin.
The ADS1115 is an analog to digital converter. It reads the analog voltage the same way as the analog pin of your Arduino does. The result then can be read over I2C as a register value. You can't read it with analogRead.
So you can use the ADS1115 to convert the analog output of the ZMPT101b.
To read the digital value from the ADS1115 with Arduino, use the Wire library or find a library for the ADS1115. For example this one.
I use ADC121 with Wire library. I initialize it in setup()
  const byte REG_ADDR_RESULT = 0x00;
  const byte REG_ADDR_CONFIG = 0x02;

  // initialize the Wire library
  Wire.begin();
  Wire.setClock(400000);

  // configure the ADC
  Wire.beginTransmission(I2C_ADC121);
  Wire.write(REG_ADDR_CONFIG);
  Wire.write(REG_ADDR_RESULT);
  Wire.endTransmission();

  // set the 'result' register as default
  Wire.beginTransmission(I2C_ADC121);
  Wire.write(REG_ADDR_RESULT);
  Wire.endTransmission();

and then in code I read the value with this function
unsigned short adcRead() {
  Wire.requestFrom(I2C_ADC121, 2); // request 2 bytes
  byte buff[2];
  Wire.readBytes(buff, 2); // read 2 bytes
  return (buff[0] << 8) | buff[1]; // get the result as 16 bit number
}


text:
How to program the nodeMCU through OTA using GPRS?
I'm using a NodeMCU in one of my projects. The setup is in a remote location. That place doesn't have WiFi so I'm using GPRS (GSM SIM800V) for sensor data collection to my server. Right now I need to update my new firmware to that NodeMCU.
Is it possible do OTA using GPRS (GSM SIM800V)?

https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#http-server

Yes, it is possible, but it takes some work on your part.
I recently had to implement OTA updates for the ESP32 over an RS-485 link, and it's actually pretty simple to manage. The hard part (for you) is the communication connection.
Performing an update (assuming the flash is already partitioned and set up right for OTA updates) is a case of "starting" the update, passing the update manager the flash data, then "ending" the update:

Update.begin(size) - This starts the upgrade process. You need to provide the expected size of the flash data at this point.
Update.write(*data, length) - Pass a block of flash data to the updater for writing.  An alternative is to read directly from a Stream class, which will try and read the number of bytes specified in the size parameter to begin.
Update.end() - This will finish it all off and switch the bootloader to load from the new flash. If it worked fine it will return true, otherwise, it will return false.

Assuming the above worked, you can no reset the board with ESP.restart()
For added security you can also pass an MD5 hash of the data to Update.setMD5(md5) and the updater will check that the uploaded data matches that MD5 hash.
Of course, all this needs implementing in your program that is running on the target device before you try and do any OTA updates. And, of course, you need to arrange the actual upgrade channel to get the commands and data through to the target in the first place.
So:

Implement a method of getting the data to the target
Implement the updater code
Go to the device and upgrade the firmware
From that point on you should be able to use OTA updates through your own chosen mechanism.


text:
Resistance measurement using loop resistance technique
Im trying do a circuit to measure resistance between Neutral and ground, for this I tried ohm law method i.e., to obtain R = (V/I). Voltage is known value 25 Vac, Current value is measured using ACS712 and tried the coding is given below, I'm getting current value from it, but when I apply ohms law I'm not getting resistance value.Please guide me
/*
Measuring AC Current Using ACS712
*/
const int sensorIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

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

void loop(){

 Voltage = getVPP();
 VRMS = (Voltage/2.0) *0.707;
 AmpsRMS = (VRMS * 1000)/mVperAmp;
 Serial.print(AmpsRMS);
 Serial.println(" Amps RMS");

}

float getVPP()
{
  float result;

  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here

   uint32_t start_time = millis();
   while((millis()-start_time) < 1000) //sample for 1 Sec
   {
       readValue = analogRead(sensorIn);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }

   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;

   return result;
 }

Welcome on this board! To increase the chance of getting a proper answer you should describe what you did, waht you expect and what didn't work as expected. Also please format your code (just select your code and press the{}-button).

What values do you actually get?

you should rename the variables


text:
ESP8266 NODEMCU V3, HOW TO USE AND CONTROL V3 OUTPUT POWER
this is my very first post in here so I apologise if I am not giving you all the information that I should.
I am creating this topic to ask you help regarding how to control and use the v3 output of my Nodemcu.
I have a script which is working fine to power on and off a led by using one of the GPIO and the ground. However, my project requires to power on a small motor for about 2 seconds and then stop it. If I connect this motor to one of the GPIO and the ground I can control it but it runs very slow. If I connect the motor to the 3V output it goes fine but I can't turn it on or off. The motor requires 3V to run properly. How can I turn it on and off by powering it from that 3V output?
What am I missing?
I have a 4n25 chip which I saw in a video that has been used for a similar project however the vide is in Portuguese and I am not able to follow it properly.
Can please someone advice?
Thank you for your time,
Ade

I would suggest to control the motor using FET rather than directly attaching it ESP pin. As these pins cannot supply enough current and you can damage your ESP by doing this. So use FET for motor and control the FET using gpio's of ESP, that will turn ON and OFF the motor.

Guys, thank you very much for replying so fast.
Which one would you suggest?
IRFZ44 Power MOSFET TO-220
or
20pcs/lot 2n7000 To92 Small Signal Mosfet 200 Mamps, 60 Volts N-channel To-92

irLz44n is the the logic-level version of the ever-popular irF44n, and one i use with ESPs a lot. be careful ordering them from a cut-rate webfront or auction house though; i've gotten ones that clearly were out of spec from places like that.

You cannot control the "V3" output. It's a 3.3V power supply output. Think of it like a battery. It's always on and always giving power.
Instead, you need to add a "switch" to control that power that the ESP8266 can itself control, such as a MOSFET or a motor driver (H-Bridge).


text:
Speed Control of Brushless DC Motor
I cannot understand the code of controlling the speed of brushless dc motor using ESP8266 WiFi Module.
I found it in- https://ubidots.com/blog/speed-control-for-brushless-motors-with-an-esp8266-2/
The part that I cannot understand is-

float btof(byte * payload, unsigned int length) {

  char * demo = (char *) malloc(sizeof(char) * 10);

  for (int i = 0; i < length; i++) {

    demo[i] = payload[i];

  }

float value = atof(demo);

  free(demo);

  return value;
}

// Callback to handle subscription

void callback(char* topic, byte* payload, unsigned int length)

{

    value = btof(payload, length);

      value = map(value, 0, 1023, 0, 180);

//Map the 0-100 values from the slider to the 0-180 to use the servo lib.

 ESC.write(value);

//Send the value (PWM) to the ESC

}

Please help me with the code!

What aspect of the code cannot you understand?  Without being specific, it is hard to help you.

The entire btof and callback function that have been created. Why have they been created, what is payload and length, why are we creating btof and callback function, what is the logic behind it and how are they related to speed control of brushless dc motor.

Callback function must be data send from server to the ESP.
Payload is the data byte sent from server.
Length is the size of data in bytes.
BTOF is basically byte to float converter which converts all the data byte received into single floating variable and return that floating point value.
ECS.write must be the function that write the value to the servo motor controller H-bridge IC. It belongs to servo library.
Value range that can be mapped into this ECS.write is between 0-180 so map function will use that will convert the floating point data received from btof function.
Basic definition of map() function:

Map function maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired.
Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers.
Syntax:
map(value, fromLow, fromHigh, toLow, toHigh)

Then ECS.write(value) will write that mapped value to servor motor controller H-Bridge.

Okay, thanks a lot for clearing most of it. Still I have few doubts- 1)char * demo = (char *) malloc(sizeof(char) * 10); Meaning of this line.   2) Is payload a defined function? Which library does it belong to?  (3) Also I would want to know about the subscribe function and client there in the code- client.begin(callback);   client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE);

In that case you need share your full sketch here. 1. char * demo = (char *) malloc(sizeof(char) * 10); Meaning of this line. You should clear your basic C concepts. In this you are assigning some memory space to this char pointer of 10 bytes size;

The full sketch is here in the link- https://ubidots.com/blog/speed-control-for-brushless-motors-with-an-esp8266-2/

Payload is a array pointer of byte type. It is declared in ESP8266 Library. Rest is features of TCP communication protocol. You should study about how TCp protocol works. Client Sever concept, what is publish and subscribe, and HTTP Post and Get request. Then you will know about these functions better.

Okay, thanks a lot!!

It would be great of your sir if you can also please provide some useful resources for the same if you have any?

this is a simple document that tells about esp8266 and contain reference links to other protocols a well document.

Thanks a lot sir for helping out! :)


text:
Arduino nano / uno analog pin
I'm working on a project where I need 7 analog pins.
I read the datasheet of Ardnuino Uno : 6 analog pins available.
So I decided to use an arduino mega with 16 analog pin available.
Then I saw the arduino nano had 8 analog pins.
But when I read the datasheet, both arduino uno and nano use Atmega328
In my final project, I will not use the board but only the pdip chip (analog pins are from pin number 23 to 28).
Is it possible to "convert" another pin of the pdip to be an analog pin ?
Thank you

If you want to stick with DIP parts, add an external ADC such as MCP3008, a 4-channel ADC with 10-bit resolution and fast SPI interface. Available at Digikey, easy to read from.

No, this is not possible. The datasheet of the ATmega328P
states it has:

8-channel 10-bit ADC in TQFP and QFN/MLF package
6-channel 10-bit ADC in PDIP Package

If you want to use a bare chip, it won't be possible with a PDIP
package.

A Nano and some ProMinis have all 8 analog input pins available from the 32-pin TQFP Atmega328P package. An Uno only has 6 of the 8 available in the 28-pin DIP package. Instead of the bare 28-pin DIP, use one of the 32-pin TQFP parts, on a breakout board, or as a packaged 'system' board; a Promini is the 328P with resonator and voltage regulator, connect to it with external FTDI module for programming/debugging; the Nano which goes a step further and adds a USB interface chip.


text:
Basic if endif not working and I'm puzzled
I got this small code I'm trying things on for like an hour.
int receivers = 0;
#if defined(PPM_RECEIVER)
  receivers++;
#endif

And I just cannot get it working, It keeps returning a "'receivers' does not name a type" on line 4.

Question about C/C++ syntax.  This is counted as off topic on Arduino SE.

Maybe you mistyped receivers; did you copy-paste the code here or rewrote it? Of course then this code is written inside a function, isn't it?

You can't use commands like receivers++ outside of a function.  That is runtime executable code, and has to be run from inside a function. Global scope doesn't get executed in the same way as code in a function.

Ah that makes sense, Thank you!


text:
Switch statement cases not executing
Overview:
I am trying to use a switch statement to run different tests. A main menu is displayed on the serial monitor, and then the user is given the option to enter their menu choice in the serial monitor. The menu choice entered in the serial monitor should subsequently run the appropriate case statement.
Issues:
 1. When I enter a choice the case statement for that choice does not run
 2. When I enter a choice my the serial monitor scrolls through my menu 3 times displaying 49, then 13, then 10.
Questions:

Why are my case statements not executing?
Why does the serial monitor scroll three times displaying these random numbers?
//////////////PREPROCESSOR DIRECTIVES/////////

#include <Wire.h>

/////////////GLOBAL VARIABLES////////////////

int ADDRESS_SLAVE = 0x08;
int ADDRESS_VERSION = 0x00;
int ADDRESS_STATUS = 0x01;
int ADDRESS_ENABLE = 0x02;
int ADDRESS_CONFIG = 0x03;
int ADDRESS_RESTART = 0x04;
int ADDRESS_STARTUP_STATE = 0X05;
int ADDRESS_COMPENDISREG1 = 0X07;
int ADDRESS_COMPENDISREG2 = 0X08;
int ADDRESS_COMPENDISREG3 = 0X09;
int ADDRESS_COMPENDISREG4 = 0X0A;
int ADDRESS_FAULT = 0X0B;
int ADDRESS_FAULTMASK = 0X0C;
int ADDRESS_TEST_MODE = 0X0D;

////////////SETUP CONDITIONS/////////////////

void setup()
{
 Wire.setClock(100000);
 Wire.beginTransmission(byte(ADDRESS_SLAVE));
 Serial.begin(9600);
}

////////////MAIN FUNCTION///////////////////

void loop()
{

  int choice = 0;

  int const
            //Clock 100
            CLOCK_FREQ_P = 101,
            CLOCK_FREQ_DIV4 = 102,
            CLOCK_FREQ_DIV8 = 103,
            CLOCK_FREQ_DIV16 = 104,
            CLOCK_FREQ_DIV32 = 105,
            CLOCK_INT_SUPPLY_IBIAS = 106,
            CLK_OK = 107,

            //Bandgap 200
            BG_2p5V = 200,
            BG_MAX_LOAD = 201,
            BG_VBE = 202,
            BG_VP = 203,
            BG_VGATE = 204,
mainMenu();

   choice = menuChoice();

   switch(choice)
   {
    case CLOCK_FREQ_P :
    {
      Serial.println(F("CLOCK_FREQ_P Not yet built out"));
      while(Serial.available() > 0)
        {
           int choice = Serial.read();
        }

      delay(10000);
    }
    break;

    case CLOCK_FREQ_DIV4:
    {
      Serial.println(F("CLOCK_FREQ_DIV4 Not yet built out"));
    }
    break;

    case CLOCK_FREQ_DIV8:
    {
      Serial.println(F("FREQ_DIV8 Not yet built out"));
    }
    break;

    case CLOCK_FREQ_DIV16:
    {
      Serial.println(F("CLOCK_FREQ_DIV16 Not yet built out"));
    }
    break;

    case CLOCK_FREQ_DIV32:
    {
      Serial.println(F("CLOCK_FREQ_DIV32 Not yet built out"));
    }
    break;

    case CLOCK_INT_SUPPLY_IBIAS:
    {
      Serial.println(F("CLOCK_INT_SUPPLY_IBIAS Not yet built out"));
    }
    break;

    case CLK_OK:
    {
      Serial.println(F("CLK_OK Not yet built out"));
    }
    break;

    case BG_2p5V:
    {
      Serial.println(F("BG_2p5V Not yet built out"));
    }
    break;

    case BG_MAX_LOAD:
    {
      Serial.println(F("BG_MAX_LOAD Not yet built out"));
    }
    break;

    case BG_VBE:
    {
      Serial.println(F("BG_VBE Not yet built out"));
    }
    break;

    case BG_VP:
    {
      Serial.println(F("BG_VP Not yet built out"));
    }
    break;

    case BG_VGATE:
    {
      Serial.println(F("BG_VGATE Not yet built out"));
    }
    break;

    delay(500);
}

////////////////FUNCTIONS/////FUNCTIONS/////FUNCTIONS/////FUNCTIONS///////////////////////////

//*******************************************
//**      Function: Main Menu Display
//**      Passes: nothing
//**      Returns: nothing
//*******************************************

void mainMenu()
{
  //Prints main menu to the serial monitor
  Serial.println();
  Serial.println(F("\t\t\t\t\t\t\t\t\t\t       ******************************"));
  Serial.println(F("\t\t\t\t\t\t\t\t\t\t       ******************************"));
  Serial.println(F("\t\t\t\t\t\t\t\t\t\t       **         MAIN MENU        **"));
  Serial.println(F("\t\t\t\t\t\t\t\t\t\t       ******************************"));
  Serial.println(F("\t\t\t\t\t\t\t\t\t\t       ******************************"));
  Serial.println();
  Serial.println(F("\t\t\t\t\t\t ********************************************************************************************************************"));
  Serial.println(F("\t\t\t\t\t\t **   Please type in the number of the test you want to run in the command line window at the top of the screen.   **"));
  Serial.println(F("\t\t\t\t\t\t ********************************************************************************************************************"));
  Serial.println();
  Serial.println();
  //                                        ******************
  //                                        ***  TOP MENU  ***
  //                                        ******************

  Serial.print(F("\t\t\t CLOCKGEN \t\t\t\t BANDGAP \t\t\t GPIO "));
  Serial.println();
  Serial.print(F("\t\t\t   (1) CLK_FREQ_P \t\t\t   (8) BG_2p5V \t\t\t   (13) GPIO0_PD \t (21) GP1_N_Buff \t (29) GP2_Buff_Max \t  "));
  Serial.println();
  Serial.print(F("\t\t\t   (2) CLK_FREQ_Div_4 \t\t\t   (9) BG_MAX_LOAD \t\t   (14) GPIO0_PU \t (22) GP1_W_Buff \t (30) GP2_Buff_Min "));
  Serial.println();
  Serial.print(F("\t\t\t   (3) CLK_FREQ_Div_8 \t\t\t   (10) BG_VBE \t\t\t   (15) GP0_N_Buff \t (23) GP1_Buff_Max \t (31) GPIO3_PD ") );
  Serial.println();
  Serial.print(F("\t\t\t   (4) CLK_FREQ_Div_16 \t\t\t   (11) BG_VP \t\t\t   (16) GP0_W_Buff \t (24) GP1_Buff_Min \t (32) GPIO3_PU "));
  Serial.println();
  Serial.print(F("\t\t\t   (5) CLK_FREQ_Div_32 \t\t\t   (12) BG_VGATE \t\t   (17) GP0_Buff_Max \t (25) GPIO2_PD \t\t (33) GP3_N_BUFF "));
  Serial.println();
  Serial.print(F("\t\t\t   (6) CLK_INT_Supply_(IBias)\t\t\t\t\t\t   (18) GP0_Buff_Min \t (26) GPIO2_PU \t\t (34) GPIO3_W_BUFF "));
  Serial.println();
  Serial.print(F("\t\t\t   (7) CLK_OK \t\t\t\t\t\t\t\t   (19) GPIO1_PD \t (27) GP2_N_Buff \t (35) GP3_BUFF_Max "));
  Serial.println();
  Serial.print(F("\t\t\t\t\t\t\t\t\t\t\t\t   (20) GPIO1_PU \t (28) GP2_W_Buff \t (36) GP3_BUFF_Min "));
  Serial.println();
  Serial.println();
  //                                        *********************
  //                                        ***  CENTER MENU  ***
  //                                        *********************

  Serial.print(F("\t\t\t VBUS COMPARITOR \t\t\t\t\t\t\t VAC COMPARITOR \t\t ISNS COMPARITOR \t\t TSNS COMPARITOR"));
  Serial.println();
  Serial.print(F("\t\t\t   (37) CLK_FREQ_P \t(47) BG_2p5V \t(57) GPIO0_PD \t\t\t   (61) GP1_N_Buff \t\t  (68) GP2_Buff_Max \t\t   (74) VB 2.715V Comparitor Test"));
  Serial.println();
  Serial.print(F("\t\t\t   (38) CLK_FREQ_P \t(48) BG_2p5V \t(58) GPIO0_PD \t\t\t   (62) GP1_N_Buff \t\t  (69) GP2_Buff_Max \t\t   (75) VB 2.715V Comparitor Test"));
  Serial.println();
  Serial.print(F("\t\t\t   (39) CLK_FREQ_P \t(49) BG_2p5V \t(59) GPIO0_PD \t\t\t   (63) GP1_N_Buff \t\t  (70) GP2_Buff_Max \t\t   (76) VB 2.715V Comparitor Test"));
  Serial.println();
  Serial.print(F("\t\t\t   (40) CLK_FREQ_P \t(50) BG_2p5V \t(60) GPIO0_PD \t\t\t   (64) GP1_N_Buff \t\t  (71) GP2_Buff_Max \t\t   (77) VB 2.715V Comparitor Test"));
  Serial.println();
  Serial.print(F("\t\t\t   (41) CLK_FREQ_P \t(51) BG_2p5V \t\t\t\t\t   (65) GPIO0_PD \t\t  (72) GP1_N_Buff \t\t\t\t"));
  Serial.println();
  Serial.print(F("\t\t\t   (42) CLK_FREQ_P \t(52) BG_2p5V \t\t\t\t\t   (66) GPIO0_PD \t\t  (73) GP1_N_Buff \t\t\t\t"));
  Serial.println();
  Serial.print(F("\t\t\t   (43) CLK_FREQ_P \t(53) BG_2p5V \t\t\t\t\t   (67) GPIO0_PD \t\t\t\t\t"));
  Serial.println();
  Serial.print(F("\t\t\t   (44) CLK_FREQ_P \t(54) BG_2p5V \t\t\t\t\t\t\t\t\t\t\t\t"));
  Serial.println();
  Serial.print(F("\t\t\t   (45) CLK_FREQ_P \t(55) BG_2p5V \t\t\t\t\t\t\t\t\t\t\t\t"));
  Serial.println();
  Serial.print(F("\t\t\t   (46) CLK_FREQ_P \t(56) BG_2p5V \t\t\t\t\t\t\t\t\t\t\t\t"));
  Serial.println();
  Serial.println();
  Serial.println();
  //                                        *********************
  //                                        ***  BOTTOM MENU  ***
  //                                        *********************

  Serial.print(F("\t\t\t QR COMPARITOR \t\t\t ADC \t\t\t MS Driver \t\t\t AC Driver \t\t\t Active Clamp FET \t\t  V10"));
  Serial.println();
  Serial.print(F("\t\t\t   (78) CLK_FREQ_P \t\t  (84) BG_2p5V \t\t  (87) GPIO0_PD \t\t  (96) GP1_N_Buff \t\t  (100) AC_FET_LEAKAGE \t\t   (1400) V10MIN_V10_OK_FAL"));
  Serial.println();
  Serial.print(F("\t\t\t   (79) CLK_FREQ_P \t\t  (85) BG_2p5V \t\t  (88) GPIO0_PD \t\t  (97) GP1_N_Buff \t\t  (101) AC_FET_LEAKAGE_SWEEP"));
  Serial.println();
  Serial.print(F("\t\t\t   (80) CLK_FREQ_P \t\t  (86) BG_2p5V \t\t  (89) GPIO0_PD \t\t  (98) GP1_N_Buff \t\t  (102) AC_FET_RDS_ON"));
  Serial.println();
  Serial.print(F("\t\t\t   (81) CLK_FREQ_P \t\t\t\t\t  (90) BG_2p5V \t\t\t  (99) GPIO0_PD"));
  Serial.println();
  Serial.print(F("\t\t\t   (82) CLK_FREQ_P \t\t\t\t\t  (91) BG_2p5V"));
  Serial.println();
  Serial.print(F("\t\t\t   (83) CLK_FREQ_P \t\t\t\t\t  (92) BG_2p5V"));
  Serial.println();
  Serial.print(F("\t\t\t\t\t\t\t\t\t\t  (93) CLK_FREQ_P"));
  Serial.println();
  Serial.print(F("\t\t\t\t\t\t\t\t\t\t  (94) CLK_FREQ_P"));
  Serial.println();
  Serial.print(F("\t\t\t\t\t\t\t\t\t\t  (95) CLK_FREQ_P"));
  Serial.println();
  Serial.println();
  Serial.println();
  Serial.println();
  Serial.println();
  Serial.println();

}

//*******************************************
//**      Function: menuChoice
//**      Passes: nothing
//**      Returns: integer for menu choice
//*******************************************

int menuChoice()
{
  int selection = 0;

  while (Serial.available() == 0);
  {
  selection = Serial.read();
  Serial.print("You entered: ");
  (int)Serial.println(selection, DEC);
  }
  return selection;
}

49, 13 and 10 are ASCII codes of characters you send from Serial Monitor

Hi Juraj...I understand these are ASCII codes, but it doesnt make sense if I enter 1, I get a 49 (1),13(carriage return), 10 returned (new line). Do have any idea how I can resolve this?

Why are you saying that it doesn't make sense? The codes that you receive are exactly what you typed and sent.

why are you not printing the value of choice right after choice = menuChoice();? .... that is a simple way of debugging the program

I think the issue is with the menuChoice() function. Try replacing it with this:

int menuChoice()
{
  int selection = 0;
  const byte bufferSize = 16;
  char inputBuffer[bufferSize + 1];

  if(Serial.available() > 0){
    // 50 bytes more in compile size using parseInt() vs
    // char buffer and atoi().
    // selection = Serial.parseInt();
    Serial.readBytesUntil('\n', inputBuffer, bufferSize);
    selection = atoi(inputBuffer);
    memset(inputBuffer, 0, sizeof(inputBuffer));
    Serial.print("You entered: ");
    Serial.println(selection, DEC);
  }

  return selection;
}

Of course, you could use parseInt() instead of the char buffer and atoi(), but the compile size is 50 bytes more.

Thanks VE7JRO! The parseInt() function fixed most of this problem. It still seems to pick up the carriage return; I would normally capture the carriage return with cin.get() in C/C++, but I don't know of a similar function available for Arduino. I did try to run the code you provided above, but the menu loops endlessly. Anyway...thanks again for bringing parseInt()to my attention...it helped a bunch!


text:
WiFi or Bluetooth to communicate between several Arduinos and a Raspberry Pi
So I want to set up a network of outdoor sensors (temperature and humidity) connected to an Arduino (and at some point a second or third Arduino further away with its own sensors). Then I'd like this Arduino to wirelessly transmit this data to a Raspberry Pi running some sort of server that can receive the data and then upload it to the cloud. I'm assuming WiFi is the best method to do this because of range and the number of devices at once? Would I just have to get each Arduino a WiFi module and what kind of range can I expect from this setup?

Comments are not for extended discussion; this conversation has been moved to chat.

I would also suggest using WIFI (ESP8266) as you need to create a local network in which all devices will communicate to single host connected to the same network. If range will be issue you can use LORAWAN network for the same. LORAWAN provide high network range and if industrial gateway is used you can connect 10000 nodes(arduino in your case) communicating to the single server at a time.Else WIFI will the good.

If I get an ESP8266-01 module to connect to an Arduino Mega or Uno, will the board still have enough digital and analog slots for some temp and humidity sensors?

Yes. ESP8266-01 require only UART pins to communicate with the arduino, so you have many pins left for another work.


text:
Software Serial blocking Wifi Connection
I'm trying to connect my NodeMCU to wifi. It isn't finishing because software serial is interrupting it.
Sort of like Software serial conflict with WiFi on ESP8266.
Here's my code:
#include <SoftwareSerial.h>
#include "ESP8266WiFi.h"

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

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

        connectWifi();

        SoftwareSerial pinSerial(1, 3);
        pinSerial.begin(9600);
}

void loop() {
    // send data received from serial port
}

// in separate function so I can reconnect in the loop
bool connectWifi() {
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
                delay(500);
                Serial.print(".");
        }
        Serial.println("");
        Serial.println("WiFi connected");
        Serial.println(WiFi.localIP());
        if( WiFi.status() == WL_CONNECTED) {
                return true;
        } else {
                Serial.println("wifi connection failed");
        }
}

The console outputs the periods as it's connecting but never prints the IP and instead prints the serial data it received while trying to connect.
Can I delay the activation of the software serial port? Should I use another serial library?
Please don't focus on basic code errors, I'm still learning.

you start SoftwareSerial on pins of the hardware serial.

oh you're right! how do I read and write to the hardware pins, not the usb port?

the USB chip of NodeMcu is wired to pins io 1 and io 3 of the esp8266 and you write and read it over Serial

SoftwareSerial pinSerial(1, 3); in setup() is strange as it 1) uses the hardware serial pins, 2) is never used other than begin(), and 3) is destructed when returning. What are you trying to do exactly?


text:
PT100 and MAX31865 readings showing wrong
I am using PT100 (3 Wire) to measure the temperature with Arduino Uno and MAX31865.
I have connected everything perfectly.
Configuration in the code i am using is :
max1.begin(MAX31865_3WIRE);

And the output is:
output
RTD value: 0
Ratio = 0.00000000
Resistance = 0.00000000
Temperature = -242.02

I am testing it in a room temperature.
My question is , is there any settings or calibration that i need to do, or any other way to test the PT100 sensor, because the temperature is showing correct readings ?

I had the same problem and was solved due to the comment of fshero (Jun 3 at 11:35) about a capacitor wich drops the voltage on PIN 20 of the MAX31865.
I have logged in just to highlight the solution. Thanks fshero!!

I've the same problem with my shields;
Where is the componant to remove on the shield to solve the problem?
a picture of the modification is welcome thanks a lot
fabien

I nearly have the same problem. I use five of the MAX31865-Boards with 2-Wire Termocouples on an Arduino Nano. Two of the five boards are working perfectly. The other 3 boards show exactly the same wrong behaviour you described. My temperature readings are exactly like yours (-242.02).
But I think I found the reason for the not working ones: The two working boards I bought on Amazon. The other three not working boards I bought on AliExpress. Maybe I (and maybe you too) got really bad fakes from China and they are simply dead :(
(BTW: If I remove one working board from the SPI bus and read out the temperature with the arduino, I get also the value of -242.02. This value seems to be an error value in the Adafruit MAX31865 library)
EDIT: Fixed it with a workaround!Like shown in the picture below, simply remove the wrong component (SMD Capacitor) and create a solder bridge . See comments for more informations!
Here is a picture of my modification of one chinese board as requested by the comments:

(It's not the best solution, but it works. For final using you should get the right filter ferrite and solder it on the board!)

I figured out the source of the error in my case: After some "debug measuring" with a multimeter I recognized, that the voltage of the VDD Pin of the Sensor is too low (1.6V but 3.3V are required)! It seems the chinese version has a capacitor at the place, where a originally a filter ferrite should be (see part FB1
at adafruit_products_schem.png). This causes the voltage drop. I removed the capacitor and replaced it with a solder bridge. Et voilá. It's working perfectly! :D

If wanted, I can provide some pictures of my modification

Can you provide a picture of the modification please..it will help me a lot.

Sure :) Look at my updated post. Hope this helps.

You have the eye of a vulture! Great find! Had the exact same issue, couldn't make the boards work until I removed that darn capacitor. These Chinese components are cheap, but come with some surprise headaches.


text:
Press one button then another?
Let's say we have two buttons - button 1 and button 2. What I need to do is to do something (like turn LED on) when button 1 is press, then button 2 is pressed. I can do it realy simple by just using two boolean variables, but how can we tell button 1 was the first pressed button?

Look up what a "finite state machine" is.  Use interrupts or digitalRead to check status of the buttons.

A nice solution is to use a state variable. In C/C++ (thus Arduino) you can use an enum variable for that.
enum EState
{
  // Button 1 and 2 are not pressed
  NoButtonsPressed,

  // Button 1 is pressed, button 2 is not pressed
  FirstButtonPressed,

  // Both buttons are pressed
  BothButtonsPressed
};

EState _state;

void setup() {
  // put your setup code here, to run once:
  _state = NoButtonsPressed;
}

void loop() {
  // put your main code here, to run repeatedly:
  switch (_state)
  {
  case NoButtonsPressed:
    if (digitalRead(1) == HIGH)
    {
      _state = FirstButtonPressed;
    }
    break;

  case FirstButtonPressed:
    if (digitalRead(1) == HIGH)
    {
      // Button 1 is still pressed, ignore second button.
    }
    else if (digitalRead(2) == HIGH)
    {
      // Button 1 is not pressed, button 2 is pressed.
      _state = BothButtonsPressed;
    }
    break;

 case BothButtonsPressed:
   // Switch on LED
   digitalWrite(2, HIGH);

   // Reset state.
   _state = NoButtonsPressed;
   break;

 default:
   // Other state, illegal.
   break;
  }
}

In every state you can define exactly what needs to be done. Because of the loop function being ran continuously, you just need to handle one state (change) at a time.
Additional notes:

Your requirements are not fully complete (like when to switch off the LED), probably when button 2 is released (which I don't check for), you can add a new state for this.
I did not take debouncing of buttons into account; you might need to do this especially if you check for releasing buttons. On the official Arduino website there is a good article about it.
I haven't tested the sketch.

Thank you! This solution is great! :)

Nice clean answer. (Voted)

It looks like this code should not have button bounce problems because it ignores button presses unless it's in the state waiting for that button press, and then it advances to a new state where it will ignore that button press and wait for the next one. As you say, if you get more elaborate, like responding to button releases, it will need debouncing.

@DuncanC Thanks for the upvote and comment. In the example above debouncing is not strictly needed, although I can imagine the user wants to have the LED off after the second button has been released, without debouncing, the LED will stay on a ms or less after the second button has been pressed because the second button will be pressed (LED on) and bounces back (switching off the LED). If the requirements are that the LED should be on until the first button is pressed, than debouncing is not strictly needed.


text:
Ways to add pins in an arduino
I'm making a project for school where I'm using flex sensors and converting that into words on an LCD (similar to the signing glove if you're familiar with that).
I ran into a problem since the Arduino I'm using doesn't have enough pins for all of my flex sensors and my LCD monitor.
I'm considering getting another Arduino with more pins but I might not have time to order it since my project is due in a couple of days. I was thinking about connecting two arduinos but I'm not sure if that would work (first year coding/engineering student) Any other suggestions as to how I can create more pins?
Your input is greatly appreciated!
The Arduino I'm using is a sparkfun redboard (it only has 6 analog pins and a separate place to plug in the LCD monitor which I connected to where it says ISP f you look on the link you will see what I'm talking about SparkFun RedBoard - Programmed with Arduino).
I'm using four flex sensors
LCD:

This can be done with the existing board. LCD can be driven by only with the digital pins. Check the below link for the wiring diagram.
https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay
Since there are 6 Analog pins available, all flex sensors can be easily connected.

This seems like a 1602 display. Note there are also I2C modules that connect to a 1602 making it possible to use it with only I2C wires (and VCC/GND).
See I2C-LCD-interface for a description, although there are many (similar) ones.
For the flex sensors you have 6 analog pins (hope that is enough). If not, than you need an external ADC (analog digital converter). Or connect a second Arduino and use I2C/SPI/Serial to transport the information from one Arduino to Another.


text:
Tinkercad but offline?
I have some issues with network and would like to work with arduino everywhere. I use Tinkercad which is great, but I would like to installit to my laptop and work without using WiFi. I couldn't find any "offline tinkercad" but maybe there are any similar programs where you can program AND write code inside.

I never use such things, but I seem to have an idea that Proteus may be what you want?

Nah I want arduino, I am  a beginer and Proteus is a bit  complicated

The only thing you can get that is Arduino is the IDE.

do you need the hardware sim of tinkercad, or just the ability to run code?

I want to connect everything to an arduino just like in tinkercad, without using an actual arduino. I do have the Arduino IDE, but there (for what I know) I can only write code, which I can't test without using Arduino

The best replacement (but keep in mind that Tinkercad is prob the best for code AND hardware sim) would be Yenka. They offer a "block style" language but you can go in depth with the hardware more than most programs.
Here is a ref image:

is the block style optional, 'cause i want to write code by myself?

i don't think so sadly


text:
Reset Button not working + Can't Upload code , What is wrong?
I was testing and debugging a code I wrote for a robot with 3 stepper motors on  (Arduino Uno + CNCShield V3 + a4988 stepper drivers). I want to disable drivers at will. so I bypassed EN pin on 2 of a4988s to pin12 and pin13 of Arduino. (by defalut all EN pins of drivers are are connected to pin8 ) everything was ok but suddenly the Reset button is not working and I can't upload new codes to Arduino! I get this error:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x83
.
.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x83
Problem uploading to board.

but Arduino still is working with the last code that was uploaded to it!!! have I fried my Arduino? and Why is this happening?

Quick thought:  Did you try a different COM port on your computer.  (It may not be an Arduino problem at all.)  If your OS is Linux try "lsusb" to see where the Arduno is connected.  If Windows there are utilities you can install to see better what USB devices are connected.

I tested another Arduino Uno with my code and computer (windows 10) . It was OK. Somethings are wrong with my new wiring (pin 12 @ 13). I'm afraid It will fry the other board too.

Try manually resetting the board:

Before uploading, run Verify.
Hold the reset button and click Upload.
Release the reset button.

If that worked, your board's reset isn't fried, it just isn't receiving a reset via the serial cable. If it failed, either part of the board or MCU may be damaged; something attached to the board may be inhibiting the reset signal; or the software may have disabled the board's reset pin. In the latter case, see the Arduino StackExchange article, How do I repurpose Arduino's reset button, for how this can happen and how to undo it if it has.

Is here anything wrong with using pins 12 and 13?

I'm not familiar with stepper driver, but at a quick glance at its data sheet, and it's logic being 3.3v & 5 v compatible, I don't see any problem with connecting any of its logic to any of Arduino's logic pins (almost all of them). Since the driver also has a motor drive-voltage input for driving your motors, accidentally connecting an Arduino pin to a driver pin (or anything else) carrying the drive-voltage could - probably would - damage at least the connected pin driver in the MCU, and possibly other parts of it as well.
If your Arduino has a socketed Atmega chip, and since you already know another Arduino works as you expect it to, replacing the Atmega chip will be the quickest, cheapest & easiest fix. Just go over your wiring and make sure no motor drive voltages are connected to the Arduino board.

I tried it. Holding reset button didn't work. Is here anything wrong with using pins 12 and 13? I guess this is what made my Uno fry!


text:
problem serial hardware sim7600 arduino due
I am very newbie using arduino. I get a EVB SIM7600 TTL 3V and I am trying to test it using a arduino Due.
I need a help please, my simple code doesnt work.
The serial monitor only show zeros. The baudrate default for SIM7600 is 115200bps. I insert a simcard and then write AT command in serial monitor, for example ATI... I received zero
Here is my code and photo of connection.

void setup() {

  Serial.begin(115200);
  Serial.println("Testing GSM SIM7600");
  Serial1.begin(115200);
  delay(100);

}

void loop() {

  if(Serial1.available())
  {
    Serial.println(Serial1.read());
  }

  if(Serial.available())
  {
    Serial1.write(Serial.read());
  }

}

I didn't see anything like AT Command in your sketch. Share your full sketch.

I send command AT using Serial monitor text box. I can connect to module using the  built in usb serial interface, then using putty com5 baudrate 115200 I can use them and even access to internet like a modem LTE. The complete sketch is same I posted :S still i can not do anything :( with arduino due

let go to step by step and solve the problem. You direct interface of module from USB to you PC and then try to send AT commands. Please don't forget to use EOL characters like \r \n at the end of AT command like this AT\r\n.

the serial usb interface of SIM7600 is working fine in windows. The problem is arduino due communication, but I know can understand the problem is a code I wrote. I checked yesteday the display work better using Serial1.readString (), but still I have searching the solution. sorry my english


text:
Compute SHA256 of string and output to string
In my Arduino project I want to compute the SHA256 hash of a string and store the result to a string, and do this recursively many times (i.e. compute hash of hash of hash etc...). So my goal is to have a reliable function as follows:

String h(String input) {
...
return output;
}

where for example h("abc") would return "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad".
I downloaded this library
(from Tools->Manage libraries, it is also in github) and then ran the example in TestSHA256.ino which passes all the checks. However I'm stuggling to make my function work since the library doesn't have a specific example on how to compute and return a SHA256 hash.
I have been looking in function testHash_N() in TestSHA256.ino, which appears to create a hash (from struct TestHashVector data) and compare it with the precomputed hash (from struct TestHashVector hash[]).
The hash seems to be computed in lines 89-96 in TestSHA256.ino.  I just want to take the actual hash string result, so for testVectorSHA256_1  in the example, I would need to have a string = "ba7816bf....15ad" as the result.
I understand that this is related to memory referencing in Arduino but I'm not experienced so I'd be grateful if you helped me with this.
EDIT: My code snippet so far is as follows, but it doesn't output the correct hash..
#include <Crypto.h>
#include <SHA256.h>
#include <string.h>

#define HASH_SIZE 32
#define BLOCK_SIZE 64

char hex[256];

char *hashvalue;

SHA256 sha256;

byte buffer[128];

char *btoh(char *dest, uint8_t *src, int len) {
  char *d = dest;
  while( len-- ) sprintf(d, "%02x", (unsigned char)*src++), d += 2;
  return dest;
}

char* h(Hash *hash, char* hashvalue)
{
    size_t size = sizeof(&hashvalue);
    size_t posn, len;
    size_t inc = sizeof(&hashvalue);
    uint8_t value[HASH_SIZE];

    hash->reset();
    for (posn = 0; posn < size; posn += inc) {
        len = size - posn;
        if (len > inc)
            len = inc;
        hash->update(&hashvalue + posn, len);
    }
    hash->finalize(value, sizeof(value));

    return(btoh(hex, value, 32));
}

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

    bool tmp;
    char *testvalue = "abc";
    Serial.println(h(&sha256,*testvalue));

}

void loop()
{
}

Hint#1: sizeof(&hashvalue); is not the length of the string. It is the number of bytes of a pointer.

Hint#2: *testvaluein the statement h(&sha256,*testvalue)); is not a pointer. It is actually the value of the first character, a in the testvalue.

Hint#3: uint8_t value[HASH_SIZE]; is a local value and cannot be returned. static uint8_t value[HASH_SIZE]; will allow that.

Thank you very much for helping

The main trick is to understand how the Arduino String class works. You can find the source code in your installation of the Arduino IDE or on github.
The basic pattern you are looking for is:
String h(String& input) {      // Pass String by reference to avoid copying
  char output[OUTPUT_MAX];
  char* data = input.c_str();  // Access to internal buffer
  ...
  return String(output);       // Return a String object of the output
}

Cheers!

Thanks, I've updated my question with an attempt to solve this but I'm still struggling with errors, can you please help me with the code inside to make it work?

Yes you have several issues but before going forward please acknowledge that you received an answer to your original question :) and I will get back to you.

ok right, just want to solve my problem in its entirety

Updated my code again, it works but it doesn't output the correct hash, outputs "ffe9aaeaa2a2d5048174df0b80599ef0197ec024c4b051bc9860cff58ef7f9f3" instead of "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"

I suggest the following function. That replaces a string by its hash.
It's done in place in order to save memory. Make sure the buffer you
give it is at least 65 bytes long. Warning: not tested.
#include <Crypto.h>
#include <SHA256.h>

#define HASH_SIZE 32

SHA256 sha256;

/*
 * Replace a string by its hash, in place.
 * `data' should point to a buffer at least 65 bytes in length.
 */
hash_in_place(char *data)
{
    uint8_t value[HASH_SIZE];

    sha256.reset();
    sha256.update(data, strlen(data));
    sha256.finalize(value, sizeof(value));

    // Convert to hex into the original buffer.
    data[0] = '\0';
    for (size_t i = 0; i < HASH_SIZE; i++) {
        data += sprintf("%02x", value[i]);
    }
}

Nice implementation! Could avoid sprintf() to reduce program memory size.


text:
Getting two trinkets to talk to each other via the serial pins
I'm trying to make a quick proof of concept of two trinket M0s talking to each other via their RX and TX pins and I'm not able to get it working.
I uploaded sender and receiver sketches to two trinkets:
//sender.ino
char state[10] = "hello";

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

void loop()
{
    Serial.write(state, 5);
    delay(1000);
}

//receiver.ino
char state[10];

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

void loop()
{
    Serial.println("reading bytes");
    Serial.readBytes(state, 10);
    Serial.println(state);
    delay(1000);
}

After the uploads I wired the two trinkets together, jumping the RX of the first to the TX of the other and TX of the first to the RX of the other. I also connected their grounds to have a common ground.

I plugged the sender into a battery and the receiver into my computer. The problem I'm running into is that when I look at the serial monitor for the receiver instead of getting the expected "hello" I'm getting broken strings of "TestingOpen":

I double checked the pinout diagram and guide for the Trinket M0 to make sure I was using the correct RX/TX pins (pin 3 for RX, 4 for TX) and it all seems fine but obviously something is still going wrong.
Anyone know what I'm missing or misunderstanding?

1) you should use if (Serial.available()) before starting to read with readBytes. now you print random memory
2) readBytes is blocking. it waits for the next character until a timeout. default timeout is 1 second. after "hello" was received it waits a second. you could use readBytesUntil and some 'separator' character for example '\n' (new line)
3) readBytes returns the count of bytes read. you should use it to terminate the buffer
void loop()
{
  if (Serial.available()) {
    Serial.println("reading bytes");
    size_t l = Serial.readBytesUntil('\n', state, 10);
    state[l] = 0;
    Serial.println(state);
  }
}


text:
How would you add Arduino WiFi Module using I2C or serial interface?
I am new to Arduino prototyping. I bought an Arduino Automatic Smart Plant Watering Kit 2.0 thinking it was a shield to use with my Arduino Uno WIFI Rev 2.  However, it turns out to be a specially designed Arduino board with all of the components integrated together.
While the system works as designed, my goal is to stream the data to IBM Watson Studio, or some other third-party SaaS.
I welcome feedback to understand how it might be possible to integrate the ESP8266 WIFI module using either the I2C or Serial interface. Here is the sample code: https://www.elecrow.com/download/watering_kit.zip I used a Raspberry Pi to get access to the data and use it in a web/mobile application but I'd like to eliminate this element, if possible.

esp8266 arduino core doesn't have a working I2C slave library. and 32u4 has Serial1

I appreciate the prompt feedback. so, maybe the better solution than connecting to a Raspberry Pi is to set up this Arduino board to communicate with another Arduino like the Wifi Rev2 or Arduino YÚN Rev 2?
https://www.arduino.cc/en/Tutorial/MasterWriter

why? you can attach esp8266 to Serial1 of this board (the "Serial interface" connector). (How did get the idea about Yun? Forget Yun.)

okay, it's forgotten! I am grateful for the feedback.

You would connect the ESP8266 to the serial port.  The normal way of working with an ESP98266 is to issue AT command (like an old Hayes modem) through a serial connection. Since you have one of those available on your board it is a simple matter to just wire it directly to it.
Just follow any of the myriad of ESP8266 + Arduino tutorials, substituting the pins in the examples for your serial pins, and use the Serial1 object instead of the SoftwareSerial class that you have to use on an Uno that lacks extra serial ports.


text:
DC motor phototransistor control
So basically I have a circuit with a phototransistor, and want to convert the phototransistor value into a PWM signal that can control the speed of the motor. The code I came up with is below, however it does not work. What have I done wrong in my code? I am using an l293d chip.
int photoTran = A1;
int reading = 0;
int forward=2;
int backward=3;
int motorspeed=0;

void setup(){
  pinMode(photoTran,INPUT);
  Serial.begin(9600);
  pinMode (backward, OUTPUT);
  pinMode (forward, OUTPUT);
}

void loop(){
  lcd.setCursor(0,0);
  reading = analogRead(photoTran);
  lcd.print(reading);
  lcd.print("  ");
  delay(100);
{
  if (reading<30){
    digitalWrite(backward,HIGH);
    digitalWrite(forward,LOW);
    motorspeed = map(reading, 30, 1023, 0, 255);
    analogWrite(backward,motorspeed);
  }
  else {
    digitalWrite(backward,LOW);
    digitalWrite(forward,HIGH);
    motorspeed = map(reading, 30, 400, 0, 255);
    analogWrite(forward,motorspeed);
  }
  }
}

You need to be a little more specific than that. Do you know that the phototransistor works on its own, and same with the motor driver? Also, what is not working? Is it not compiling, not showing a proper value on the lcd, not affecting the motor, etc? In your code I see "{" after your delay(100) which I don't see that purpose of that and why the if/else statements are inside it. I would get rid of that and test.

A phototransistor is hard to calibrate, and should rather be used as a switch (digitalRead)

analogRead() returns an integer between 0 and 1023. Using 30 and 400 in the map() function, then passing in a value outside of that range will cause strange results. Here is a sketch to illustrate my point.
void setup(){

  Serial.begin(9600);

  // Prints -20 to 684
  for(int i = 0; i < 1024; i++){
    Serial.println(map(i, 30, 400, 0, 255));
  }
  Serial.println();

  // Prints -7 to 255
  for(int i = 0; i < 1024; i++){
    Serial.println(map(i, 30, 1023, 0, 255));
  }
  Serial.println();

  // Prints 0 to 255
  for(int i = 0; i < 1024; i++){
    Serial.println(map(i, 0, 1023, 0, 255));
  }
}

void loop(){}

If you are using l293d you must control the voltage on its ENABLE PIN rather than controlling it on other INPUT PINS (l293d). Here is simple tutorial on controlling the Motor using L293d. here.
And @VE7JRO is right about map() function as your are passing the values that are out of range please take care of that part as well.