text:
Can't fetch arduino param on server, Using POST method via arduino wifi shield
I am creating a slot sensor, using photoresistor.
The goal is to send the photoresistor value, via analog read, pin A0 to my web server, so I can stored it in my database.
void loop() {
  int sensorvalue = analogRead(A0);// LightValue, read from sensor pin A0
  data = "sensorValue=" + (sensorvalue);
  //there is a car parked
  if(sensorvalue >=1000){
    if(flagstatus == false){
            if (client.connect(server, 80)){
              Serial.println("Connected to Host Server");
              client.println("POST /dataPost.php/HTTP/1.1");
              client.print("Host:");
              client.println(server);
              client.println("Content-Type: application/x-www-form-urlencoded");
              client.print("Content-Length: ");
              client.println(data.length());
              client.println();
              client.print(data);
I've been trying to send mock data via postman, and it works like a charm, so I can eliminate my server side from the equation. Been guessing using : or = on sensorvalue=analogread(a0) or sensorvalue:analogread(a0). Or I made mistake on the code? I don't know much in Arduino, and this issue kinda frustrate me.

the Image just for confirmation only, of course I installed the protoboard correctly.
Connect to SSID: Adamar
IP Address: 192.168.1.14
Connect to server...
Connected with network---------
Connected to Host Server
sensorvalue:1007
There is still a car parked
sensorvalue:1007
There is still a car parked
sensorvalue:1008

I manage to get this result from my serial monitor, so I think there is no wrong reading from my setup.

Before you start writing software that generates HTTP requests, you really should learn the format of an HTTP request.

hi, thank you for your friendly reminder :) Any suggestion? been go back and forth around this topic without any clear answer. About format, all snippets code, and example code from arduino written that way :)

You might want to look at the line "POST /dataPost.php/HTTP/1.1"

thank you for the hint on POST /dataPost.php/HTTP/1.1 , could you please be more elaborate?

The correct format is POST /dataPost.php HTTP/1.1

Hi, thank you for spotting my mistake. I already update my arduino sketch. It almost took my breathe away, but I hate to say this. The issue persist.
client.connect("the******tem.com", 80)){       client.println("POST /dataPost.php HTTP/1.1");        client.println("Host: the******tem.com");       client.println("Content-Type: application/x-www-form-urlencoded");       client.print("Content-Length: ");        client.println(data.length());       client.println();       client.print(data);       client.stop();
already double check with http request format. Any idea about this?

you have not said anything about any errors that you are or are not getting

@jsotola Hi, thank you for highlight this. But I am really sorry, I didn't get any errors report.

print the response

hi @Juraj it is nice to meet you here. I read a lot your answers. You are such a big help for community.  What kind of response do you need?
It confuse me, since we still can see sensor value from serial monitor.
I would like to update this issue, it may be because of server hosting fault. I can manage to store data via GET although I understand it is not the best practice.

Thank you @Majenko :)


text:
How to adapt this code using a DF Mini Player and interrupts for the ATTiny85?
So I programmed my Arduino Mega 2560 to play certain sound effects from a DF Mini Player that I have. I  took the base code that I modified from online so some fo the names might seem odd. Currently, when uploaded to the Arudino, it works as it should, "buttonPause" and "play()" only play one of the audio files WHILE I am pressing a button. "buttonNext"/"play1()" and "buttonPrevious"/"play2()" activate a sound when a button is tapped (not held down). To allow the sound effect to play in full only while I'm, holding down "buttonPause," I had to use a delay as well as interrupt to stop the playback as soon as I released the button. However, I know aside from changing pin numbers, there are some other alterations I have to make for the interrupt to adapt it to work with the ATTiny85. Any idea how I can get started on making those changes? I have been confused by the sources I have found online.
Full code for using the DF Mini Player with the Arduino Mega
///              MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
# define ACTIVATED LOW

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;
const byte interruptPin = 3;
volatile byte state = LOW;
int buttonState = 0;
int buttonState1= 0;
int buttonState2= 0;
int ledPin = 9;

void setup () {
pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);
mySerial.begin (9600);
attachInterrupt(digitalPinToInterrupt(interruptPin), pause, CHANGE);
pinMode(ledPin, OUTPUT);

}
void loop () {

buttonState = digitalRead(buttonPause);
buttonState1 = digitalRead(buttonNext);
buttonState2 = digitalRead(buttonPrevious);

if (buttonState == LOW)
  {
      play();
      setColor(255, 0, 222); // red
      digitalWrite(ledPin, HIGH);
      delay(1500);

  }

if (buttonState1 == HIGH)
  {

  }

if (buttonState == HIGH)
  {

  }

  if (buttonState1 == LOW)
  {
      play1();

      delay(100);

  }

if (buttonState2 == HIGH)
  {

  }

    if (buttonState2 == LOW)
  {
      play2();

  }

}

void pause()
{
  execute_CMD(0x16,0,0);

      digitalWrite(ledPin, LOW);
}
void play()
{
  execute_CMD(0x03,0,1);
}
void play1()
{
  execute_CMD(0x03,0,2);
}
void play2()
{

  execute_CMD(0x03,0,3);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}

Board Layout
The amount and placements of the resistors seemed to reduce the amount of noise as much as possible.

why do you need to use an interrupt?

So that when I release "buttonPause" it immediately interrupts the delay (that allows it to play through without moving to the next audio clip) and stops the playblack. I attempted to use millis instead of delay and interrupt to avail.

source: Stack Exchange

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

sort: votes


text:
ESP32 Wifi not working when powered by battery
I'm quite new to ESP32 development. I've been using this devkit for a few small projects and everything was going smoothly until I decided to run it on battery. In particular, the ESP32 devkit I'm using, when connected to a battery, seems to have issues when trying to connect to the Wifi.
I'm using a 9V battery connected to a MB-V2 power supply to convert the output voltage to 3.3.V. The power supply board has the following specifics:

Input voltage: 6.5-9v (DC) via 5.5mm x 2.1mm plug
Output voltage: 3.3V/5v
Maximum output current: 700 mA
Independent control rail output: 0v, 3.3v, 5v to breadboard

As you can see in the picture, my multimeter measures an output voltage of about 3.3V

I built a sample project for debugging, here's the schematics:

The battery is connected to the power supply which outputs 3.3V and powers the ESP32 through its 3.3V pin. I don't have a schematic for this specific devkit I'm using so the devkit used in the schematics is the DOIT one, hence all of the pins are off. The code is quite simple, though, so it hopefully can clear things a bit:
#include <WiFi.h>

const int uS_TO_S_FACTOR = 1000000;
const int TIME_TO_SLEEP = 3;
const int RED_LED_PIN = 32;
const int BLUE_LED_PIN = 25;
const int YELLOW_LED_PIN = 26;
const char SSID[] = "SSID";
const char PASS[] = "PASS";

void startupSequence(){
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  // Sequence
  digitalWrite(RED_LED_PIN, HIGH);
  digitalWrite(BLUE_LED_PIN, HIGH);
  digitalWrite(YELLOW_LED_PIN, HIGH);
  delay(1000);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  delay(500);
}

void setup(){
  Serial.begin(115200);
  while(!Serial){}
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
  pinMode(YELLOW_LED_PIN, OUTPUT);
  startupSequence();
  delay(500);
  digitalWrite(RED_LED_PIN, HIGH);
  delay(1000);
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);
  while ((WiFi.status() != WL_CONNECTED) && (millis()<10000)) {
      Serial.print(".");
      delay(500);
  }
  Serial.print("Connected. IP: ");
  Serial.println(WiFi.localIP());
  digitalWrite(RED_LED_PIN, LOW);
  if(WiFi.status() == WL_CONNECTED) //Run this only the first time
  {
    Serial.println("Connected");
    digitalWrite(YELLOW_LED_PIN, HIGH);
  } else
  {
    Serial.println("Not connected");
    digitalWrite(BLUE_LED_PIN, HIGH);
  }
  delay(3000);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  Serial.println("Going to sleep");
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

void loop(){}

In the code, the ESP32 first lights up all LEDs, then it lights up the red LED while it tries to connect to the Wifi. After at most 10 secs, it lights up the yellow LED if it successfully connected, otherwise it lights up the blue LED. Also, as a last thing I send the ESP32 into deep sleep, as my intention was to measure its power consumption during sleep.
When connected to the PC, everything runs smoothly, while when connected to the battery the ESP32 (apparently) never exits the while loop and the red LED stays always on. The RED led then starts flickering and the power LED start blinking. Resetting it throught the RST button on the devkit causes the power LED to start blinking and the red LED never lights up. This continues until I cut off the power, then the code seems to start again from the beginning (i.e. the startup sequence) and the this behavior repeats.
I've read a few posts about similar issues with ESP32 devkits, but the problem was always about batteries not having high enough voltage, which doesn't seem to be my case. What could be causing the issue?

Common problem. These 9V block batteries are not meant for providing the needed current. They are only for low power appliances, like smoke detectors or IR remotes. Use a battery that can actually provide the needed current (can be up to 1A for a short time with Wifi working)

The third point my answer to this question talks about that.

"batteries not having high enough voltage, which doesn't seem to be my case" - It is as soon as you actually draw some power from the battery. Then - due to the batteries internal series resistance - the voltage will drop fast.

try the gnd pin on the upper right, that one on the lower/middle left is apparently not a gnd but is mislabeled as one on some of my modules. drove me nuts...

@chrisl you're completely right, I didn't realize it was the battery. I switched it with my phone power bank, which connects through a USB cable, and everything works fine. I didn't record currents over 120 mA even with the Wifi working though.

I have this same issue. It's quite annoying because my Arduino used to work just fine. After switching over to ESP32, 4 1.5V AA batteries ain't cutting it. I guess I'll have to order yet another battery case...

I agree with chrisl, the battery does not have a low enough impedance to operate your project. What you are not taking into account is the transmitter current when it is transmitting to the wifi. I have been finding that when it wakes up it draws upwards of 500mA for a short time, measured with a scope and current probe. This appears during the " WiFi.scanNetworks()" function. Add on top of that all the LEDs and other electronics What do you think it will draw. The fact that it operates on the USB also helps confirm this. Try with 6 bigger batteries in series, I expect it to work properly. Check this link out from:Expressif, the manufacturer of the chip at https://esp32.com/viewtopic.php?t=2662

Also replacing the linear regulator with a switching one of >1A will help matters considerably.

Thank you very much, it was the battery, I switched it for a power bank and everything works fine. I didn't realize how power-hungry the ESP32 can be. I'll try to use some of the suggestion in this thread since the power bank has another issue: it shuts down during the ESP32 deep sleep phase, but that's a different issue.

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


text:
Micronucleus firmware 2.6.1 - Activate bootloader put D- pin to high
I flashed my ATTINY85 Digispark v3.0 with micronucleus firmware 2.6.1 and it works fine, the onboard led lights up and the another led blinks twines every 500ms (not sure way but it seams like everything is working correcly). But now I don't understand how to activate the "flash" mode to upload my program or upload a new bootloader.
I'm familiar with pull-up resistor but have never used it on a USB pins before (If I'm not mistaking the bootloader is activated to receiver programing when USB Data minus have a pull-up resistor and the board is reset and not only powered on).
Below are the condition to enter bootloader, text copied from micronucleus github page. https://github.com/ArminJo/micronucleus-firmware#entry_d_minus_pullup_activated_and_entry_ext_reset-entry-condition
ENTRY_D_MINUS_PULLUP_ACTIVATED_AND_ENTRY_EXT_RESET
Activate the bootloader only if the D- pin is high, i.e. a pull-up resistor is attached and powered and we have an ENTRY_EXT_RESET condition. Useful if the pull-up is powered by USB V+ and NOT ATtiny VCC to save power. In this case often a schottky diode is connected between V and VCC.
I have tried using a resistor from USB V+ to USB D- and resetting it using PIN 5 to ground but the leds just blinks to indicate a reset but no connection to is establish.
So if someone knows how this should work let me know.


text:
FastLED: "Invalid pin specified" when specifying LED_TYPE from WS2811 to WS2801
I'm trying to run the "DemoReel 100" code from FastLED.
Out of the box, it can be verified.  But when I switch from #define LED_TYPE    WS2811 to #define LED_TYPE    WS2801, I get the error:

error: static assertion failed: Invalid pin specified
static_assert(validpin(), "Invalid pin specified");

the line this error originates from is:
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

I can't think of any reason that the LED_TYPE argument should change whether or not a data-pin is valid.  What's going on?

I figured it out.  There's two lines for FastLED.addLeds, and one needed to be commented out and the other enabled in order have a clock pin work.
//  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);


text:
sdFat and Serial conflict?
I am using the sdFat library to manage an SD card with an ATmega1284p @ 8MHz internal clock. I have come across a strange issue in my system, and I created the smallest sketch that shows the problem: What I do is, that i call sd.begin() in the setup(), and then in Loop, I open a file and write the word "test". After that, I close the Serial and I turn off the SDcard's power (TLV_EN signal). After a while I re-enable the power and restart Serial. The second time I try to open the file to write "test", it fails. If I, however, comment out the Serial.end() and Serial.begin() commands, everything works as expected.
Here is the code:
#include <Arduino.h>

//Power Management Libraries
#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/sleep.h>

//SD Card
#include "SdFat.h"
#include "sdios.h"
#include "FreeStack.h"
#define SD_FAT_TYPE 1
const uint8_t SD_CS_PIN = 3;              //SPI CS pin of SD card
#define SPI_CLOCK SD_SCK_MHZ(2)

// Try to select the best SD card configuration.
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
SdFat32 sd;
File32 file;

const char fileName[]="COMPMEAS.TXT";     //8.3 supported filenames: https://en.wikipedia.org/wiki/8.3_filename
int count=1;

//PSU Enables
const uint8_t TLV_EN=1;

// Serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// Store error strings in flash to save RAM.
#define error(s) sd.errorHalt(&Serial, F(s))
//------------------------------------------------------------------------------

void setup() {
  pinMode(TLV_EN, OUTPUT);    // sets the digital pin 13 as output
  digitalWrite(TLV_EN,HIGH);      //TLV high enable
  delay(100);
  Serial.begin(38400,SERIAL_8N1);
  Serial.println();
  Serial.println();
  Serial.println(F("Hello!"));
  Serial.println();

  //SD Setup
  Serial.print(F("- Initializing SD card..."));
  while (!sd.begin(SD_CONFIG)) {
    Serial.println();
    Serial.print(F("SD initialization failed. Retrying in 2 seconds..."));
    delay(2000);
  }
  Serial.println(F("done."));

  Serial.println(F("- Setup Complete."));
  Serial.println(F("=================================================="));
  Serial.println();
  delay(5000);
}

void loop(){
  Serial.print("Loop: ");
  Serial.println(count);
  count++;
  if (!file.open(fileName, O_RDWR | O_CREAT | O_APPEND )) {
    Serial.println(F("- SD open failed!"));
  }
  else{
    Serial.println(F("- SD open success!!!"));
    if(file.write("test", strlen("test"))!=strlen("test")){
      Serial.println(F("- SD write failed!"));
      error("write failed");
    }
    else{
      file.flush();
      Serial.println(F("- SD write success!!!"));
    }
    file.close();
  }
  delay(1000);
  Serial.end();
  delay(1000);
  digitalWrite(TLV_EN,LOW);      //TLV high enable
  delay(1000);

  digitalWrite(TLV_EN,HIGH);      //TLV high enable
  delay(1000);
  Serial.begin(38400,SERIAL_8N1);
  while(!Serial){
  }
  delay(1000);
  Serial.println("----------");
  delay(5000);
}

Here is the result on console:
Hello!

- Initializing SD card...done.

- Setup Complete.
==================================================
Loop: 1

- SD open success!!!
- SD write success!!!
----------

Loop: 2

- SD open success!!!
- SD write failed!
error: write failed
SdError: 0X1D,0XFF

I tested your code almost verbatim using an SDCard shield that was designed to work with the UNO and so I used an UNO.  The only change to the code was to SD_CS_PIN.  This was using SdFat 2.0.4.  I have run it for at least 20 iterations reporting success on both open and write.  I have not investigated further yet.  Thought I'd just contribute that information for now anyway.  It seems unlikely that being a ATMega1284P will play into this, but perhaps.  If I happen to find one I may try it later.

Regarding your SdError: 0X1D,0XFF, this is apparently a read timeout.  Not sure what to do with that information though.  Maybe seeing how you've wired it would help.


text:
Set TX, RX to LOW before sleeping, re-enable uart after waking up
I have an ATmega1284p and I need to have the TXD0 (i.e. pin 9) set to LOW, before going to sleep. After waking up, I want to restore UART0 communication to work as expected. Here is my code:
Serial.begin(38400,SERIAL_8N1);

*do Stuff*

Serial.end();
//pinMode(9,OUTPUT);
//digitalWrite(9,LOW);
//UCSR0B &= ~bit (RXEN0);  // disable receiver
//UCSR0B &= ~bit (TXEN0);  // disable transmitter
cli();
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// turn off brown-out enable in software
//MCUCR = bit (BODS) | bit (BODSE);  // turn on brown-out enable select
//MCUCR = bit (BODS);        // this must be done within 4 clock cycles of above
sleep_bod_disable();  //disable brown-out detection
sei();             // guarantees next instruction executed
sleep_cpu ();              // sleep within 3 clock cycles of above
sleep_disable();

//  UCSR0B |= bit (RXEN0);  // enable receiver
//  UCSR0B |= bit (TXEN0);  // enable transmitter
//pinMode(9,OUTPUT);
//digitalWrite(9,HIGH);
//delay(100);
//pinMode(9,INPUT_PULLUP);
Serial.begin(38400,SERIAL_8N1);
delay(1000);
Serial.println("- Good Morning");

*do Stuff*

You can see in comments all the different things I tried:

Using Serial.end() and then, after waking up, Serial.begin()
Using the UCSR0B register
Using digitalWrite to set the pin to LOW and then, after waking up, either setting it to high, or setting it as input

All of the above combinations have the common problem that the cpu hangs after waking up, and the Serial is never restarted to print good morning message, neither does the program continue to execute further down.

Perhaps your terminal must be resetted as you have closed the serial connection. From my experience: Simply calling Serial.begin() does not trigger the Serial Terminal to reconnect again. I'm not sure, but the Serial.println might block then and that would be the reason your program won't be executed any further. Again; these are just guesses, but worth a try. ;-) Did the sleep mode work without the Serial shutdown? Can you try "the further processing" with out any println to see if the prints block or not? Can you recognize "further processing" without print statements?

Just a hint how to mark tried alternatives, which is easier to grasp and maintain than commenting each line: Use conditional compilation by #if 0 // try 1 ... #elif 1 // try 2 ... #endif.

Try adding delay(1000); after * do Stuff*. My guess is that there is still data being send over the serial connection when the MCU is put to sleep; leading to weird issues.

Thanks for the sugggestions. I tried those, before the solution came to me, which I posted below. Just one suggestion about @Gerben 's comment: It is indeed common to still have data before going to sleep, but the best way I found to deal with such issues is by using Serial.flush(). Of course, both would work fine

After trying many different alternatives, it turns out that my mistake was that, foolishly, I had included Serial printing inside my ISR routines, which where accessed when my interrupt fired, in order to wake my uP. As a result, Serial.print was called, with Serial being closed (before issuing the Serial.begin command to restart it), thus breaking my uP.
Extra: Just wanted to comment about using Serial.print inside ISRs. Although it can lead to unexpected problems like this one, or timing issues (ISR would take too long to execute) and is definitely a bad practice, it can sometimes be useful for debug purposes during development to print some kind of message there.
Printing a message takes long, and the ISR will return before the message is completely transmitted, with the potential to cause a lot of headache. Also, interrupts are disabled inside ISRs, so delay() is not working to do some kind of flow control. The best way to print messages in ISRs that I have come across so far, is by using Serial.flush() before exiting the ISR, making sure the message is completely transmitted.

You should keep the ISR as short as possible, just to set the flag or something. It never a good idea to use I/O access (such as Serial.print() within an ISR routine, even for debugging purpose, do it outside of the ISR based on the flag set by ISR.

I would suggest you read Nick Gammon's Interrupt.

Thanks for the suggestion, I have already read it, a great tutorial indeed. And yes, keeping only flags inside ISRs is definitely the best practice.


text:
Use JYETech 2.4 Inch LCD Display Screen Module with Arduino?
I have this JYETech 2.4 Inch LCD Display Screen Module that I would like to use for a project I have in mind, however, I'm not sure how to wire it up with my Arudino Mega. Here is the datasheet for the display. I have also attached a picture of the display below. The display is meant to work with a DIY oscilloscope but according to the manufacturer and other forum posts, it can be used as a display with other projects as well.
Pictures of the display

That display is an ILI9341 based one. On the DSO138 it connects the data pins D0-D7 to PORTB of the STM32.
You need to connect those 8 pins to 8 pins on the Arduino, along with the RS (Register Select) and CS (Chip Select) pins. The RD pin can be connected to 3.3V and the WR pin to GND, since you only really want to write to the screen (if you do want to read from the screen then you will want to connect RD and WR to two IO pins as well). Reset can be connected to a GPIO or to 3.3V, depending on if you want to do a hard reset at any point or not.
LED-A can connect to 5V, and each of the LED-K* pins should connect to ground through a resistor each. The size of the resistor will set the backlight brightness (try 100Ω to start with).
Then it's just a matter of finding a library that works with the ILI9341 in 8-bit parallel mode (u8glib maybe? I don't know, I never use Arduino to drive a TFT).
Note that since this is a 3.3V device you should really use a level shifter for all the digital signals.

the ILI9341 has a serial interface available


text:
How to detect button presses with a 74HC595 shift register?
Is there a way I can have my arduino uno differentiate between pushbuttons that are wired through a shift register and detect when each are pressed or not? I found this tutorial for the 74HC165 but I'm not sure it's applicable to the 74HC595.

The 74HC595 is a deserializer while the 74HC165 is a serializer. This means the former consumes a serial datastream and provides all data bits in parallel on dedicated data lines. While the latter consumes parallel data and converts it to a serial datastream.
To scan buttons you want to have parallel input data, where each switch is attached to a single data line. Then you serialize the data to reduce the amount of required Arduino inputs. This method is well explained in the mentioned tutorial.
As the 74HC595 is a deserializer it is not really applicable here. Instead you could use it to drive multiple outputs through a serial interface (see https://www.arduino.cc/en/tutorial/ShiftOut as an example).

Well, it's not completely true about it's not applicable. It can be used as outputs for scanning buttons. However it has some pitfalls


text:
SIM7600 MQTT CONNECTION TO shiftr.io broker
I am trying to use SIM7600 MQTT command to publish and subscribe to shiftr.io broker.
I have not been able to get pass stage of connecting to broker.
I use this
AT+CMQTTCONNECT=0,"tcp://instance.cloud.io:1883",90,1,"username","token"
I get this error code.
+CMQTTCONNECT:  0, 25
Of which code 25 indicate DNS error

I doubt that username is actually a valid user name ... same with token

You answered your own question with "DNS error".
The domain name that you're using, instance.cloud.io, is currently not valid. You can verify this quite simply by searching the web for any web site that looks up domain names for you and searching for that domain name.
In this case, "instance" is most likely a placeholder for the correct name. You need to go back to whatever tutorial or instructions you were following for this and use the correct name for this to work.

The "instance " is the name i gave. I used the same pattern to pub/sub using SIM800L. But not witj SIM7600. So i am sure the issue is with understanding MQTT stack in SIM7600.


text:
In Nrf24lO1 pa+Lna,is there any indication led light?
How do I know that my **Nrf24lO1 pa+Lna **  is working or not? For that any separate led is there for on ?

There is no led.
But you can use the isChipConnected function in the RF24 library


text:
Why is this Code not working with Esp8266 when it worked perfectly with Arduino Uno?
I'm making an attendance System using an RFID scanner, scanning RFID Card & saving Data in Excel.
When I used this code with Arduino Uno (by changing #define SS_PIN 12 and#define RST_PIN 9) it worked perfectly fine.
However, when I used the same code (by changing #define SS_PIN 15 and #define RST_PIN 5) the RFID is unable to scan any of the RFID Cards.
PIN CONNECTION Of ESP8266 & MFRC522
SDA to D8
SCK to D5
MOSI to D7
MISO to D6
GND to GND
RST to D1
3.3V to 3V3
#include <ESP8266WiFi.h>     //Include Esp library
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>        //include RFID library

#define SS_PIN 15 //RX slave select
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

byte card_ID[4]; //card UID size 4byte
byte Name1[4]={0x36,0x69,0x25,0xD9};//first UID card 36 69 25 D9
byte Name2[4]={0xA7,0xB5,0x33,0x04};//second UID card A7 B5 33 04

int NumbCard[2];//the number of cards. in my case i have just two cards.
int j=0;
int statu[2];//the number of cards. in my case i have just two cards.
int s=0;

int const RedLed=6;
int const GreenLed=5;
int const Buzzer=8;

String Log;
String Name;//user name
long Number;//user number
int n ;//The number of card you want to detect (optional)

void setup() {

  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card

  Serial.println("CLEARSHEET");                 // clears starting at row 1
  Serial.println("LABEL,Date,Name,Number,Time IN,Time OUT");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53)

  pinMode(RedLed,OUTPUT);
  pinMode(GreenLed,OUTPUT);
  pinMode(Buzzer,OUTPUT);

  delay(200);
   }

void loop() {
  //look for new card
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
  return;//got to start of loop if there is no card present
 }
 // Select one of the cards
 if ( ! mfrc522.PICC_ReadCardSerial()) {
  return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
 }

 for (byte i = 0; i < mfrc522.uid.size; i++) {
     card_ID[i]=mfrc522.uid.uidByte[i];

       if(card_ID[i]==Name1[i]){
       Name="First Employee";//user name
       Number=123456;//user number
       j=0;
       s=0;
      }
      else if(card_ID[i]==Name2[i]){
       Name="Second Employee";//user name
       Number=789101;//user number
       j=1;
       s=1;
      }
      else{
          digitalWrite(GreenLed,LOW);
          digitalWrite(RedLed,HIGH);
          goto cont;//go directly to line 71
     }
}
      if(NumbCard[j] == 1 && statu[s] == 0){
      statu[s]=1;
      Serial.print("DATA,DATE," + Name);//send the Name to excel
      Serial.print(",");
      Serial.print(Number); //send the Number to excel
      Serial.print(",");
      Serial.print("");
      Serial.print(",");
      Serial.println("TIME");

      }
      else if(NumbCard[j] == 0){
      NumbCard[j] = 1;
      n++;
      Serial.print("DATA,DATE," + Name);//send the Name to excel
      Serial.print(",");
      Serial.print(Number); //send the Number to excel
      Serial.print(",");
      Serial.print("TIME");
      Serial.print(",");
      Serial.println("");
      digitalWrite(GreenLed,HIGH);
      digitalWrite(RedLed,LOW);
      digitalWrite(Buzzer,HIGH);
      delay(30);
      digitalWrite(Buzzer,LOW);
      }
      else if(statu[s] == 1){
     //Turn Red LED when the employee Already Left
     digitalWrite(RedLed,HIGH);
      }
      delay(1000);
cont:
delay(2000);
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,LOW);

//if you want to close the Excel when all card had detected and save Excel file in Names Folder. in my case i have just 2 card (optional)
/*if(n==2){
    Serial.println("SAVEWORKBOOKAS,Names/WorkNames");
    Serial.println("FORCEEXCELQUIT");
    }*/
}

What voltage do the SPI lines expect/require? The Arduino Uno signals with 5V, while the ESP8266 signals with 3.3V.
Also, you may check if the MFRC522.h library supports the ESP8266 (or if it's using low level atmega code)

pinMode(RedLed,OUTPUT); ... RedLed is GPIO 6 ... GPIO 6 is SDCLK - the clock for the flash ram ... using GPIO 6 like that will cause your code to fail - similarly, using GPIO 8 ... SD_DATA1 ... will also cause failure ...you're also using GPIO 5 as reset AND buzzer

sorry, not flash ram - flash memory :p i.e. GPIO 6 and 8 (and 7, 9, 10, 11) are instrumental in being able to read the flash memory that contains your code .... and are not even broken out on the bulk of ESP8266 modules on the market - the nodemcu being the exception of course, because, well, it's nodemcu and they do things differently - but GPIO6-11 should NEVER be used by your code ... Though 9 and 10 can be, if you know what you are doing

you mix Dx labels and io pin numbering, so it is hard to know what is where wired. esp8266 doesn't use Dx constants only some boards use it to match the labels

@Juraj, actually, its code only uses gpio numbers

second time you've asked the same question and ignored comments @Ashish - do you need to take a tour of the site to understand how it works?

Sorry for reposting the question @JaromandaX but i havent got any solution

your comments didnt sloved my problem yet @Juraj

did you connect a LED to D6? then use int const RedLed=D6;, D6 is io 12 and io 6 is a different pin wired on-board to the flash memory. https://electronics.stackexchange.com/questions/402066/esp8266-free-gpios-for-relay-switching/404845#404845

@Ashish - the problem is, you're using GPIO pins in your sketch that you shouldn't be using


text:
What should I use Arduino-Mega or Rasbeery pi?
I am doing a project on Vehicle tracking and security. In my project Micro controller will sense input from sensors and at the same time it has to sense signal from user for tracking purpose and continuously checking the speed limit and boundary. so, there will be 3-4 tasks that would be executing parallel. Can anyone suggest which one is perfect for this kind of project... Arduino-Mega or Rasberry Pi?

there are many other options.

beery pi are more fun

What are the readout from sensors? If any of them is video, go for PI.

A RaspberryPi is essentially a small, low-spec computer. It is mostly an overkill for many small projects. Imagine using a super high-spec computer to play Minecraft. It's just nonsensical.
I'm assuming you'll be connecting to the car battery? Take note of the power requirements of your project. The RaspberryPi has a power requirement of 2.1A at 5V (which is a lot!), whilst an Arduino has a minimum requirement of 250mA.
Also remember: the RaspberryPi is running an operating system in the background in order to run your code. It will be working on numerous other operations and programs, not just yours. The Arduino will only run your program.
I had a similar project to what it sounds like you're doing. I used an Arduino Mega and had Bluetooth, GPS, and SD card all connected to it. The project worked absolutely fine, and I had lots of spare program space left over should I wish to expand on it. For reference, feel free to explore.

Thank you for your kind reply and suggestion. Your are absolutely right about the power requirements but the thing that I am concerned about is that can Arduino run parallel tasks like I mention there's been a request for a location at the same time sensing data from vibration sensor and check for specified boundary or speed...... so can arduino handle all tasks at same time?

In short, multithreading is not support on the Arduino. There are libraries that can supposedly do it, but all they do is slow down the program. Arduinos work synchronously (lines of code are executed one after the other, never simultaneously), so you would have to design your program to run synchronously.

you could use a dual-core ESP32 to do 2 things at once, and the ESP does them WAY WAY faster than a mega, which cuts down on opportunities for conflict. it's also cheaper and smaller.

so you mean ESP32 can run tasks(more than 2) simultaneously ?


text:
to measure the time between the ON signal and OFF signal
int pin_state = LOW;
struct Channel {
    byte pin;
    byte state;
    byte count;
    unsigned long fell, rose;
};

const int CHANNEL_COUNT = 3;
Channel channels[CHANNEL_COUNT] = {
    { 2, LOW, 0, 0 },
    { 3, LOW, 0, 0 },
    //{ 4, LOW, 0, 0 },
    //{ 5, LOW, 0, 0 },
    //{ 6, LOW, 0, 0 }
};

void setup()
{
    for (int i = 2; i <= CHANNEL_COUNT; ++i) {
        pinMode(channels[i].pin, INPUT);
    }
    Serial.begin(9600);
    //Serial.println("pin,fell,rose,low time");
    Serial.println("Minutes, Seconds, Count");
}

void loop()
{
    for (int i = 0; i < CHANNEL_COUNT; ++i)
    {
        Channel &c = channels[i];
        byte new_state = digitalRead(c.pin);
        if (c.state == LOW && new_state == HIGH)
        {
            c.rose = millis();
            c.count = c.count + 1;
        }
        else if (c.state == HIGH && new_state == LOW)
        {
            c.fell = millis();
            display_channel(c);
        }
        c.state = new_state;
    }
}

void display_channel(const Channel &c)
{
  int minutes, seconds;
  unsigned long difference;
  difference = c.fell - c.rose;
  seconds = int(difference/1000);
  if (seconds >= 60)
  {
       minutes = seconds / 60;
       seconds = seconds % 60;
  }
    //Serial.print(difference/1000);
    //Serial.print(",");
    Serial.print(minutes);
    Serial.print(",");
    Serial.print(seconds/1000);
    Serial.print(",");
    Serial.println(c.count-1);
    //Serial.print(",");
  }

When I try to run the program, I don't get any output.
Is there anything wrong with the code, that must be solved before any output can get displayed?

Hint: Might want to check how you handle channel vector index, pin initialization, etc. There are many trivial mistakes in the sketch.

Could you provide a better solution code for the mistakes as i cant find any.

Check the answer provided below by Majenko. He understood the hints :).

Here's the catalog of errors I see at first glance:
const int CHANNEL_COUNT = 3;
Channel channels[CHANNEL_COUNT] = {
    { 2, LOW, 0, 0 },
    { 3, LOW, 0, 0 },
    //{ 4, LOW, 0, 0 },
    //{ 5, LOW, 0, 0 },
    //{ 6, LOW, 0, 0 }
};

You set up space for 3 entries but only fill 2.  Also, the Channel structure has 5 entries, not 4. You don't initialize the 5th (rose) entry (although it will be initialized to 0 for you - best to be explicit though).

for (int i = 2; i <= CHANNEL_COUNT; ++i) {
    pinMode(channels[i].pin, INPUT);
}

You start from entry number 2 (the third entry) and iterate to the 4th (non-existent) entry to set the pin mode of either undefined or invalid pins.

for (int i = 0; i < CHANNEL_COUNT; ++i)

You have only filled in 2 of the three entries. Yet you use the third as if it were filled in.

Serial.print(minutes);

If seconds is less than 60 then minutes is undefined here.

I would suggest changing your code so that Channel is a class and embed the code to manage that class within it.

Bonus Time

Here's your program re-written using a class. As an added bonus I have added automatic allocation of a channel number to each object as it's created.  To add more channels just add the pin number into the initialization list.
class Channel {
    private:
        uint8_t _pin;
        uint8_t _state;
        uint32_t _rise;
        uint32_t _fall;
        uint8_t _count;
        uint8_t _channel;

        static uint8_t channelCount;

        void display() {
            uint32_t diff = (_fall - _rise) / 1000;
            uint32_t secs = diff % 60;
            uint32_t mins = diff / 60;
            Serial.print(_channel);
            Serial.print(",");
            Serial.print(mins);
            Serial.print(",");
            Serial.print(secs);
            Serial.print(",");
            Serial.println(_count);
        }

    public:
        Channel(int pin) : _pin(pin), _count(0) {
            _pin = pin;
            _count = 0;
            _channel = channelCount;
            channelCount++;
        }
        void process() {
            int s = digitalRead(_pin);
            if (s != _state) {
                _state = s;
                if (s == LOW) { // Fell
                    _fall = millis();
                    _count++;
                    display();
                } else {
                    _rise = millis();
                }
            }
        }
        void begin() {
            pinMode(_pin, INPUT);
        }
};

uint8_t Channel::channelCount = 0;

Channel channels[] = { 2, 3 };
#define NUM_CHANNELS (sizeof(channels) / sizeof(channels[0]))

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

    Serial.println("Channel,Minutes,Seconds,Count");

    for (unsigned int i = 0; i < NUM_CHANNELS; i++) {
        channels[i].begin();
    }
}

void loop() {
    for (unsigned int i = 0; i < NUM_CHANNELS; i++) {
        channels[i].process();
    }
}

Is class in arduino same as it is in python, as im just starting with arduino. Modified code would be helpful in that case :)

The concept of a class is the same, yes (it's a standard Object Oriented Programming term), but the way of working with them and the syntax is different. You should check some of the many many libraries around - they almost all use classes.

@RajeshAnand10 I have rewritten your program using a class.  There's no comments. It's up to you to pull it apart and work out what it's doing and how it's doing it.

But this doesn't seem like two pins can process the same "void process()" when two inputs come in simultaneously right?

Each pin has its own void process(), and there is no such thing as simultaneously.

Here the count keeps incrementing when the pin is low, but I need the count only when the pin gets low. I mean the count is effectively the number of times when the pin gets low and not how long the pin is low. How do I change to that condition accordingly as I can't even use break command since it's not in the loop structure?


text:
Arduino esp8266 interferes with analog sensors
UPDATE: I tried CNY70 sensor and the same error is valid for it too. Even outputs of CNY70 and LDR is the same while ESP8266 plugged in. I think ESP8266 interferes with all analog sensors
I connected my esp8266 and ldr sensor to my seeediuno (clon of arduino by seeedstudio) and ldr returns values like 70 110 105 120 etc. When I directly pointed light to ldr, return values don't change, value scatter randomly between 50-130. When I disconnect esp8266 and switch to arduino diecimila from ardunio ide, ldr sensor works fine. I think esp8266 somehow interferes with ldr sensor. How can I fix this problem?
#include "ESP8266WiFi.h"
#include "ESP8266HTTPClient.h"
[![#define SSID "myssşd"
#define PASS "mypass"
#define BID 000001

const char *host = "api.host.com";

void setup() {
  //start serial connection
  Serial.begin(115200);
  //configure pin 2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
  pinMode(A0, INPUT);

  WiFi.begin(SSID, PASS);

  while(WiFi.status() != WL_CONNECTED){
    delay(1000);
    Serial.println("Connecting...");
  }
  //If connection successful show IP address in serial monitor
  Serial.print("Connected to ");
  Serial.println(SSID);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP
}

void loop() {
  //read the pushbutton value into a variable
  int sensorValMeal = analogRead(A0);
  Serial.println(sensorValMeal);
  delay(1000);
}

This is how my serial prints looks like. You can see the anomally, I added my events as well.
Connecting...
Connecting...
Connecting...
Connecting...
Connected to Anaconda
IP address: 192.168.1.21
42 <- This is start
41
41
41
41
41
41
41
40
40
151 <- I turned my phones light to ldr
78
85
84
89
92
69
97
99
100
96
104 <- I switched of my phone's light
63
103
103
108
108
109
109
114
111
112
111
103
112
113
114
112
116
104
116
116
101
117
118
118
108
122
80
109
118
123
124
125
124
114
127
127
127
98
126
127
124
114
125
127
125
124
127
98
127
126
104
127
127
126
118
128
127
92
123
126
127
128
127
111
130

esp8266 takes power from 3.3 V pin?

the current draw of esp8266 causes voltage drops

You aren't using the Seeduino Arduino clone. You're using (as in writing software for, and programming) the ESP8266.  Every instruction you write affects only the ESP8266. The Arduino is nothing more than a power supply (and maybe a USB to Serial adaptor if you use it as such).
To access the analog pins on the Arduino you will need to:

Design a communication protocol between the two boards
Implement that communication protocol for both boards
Program both boards with their own unique sketches that use the protocol to communicate between them.

The Arduino will gather the data using its sketch, then send the results to the ESP8266 for sending through the internet.
Alternatively put the standard AT firmware on the ESP8266 and use that as the protocol above - then you only have to implement it on the Arduino.

You read the analog pin of the esp8266, not the analog pin of the Seeeduino.

you have two MCU. you need two sketches


text:
D1 Mini latch button using rst pin
I'm trying to use a Wemos D1 mini as a smart button that will boot up, perform a task, and then shut back down. I'd like to do this as a true power off as opposed to any sort of sleep mode.
I'm hoping I can do something similar to this post https://www.esp8266.com/viewtopic.php?f=11&t=4458

Tie RST pin to a Low GPIO pin so that it doesn't boot
Push a button that will run 3.3v to RST pin to make it go high and cause a boot up
Flip the GPIO pin that is tied to RST to high so that it stays running when button is no longer pressed
Run some code and flip GPIO back to LOW shutting down

Things I've tried:

Tie to GPIO15 (D8) - This stops the boot and starts booting when button is pressed but never finishes booting up. I'm assuming I am causing D8 to go high by pressing my button and interfering with the boot, but honestly not sure
Tie to GPIO4 or 5 (D2, D1). This doesn't prevent boot.
I've also tried #2 with a pull down resistor on the GPIO pin, but that doesn't seem to work either

Any help would be much appreciated.

reset button is HIGH and connecting it to ground executes reset

how do you plan to turn off the USB chip on Wemos D1?

To do this you would usually use MOSFETs to control the power.
Take the following circuit, for example:

simulate this circuit – Schematic created using CircuitLab
M1 is normally off, having its gate pulled up by R1.
Pressing SW1 pulls the gate of M1 low, allowing current to flow through it to power the D1.
The D1 boots up, and immediately drives the GPIO high.
This then turns on M2 (which is normally off, having the gate pulled down by R2), which in turn pulls the gate of M1 low.
SW1 can now be released since M2 is doing the same job.
To turn off, simply drive the GPIO low, or allow it to float as an input, in which case R2 will turn off M2, which then turns off M1, which stops the current flowing.

Try using D8, also follow this for selecting your pins to make sure the code runs as it is attended to work

D8 (io 15) must be LOW at boot

Would a diode between my button and D8 maybe fix the problem with it getting pushed high?

as far as I know, it's not possible [the way as simple as you said]. here's some notes :

after a reset, GPIOs are set as inputs. if you connect a GPIO to RST and make it low, it resets the chip, but immediately sets the GPIOs as inputs and the RST is released.
if you don't use appropriate resistors, you'll burn the GPIO driver by connecting an output GPIO to a supply line. e.g. when you are trying to connect 3.3v to RST and LOW GPIO which is holding RST down.
sleep modes are very efficient. many times, the battery self discharge is much higher than an slept MCU
if you insist, turn the chip off by cutting off it's supply using an external circuitry. a 555 with a mosfet without any res,cap will do the jb (using only it's internal flip flop)

reset pin has a pull-up so a pin in input mode will nott pull it LOW

@Juraj that's exactly what I assumed. he wanted a GPIO to keep reset LOW. but I said it's not possible because as soon as chip resets, the GPIO is input and the reset is released. it boots up

sorry, yes, you are right


text:
How to extend gsm buffer?
Haii All,
I am using gsm SIM900A module with arduino uno. I am trying to send some data from that to server. When i am writing some commands for that, let's say i have written 3 commands before. But when i am adding one more command, it is giving me error. It seems like there's a buffer issue i.e, maybe it is getting full. So it is nto taking extra commands written on sim900A. How to solve this problem? If it a buffer issue then how should i solve it?
Thanks in advance.

you have not described the problem .... you only described what causes the problem

What error do you get? Do you receive an error code from the SIM900A? Or do you have some compiler error? You have to include the full error message and what triggered it into your question

I got the solution. My SIM900A buffer was getting full. I had to clear it after one complete cycle so that when next time loop will get started, the buffer will be empty to store new data. Thanks for your time. Thank you everyone.


text:
Are there any alternatives to Tinkercad Circuits that is PC application based instead of web app based?
I have been using Tinkercad's Circuits web application to create my Arduino circuits and apply my Arduino code (c++) for testing.
Despite the amazing product they have and the fact it's free, I find myself very disappointed at times.  Don't get me wrong, Tinkercad has a bunch of great products that I use all the time (like "3d Designs").  I just feel like "Circuits" needs work or maybe even a different dirrection.
I have been dealing with some of the following issues...

An extremely slow interface creating my circuit:
I have seen it do a bunch of random things that could use some TLC in the interface.  Sometimes objects get stuck and you have to disconnect them from everything before you can move them.  Sometimes using a breadboard, objects that seem connected to a pinhole does not make a connection and need to be connected to the breadboard using a wire.  There are a bunch of little quarks I see.  None are a show stopper and I can work around them but the slow interface makes me hate dealing with a web app.  It makes me really want a PC app instead.
The lack of support updating the Arduino compiler:
It's a very old version and they are not in a hurry to upgrade it.  I have contacted support a bunch about issues with the compiler not compiling code that works perfectly fine in the Arduino IDE.  Classes need to be defined in a specific way, enums need to be defined in an old way that makes the source look ugly etc.  Also, I have let them know when debugging it's about impossible to find out where your bug is because it does not tell you a line number it had a problem on.  It tries to highlight the line with little success in my tests.  I have suggested to them that maybe they could introduce a new option to choose the compiler version to use for each project this way old designs do not break etc.  I didn't get any feedback on the feedback I submitted.  So I guess that is a no go.
The simulation time:
This is the worst offender by far!  This is the main reason I want to look for different software to replace Tinkercad Circuits.  When simulating code on my circuit design the simulation runs in milliseconds (NOT real-time).  I have my code set to do something in 15 seconds.  Seems like it will happen in no time...  NOPE!  I have to wait about 15 minutes to see the results!!

So back to my original question...  Is there a PC application out there that does the same thing as Tinkercad Circuits?  I want to be able to design an Andrino circuit and then test code with it.

I've not had the same issues, but i haven't used it as much as it sounds like you have. Emulation will always be relatively slow, so make sure you're using as beefy a computer as possible (no tablets/laptops) to run it. Emulation will also slow as the code size increases, perhaps even exponentially. I have seen it get better since launch, so give it time. Meanwhile, I would try to isolate and test smaller pieces, mocking up the "non-moving parts" to avoid overhead. I've not seen anything better...

Don't use simulation. Use a real Arduino and the IDE. Simulation often gets it wrong and you find that things that "worked" in the simulation don't in real life. Skip simulation altogether and save yourself the headache of things not working later.

@Majenko that should almost be an answer...  I totally agree!  After some testing yesterday on some source code, Tinkercad would run something just as I expected and when it was flashed to my ATtiny85 it was like NOPE!  bool resetButtonIsPressed = (digitalRead(PB_BUTTON) == HIGH ? true : false); works fine in c++ (also TinkerCad).  But the only way to get it to work on the ATtiny85 is to use bool resetButtonIsPressed; if (digitalRead(PB_BUTTON) == LOW) { resetButtonIsPressed = false; } else { resetButtonIsPressed = true; }.

I work with the wokwi Arduino simulator

It is faster
It uses the latest Arduino IDE for compilation
It almost runs in real-time. For example, your job of 15 seconds might get executed at about the 17th or 20th second.

Please give it a try. here are some references

Links: https://wokwi.com and https://wokwi.com/arduino/libraries

Thanks for the suggestion!

I'll try to find such PC app, but I can't find anyone. When I give up to find such app, I wrote my own arduino emulator via qt. My app is include arduino app and compile them as part of the qt app. Thank's to #ifdef macros i'm change the arduino.h . My emulator is not let you add scheme elements, but add you advantage to watch pin states and sets values to them. You can correct your project and emulate your own functions and algorithms. There it is https://github.com/ravenclawprog/arduino_mobil


text:
char buffer to String in Arduino UNO
String getAPIData()
{
  char res_buffer[450];
  int numdata = inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", res_buffer, 450);
  String result = String(res_buffer);
  Serial.println(result);
  Serial.println(numdata);
  return result;
}

Output on Serial:
15:52:07.208 ->
15:52:07.208 -> 393

But, When I print the buffer by loop I got the below output:
HTTP/1.1 200 OK
Date: Mon, 16 Sep 2019 06:28:59 GMT
Server: Apache
X-Powered-By: PHP/7.2.20
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=5b21eeac22dcf61f2e4d2efd579d437c; path=/
Upgrade: h2,h2c
Connection: Upgrade, close
Vary: Accept-Encoding,User-Agent
Content-Type: text/html; charset=UTF-8

-1

I am not sure why the char buffer is not converting to String in Arduino UNO.
Any known issues ? Please suggest if any correction required.

Don't use String. It's not fit for purpose. There is no cause to ever use String.

Chances are you are running out or memory and the String allocation doesn't happen. You need 450 bytes for your buffer, 450 bytes for the String you are using, and another 450 bytes for the String you are returning. That's 1350 bytes out of a maximum 2048 just for that function.

Do not use String. And especially do not use String in the way you are using it.
You can read more about why not here.
Instead stick to just using char* buffers.
The correct way of doing what you want is to define the buffer outside your function and then pass that buffer to the function to be populated:
int getAPIData(char *buf, int maxlen) {
  return inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", buf, maxlen);
}

Then you call it with:
char *my_buffer[450];
getAPIData(my_buffer, 450);
Serial.println(my_buffer);


text:
Push Button to Drive Power to Servo
I am currently doing a project for a class which uses a few other components such as an LCD, a servo, and such. I want to use a button which acts as a circuit breaker on the Vin of the servo in which the servo will only be powered when the switch is pressed. I wanted to implement something like this because I wanted to minimize the power consumption and also acts as a mechanical counter-measure in case the servo keeps on spinning in unwanted situations, such as having the servo entangled by hair or something like that.
I know that I can just connect the button to the I/O pins but I wanted to rely on a hardware solution for power minimization and safety reason.
The servo draws 170mA when idle and can draw a maximum of 1.2A, but I believe it will only draw about 500-600mA with the intended load. It can run between 4.8-6V.
So my question is, would my circuit configuration work for my application? Would it be safe? Do I need any other additional components? Thanks for anyone that can help!

There is a chance that this arrangement could damage the servo and possibly the Arduino.  The problem is that, depending on the internals of the servo, it could try and draw power for the servo through the data pin when the button is not pressed.  This would both over-stress the internals of the servo and the internals of the Arduino's GPIO pin.
What you could do to mitigate that is to connect the servo's switched power to another GPIO pin of the Arduino, which is set as INPUT.  That will then tell the Arduino when the button is pressed and when it's not pressed. Then you use that information to attach and detach the servo in your code so it is only being actively driven when the button is pressed.

Yes, that should be safe, as long as the button can conduct the needed current. That depends on the type of button. You can simply test this. If the button get's hot, it is too small for this.
If it should happen, that the button cannot conduct the needed current, you have 2 ways to go:

Just use a bigger button. You can buy buttons, that are meant for mains supply, which will be able to conduct way enough. Every button, that you buy (at least at electronics shops, maybe not on aliexpress or ebay), should have some kind of data sheet, which states the absolute maximums for the electrical characteristics. A maximum current can be found there.
You can use a MOSFET (that is capable of providing the needed current) and control it with your button. That would be the way to go, if you really need or want to use this specific button.


text:
Arduino code working via IDE, not via PlatformIO Arduino code
I have a working Arduino code. The code works as intended when I upload it to an Arduino Nano using the old bootloader via the Arduino IDE. However, when I upload the same code via PlatformIO, the code uploads successfully but does not work as intended. There are no errors or warnings during the upload process, and I am having trouble figuring out what could be causing the issue.
Now for troubleshooting I am using simple blink example.
#include <Arduino.h>
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

1st PlatformIO configuration .ini
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
debug_port = COM3
monitor_speed = 115200

I have also tried following but no luck.
2nd PlatformIO configuration .ini
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
board_oldbootloader = true
debug_port = COM3
monitor_speed = 115200

Any suggestions on how to debug this problem or what might be causing the issue? Thank you.

The blink function gets programmed by the IDE. In case I program with Arduino IDE the code gets uploaded to the board and works as intended (i.e. LED blinks). In case I program with PlatformIO the code gets uploaded to the board but doesn't work as intended (i.e. (The LED doesn't blink).

It's very weird. I have tried different solutions but nothing seems to work.

turn on the LED in setup ... leave loop() empty ... what happens?

print the value of LED_BUILTIN to serial monitor to see its value ... also, try referring to the LED pin by number

My apologies. Not familiar, 1st ever question.

Ok, a weird thing happened. :D

I did as you said. I left the loop empty and turned on led in the setup. Result: The LED stays off.
I uncommented the loop and uploaded again. The LED started blinking.
The problem resolved itself. Any idea what went right.

you never loaded the sketch the first time around

I had a similar behavior for a while and nothing I would change in the PlatformIO .ini configuration file seemed to help. I tried to re-init and clean the project, but also didn't seem to help.
Eventually, what worked for me was to start a new fresh PlatformIO project and migrate the files over.
I suspect that under certain conditions (that may be related to the project settings), PlatformIO fails to upload the script, yet it claims that the upload was successful.


text:
Connecting HM-10 and relay to Arduino Uno
I have an 8 channel relay, an Arduino Uno, and this HM-10 bluetooth module: https://www.amazon.com/dp/B06WGZB2N4
The Goal
Send a number (1-8) from my Android phone via bluetooth to turn a relay on.
The Problem
I can't seem to get the bluetooth to reply to anything I send. I'm trying to use "Arduino Bluetooth" from the app store to send commands, but it either errors or ignores me and doesn't do anything. I can't communicate with the bluetooth from the Arduino IDE either.
The wiring
I'm SUPER new to small electronics, I suspect I'm not giving the system enough power and might need to give my relay its own 5.5v supply, but here's what I've got:
HM-10    | Uno
-------------------
RX       | Digital 3
TX       | Digital 2
VCC      | 3.3V
GND      | GND

Uno      | Relay
-------------------
Digital 4       | IN8
Digital 5       | IN7
Digital 6       | IN6
Digital 7       | IN5
Digital 8       | IN4
Digital 9       | IN3
Digital 10      | IN2
Digital 11      | IN1
GND             | GND
5V              | VCC

The code:
#include <SoftwareSerial.h>

const int relayPins[] = {4, 5, 6, 7, 8, 9,10,11};
SoftwareSerial HM10(2, 3);

void setup() {
  Serial.begin(9600);
  HM10.begin(9600);
  for (int i = 0; i < sizeof(relayPins) / sizeof(relayPins[0]); i++) {
    pinMode(relayPins[i], OUTPUT);
    digitalWrite(relayPins[i], HIGH); // set relays to OFF
  }
}

void loop() {
  if (HM10.available() > 0) {
    int relayNum = HM10.read() - '0'; // convert ASCII to integer
    if (relayNum >= 1 && relayNum <= 11){
        digitalWrite(relayPins[relayNum - 1], LOW);
        Serial.print("Turned on relay ");
        Serial.println(relayNum);
        delay(1000); // wait for 1 second
        digitalWrite(relayPins[relayNum - 1], HIGH);
        Serial.print("Turned off relay ");
        Serial.println(relayNum);
    }
  }
}

add some debugging code


text:
Reverse engineering LIN bus on E-bike system
As a project I am trying to 'hack' an old E-bike.
The electronic system of the bike consists of:

A torque sensor measuring deformation of the rear.
A 'spin' sensor measuring if the person is pedeling.
A battery pack with BMS
A speed controller inside the hub motor.
A display to control speed, lights and display distance information etc.

From researching I concluded that the sensors, dislay and speed controller are communicating over LIN because they have a ATA6661 LIN transceiver and they are all connected parallel over the VS, LIN and GND wire.
When I power up the speed controller on its own I can see some LIN communication on my oscilloscope:

I do not have a LIN transceiver to log the data but I attached a USB-TTL transceiver to the uart-side of the LINtransceiver. From my oscilloscope a deduced that the baud rate was 9600. I used termite to listen on my serial port and set it to hex view. This is what I got:

I'm not sure if I should change the amount of bits or parity bits.
My goal is to understand the frames that are send and to deduce which frame holds which sensordata or results in a certain activity.
When I compare this to an CANbus project I was doing it was fairly easy to for example deduce which command was controlling my car's left window because with can-utils (candump) I could see every packet. I could filter unchanged packets and it colorcoded which bit(s) in each packet recently changed.
Any advice/ideas on how to do this for LINbus?

I know nothing about LIN, but the datasheet of the transceiver should tell you, how it communicates over Serial. Then you should be able to extract the LIN packages from the serial stream.

please post the captured serial communication as text, not as a picture

Where is the Arduino in this?

this may help you ... at 1:32  ... https://m.youtube.com/watch?feature=youtu.be&t=92&v=tu8Ow6fJm1g

@chrisl Well a transceiver is just like a translator, it translates uart into LIN and vice versa. I doesn't understand the conversation nor does it choose how fast the communication is (baudrate). Apart from that I did check the datasheet (http://www.farnell.com/datasheets/1678261.pdf). Thanks anyway for putting effort to helping me!

@jsotola Yes you are right, that would be more helpfull. I didn't succeed in termite logging the hex values of the traffic though (It always seems to log the ascii values) But I will copy it from to program tomorrow and change it here :)

@Majenko Indeed, I get that this is not yet an 'Arduino' project. My goal is to attach an Arduino in the end to send certain LIN commands to spoof my sensors.

@jsotola Yes thank you, I've seen the video. To bad I do not have acces to an oscilliscope with does LIN decoding. But its a good video to become aware of what mathers (LIN version, baudrate, ...)

my comment is about the signal trace on the oscilloscope screen, not about the oscilloscope itself

@SvenOnderbeke Mhh, from what I read just now, LIN is at least similar to UART with different voltage levels and a protocol imposed on the data stream. I would try to find individual packages in the data stream, that you captured. Looking at the captured data, the bytes 0xfdfe seem suspicious to me.

did you make any headway with this project? I know we are going back over a few years now. With the Go SwissDrive displays becoming scarce, I'm investigating reverse engineering the bikebus communications. I believe it has been done before, YouMo has taken over SwissDrive support and they advertise a transceiver box to interface with alternative bafang displays such as the SW-102 but they won't sell them.
I hoping to get some of the stream captured from a working bike.

As a starter point I would hookup your rigol ds1054z via usb to sigrok
https://sigrok.org/wiki/PulseView this will enable you to log dump and analyze your lin frames . It has a frame decoder for LIN protocol.
This should give you a great view of what is transiting over the lin bus and which slave PID to call .
From there you may use a macchina.cc  to comunicate over lin or use
https://github.com/macchina/LIN with a arduino due and a lin tranceiver.
Cheerz

Thanks Bernard! This seems like the exact kind of answer I was hoping for! I will go and try those out. Thanks for your help!

If you are using "go swissdrive" controller (I'm looking at the picture) the bikebus protocol (bulls green mover) was used and in later, linbus (e-technology, Alber etc.) Display is master, motor and bms as slave .. Good luck :)


text:
Maximizing SPI-speed between Arduino DUE and RA8875 display driver
For a project I would like to be able to control my RA8875 display driver as quick as possible using an Arduino due.
I started from the Adafruit library and replaces all  "digitalWrites" with direct port manipulation.
Apart from that I wanted to also use that maximum possible SPIspeed.
In the adafruit datasheet I didn't find any specification of the maximum SPIspeed of the controller. In an older datasheet I only found the max speed in relation to the system clock. But I have no idea what that is. .
After googling, the max spi speed of the RA8875 seems to be 12Mhz (source).
So I decided to just try different SPIspeeds. Though I do found the library's Adafruit_RA8875.cpp file a bit confusing since it defines uint32_t spi_speed multiple times based on the architecture.

Once starting at line 48
Once starting at line 134
Once starting at line 164

And the chosen speeds for each architecture are not consistent between those 3 assignments.
I decided to replace line 66:

SPI.beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE0));

with:

SPI.beginTransaction(SPISettings(12000000, MSBFIRST, SPI_MODE0));

and tried other speeds. But it always resulted in a black screen on my display.

To speed up the RA8875, you should start with small clock frequency to initialize the RA8875 including the pll configuration and then you can make the clock frequency faster. It works with me.


text:
Blew my Arduino. Did I wire this correctly?

Hi,
I am currently doing a project and it seems that I may have blown my Arduino Nano (or maybe not). The power LED of the Nano was still on and I believe the L pin blinks once every time I press the reset button.
I wanted to use 4AA alkaline batteries to power my project. The servo is a continuous servo rated for 4-6V and 15-200mA from Parallax. Given that the Nano runs optimally when powered at 7-12V, I decided to buy a step-up converter (adjustable output voltage). It looks like this although I bought it elsewhere:
https://www.ebay.com.au/i/283603471149?chn=ps&norover=1&mkevt=1&mkrid=705-139619-5960-0&mkcid=2&itemid=283603471149&targetid=752505019384&device=c&mktype=pla&googleloc=9071392&poi=&campaignid=1979582348&mkgroupid=72745766764&rlsatarget=pla-752505019384&abcId=1139426&merchantid=7364522&gclid=Cj0KCQjwt5zsBRD8ARIsAJfI4Bh8cSOKugFrugHz-gA-s8nXclnO7H8iQ-WX46FRdhDLchwbl6UyWLgaAr4oEALw_wcB
When I tried to test it with the servo running, my Nano stopped working after several seconds later. Did I wire them up wrongly? I also measured the output of the step-up converter when it was running with a voltmeter between the two terminals of the step-up's output. Would it be possible to short it that way?
Appreciate any help I can get. Thanks

It would be best if everything ran at the same voltage. (And it is necessary that everything uses the same ground.)  Which is possible as there are 5V Arduino boards.  Interestingly, the Arduino nano, according to this schematic, runs at 5V.
In order to use the Arduino Nano at 5V, instead of using VIN / Pin 1, you should be able to skip the Arduino's 5V regulator and use +5V / Pin 4.  But this must be a regulated 5V power source.
Now, why are you having problems controlling the servo?
It is difficult to tell, but your boost switching power supply negative input may not be directly connected to the negative output.  With out a common ground, it may be difficult to create the proper signal to control the servo.
To be specific, if the ground or negative side of the servo power supply is not at the same potential as the ground or negative side of the Arduino power supply, controlling the servo may be difficult at best and at worst you could burn something out on the servo or Arduino.
To check, measure with a volt meter to see if there is any difference between the boost switcher negative input and negative output.
To solve this problem consider using a USB power supply plugged into the Arduino Nano and powering the servo off the 5V at pin 4 of the Nano.  Or, keep using your 6V battery and 6V to 9V boost switching power supply.  Connect this as you are to VIN Pin 1.  The Arduino Nano's 5V power regulator should kick in and provide 5V at pin 4.

Hey thanks for answering!
I used the step-up converter in hopes that it could regulate a constant voltage around 7-12V and also avoid the Nano from resetting when the servo is powered. I didn't want to set the Vin at the lowest possible level to keep it from happening.
I don't have much problem with using the servo if the Arduino didn't blow up. Also, I recalled that the Arduino cant supply enough current to the servo.
The device will need to be portable as well. I think your explanation with the step-up converter may help. I will check on it when I can. Thanks a lot for the help!

I think your servo is small enough such that it can be powered through the Arduino's voltage regulator.  But you are correct to concern your self with the possibility of the servo pulling too much current and resetting the processor or, worse, burning out the Arduino's voltage regulator.  The most common problem I have seen in questions here is not having a common ground between the servo and the Arduino power supplies. If the above answer eventually works for you mark it as correct. If not, add to your question so that others may be able to provide better answers.

I had a friend to check it for me and he said that the grounds are connected appropriately. Still was not too sure why it blew up but appreciate the help. Got the arduino working now as well! cheers!


text:
Attiny85 Watchdog fires only once
I build something like a flashlamp with different modi. From the hardware site it's quite simmilar to the Nanjg105c.
There is a Attiny85 which generates a PWM signal to an AMC7135.
I have one push button, if I click it the Attiny go to sleep, if I hold the button the Attiny changes his mode.

For checking the battery voltage I use the watchdog timer to make the ADC conversion every 8sec.
    #include "OneButton.h"
#include <avr/sleep.h>               // Sleep Modes
#include <avr/power.h>              // Power management
#include <avr/wdt.h>              // Watchdog Timer
#include <util/delay.h>

#define mid 4000                // BAttery Level Mid
#define low 3200                // Battery Level low, flash and start dimming the Led
#define crit 2600               // Battery Level critical, shut down

const byte LEDr = 1;              // pin 1
const byte LEDw = 4;              // pin 4
const byte ModeNr = 3;
volatile bool WDR_flag = false;
bool PWR_flag = false;

OneButton button1(2, true);
int count = 1;
int flag = 0;
long Vcc;
int PWMr = 255;
int PWMw_l = 50;
int PWMw_h = 255;

ISR(PCINT0_vect)
{
    // do something interesting here
}

ISR(WDT_vect){
  WDR_flag=true;
 }

void setup()
{
    pinMode(3, OUTPUT);
    pinMode(LEDr, OUTPUT);            // turn the LED on (HIGH is the voltage level)
    pinMode(LEDw, OUTPUT);
    digitalWrite(LEDr, HIGH);           // turn the LED on (HIGH is the voltage level)
    digitalWrite(LEDw, HIGH);
    delay(1000);
    button1.attachClick(sleep);
    button1.attachLongPressStart(changeMode);
    WDT_on();
}

void loop()
{
  uint8_t i = 0;
    button1.tick();               // keep watching the push buttons:
  if(WDR_flag == true){           // do every 8s
    WDR_flag = false;           //reset WDT Flag
    digitalWrite(3, HIGH);      //debug with third LED
    delay(250);
    digitalWrite(3, LOW);
    WDT_off();
    //ADC_on();
    /*Vcc = readVcc();            //read Battery voltage
    if(Vcc < low && count == 3){
      if(PWMw_h <= PWMw_l){       //change Mode to low when PWM output is smaler then low PWM
        count = 2;
      }else
    {
    i = 0;
        while (i++<3 && PWR_flag == false) {         //flash 3 times the red LED befor dimm the white LED
          analogWrite(LEDr, PWMr);
          _delay_ms(500);
          digitalWrite(LEDr, LOW);
          _delay_ms(250);
      PWR_flag = true;
        }
      PWMw_h = PWMw_h / 2;        //halve the PWM output of the white LED
      }
      if(Vcc <= crit){          //go to sleep when Battery is empty
        sleep();
      }
    }
    if(Vcc < low && count == 1){
      i = 0;
      while (i++<3) {
        digitalWrite(LEDr, LOW);
        _delay_ms(250);
        analogWrite(LEDr, PWMr);
        _delay_ms(500);
        }
      PWMr = PWMr / 2;
      if(Vcc <= crit){
        sleep();
      }
    }*/
    //ADC_off();                //save power
    WDT_on;                 //start watchdog again

  }
  switch (count) {
    case 1:                 //Mode red LED
    analogWrite(LEDr, PWMr);
    digitalWrite(LEDw, LOW);
    break;
  case 2:                   //low Mode white LED
    digitalWrite(LEDr, LOW);
    analogWrite(LEDw, PWMw_l);
    break;
  case 3:                   //high Mode white LED
    digitalWrite(LEDr, LOW);
    analogWrite(LEDw, PWMw_h);
    break;
  }
}

void sleep()                  // This function will be called when the button1 was pressed 1 time
{
    digitalWrite(LEDr, LOW);
    digitalWrite(LEDw, LOW);
    //prepare sleep
    WDT_off();
    GIFR |= bit(PCIF);              // clear any outstanding interrupts
    GIMSK |= _BV(PCIE);             // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT2);             // Use PB2 as interrupt pin
    ADC_off();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();               // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                    // Enable interrupts
    sleep_cpu();                // sleep

    cli();                    // Disable interrupts
    PCMSK &= ~_BV(PCINT2);            // Turn off PB2 as interrupt pin
    sleep_disable();              // Clear SE bit
    WDT_on();

    flag = 1;                 //set flag, uc was in sleepmode before
}

void changeMode()               // This function will be called once, during pressed for a long time.
{
    if (flag == 1) {
        flag = 0;
    }
    else {
        if (count < ModeNr) {
            count++;
        }
        else {
            count = 1;
        }
    }
}

void WDT_on() {
  // Setup watchdog timer to only interrupt, not reset
  cli();                    // Disable interrupts
  wdt_reset();                // Reset the WDT
  WDTCR |= (1 << WDCE) | (1 << WDE);       // Start timed sequence
  WDTCR = (1 << WDIE) | (1 << WDP3) | (1<<WDP0);      // Watchdog cycle = 8 s
  //WDTCR = (1 << WDIE);             // Watchdog Interrupt enable
  sei();                    // Enable interrupts
}

void WDT_off(){
  cli();                    // Disable interrupts
  wdt_reset();                // Reset the WDT
  MCUSR &= ~(1<<WDRF);            // Clear Watchdog reset flag
  WDTCR |= (1<<WDCE) | (1<<WDE);        // Start timed sequence
  WDTCR = 0x00;               // Disable WDT
  sei();                    // Enable interrupts
}

void ADC_on() {
  ADCSRA = (1 << ADEN );            // ADC power on
}

void ADC_off() {
  ADCSRA &= ~(1<<7);              //ADC off
}

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference

  ADMUX = _BV(MUX3) | _BV(MUX2);
  delay(2);                  // Wait for Vref to settle
  ADCSRA |= _BV(ADSC);              // Start conversion
  while (bit_is_set(ADCSRA,ADSC));        // measuring

  uint8_t low_adc  = ADCL;              // must read ADCL first - it then locks ADCH
  uint8_t high_adc = ADCH;              // unlocks both

  long result = (high_adc<<8) | low_adc;

  result = 1126400L / result;           // Calculate Vcc (in mV); 1126400 = 1.1*1024*1000
  int x = 0;
  /*while (x++<2) {         //debug with third LED
          digitalWrite(3, HIGH);
          _delay_ms(500);
          digitalWrite(3, LOW);
          _delay_ms(250);
        } */
  return result;                // Vcc in millivolts
}

my problem is that the watchdog fires only once. after putting the attiny to sleep the watchdog fires also only once.
I think the problem is in the WDT_off() function...

The line below lacks parens () to make it a function call; as it stands, it's not actually calling WDT_on.
WDT_on;                 //start watchdog again

should be:
WDT_on();                 //start watchdog again


text:
mBlock update firmware
Total Arduino newbie here.
I was playing with mBlocks, with the Arduino Uno extension enabled. That extension offers you to "update firmware" which I accidentally did. What exactly is this firmware? Is it just a compiled sketch or does it alter stuff like bootloader or reside permanently in the memory?

Usually by Firmware we understand "a program that was prepared by company that produced the hardware and that is necessary for that hardware to work correctly". I suppose that developers of mBlock are smart enough not to allow people to "brick" their Arduino's. I suspect that ether you updated your bootloader (it's also a firmware) to latest version or simply nothing happened. In both cases your device should be operational. Burning a bootloader onto an Arduino is not as hard as it seems so even if you broke something you should be able to fix it.

Hm, I thought one couldn't modify the bootloader by just merely connecting it to the PC via a USB cable as you need a special programming device or additionally manipulate the onboard fuses for that? So, other than that, nothing could possibly have been modified, and the board can still be fully used in other projects?


text:
Arduino Nano burns with ESP-01 in parallel
So I have an Arduino Nano powered in parallel with an ESP-01 (for the ESP there is an extra LM1117-5.0 voltage regulator in series).
+12V ---------+---------+
              |         |
             Reg        |
              |        NANO
             ESP        |
              |         |
 GND ---------+---------+

My problem is that after a while, the Nano burns (my guess is the difference in current that both devices draw).
In any case, what could be the reason and what could I do to fix it?
Thanks!

how are you connecting the 12 V supply to the nano?

I´m using the Vin pin.

"for the ESP there is an extra LM1117-5.0 voltage regulator in series" ... shouldn't an ESP-01 get 3.3V?

please do not crosspost ... https://electronics.stackexchange.com/questions/461286/arduino-nano-burns-with-esp-01-in-parallel

Didn't know, deleted the duplicate one. Thanks.

Use the 5v regulator to power both the ESP and the Nano. Those onboard regulators have minimal heat dissipation and if they burn out you lose the whole Nano. Check how hot your external regulator gets and mount it on a heat sink if it gets too hot to touch.
NB Connect the regulator output to the Nano 5v pin directly

12V is the upper limit for input voltage on an Arduino. With a 12V input the regulator has to convert 12-5, or 7 volts, to heat. (That's how linear voltage regulators work.) As the other poster said, Arduinos don't have much heat dissipation on their voltage regulators.
Like jksemple, I would suggest powering both the ESP and the Nano from the external regulator (You might want to cut a USB cable and wire it to your external voltage regulator, then plug it into your Nano. That way you're not bypassing the power control circuits on the Nano.
By the way, did you build a full voltage regulator with the LM1117 chip? You need some extra components like capacitors and resistors to complete the voltage regulator.
Finally, you might think about using a DC-DC buck converter rather than a linear regulator. That will run a lot cooler and waste a lot less power.


text:
TFT menu system sometimes doesn't refresh the screen properly
I have a project in which I control a display using an Arduino Due microcontroller.
The user can navigate on the TFT display (RA8875 driver ic) with a rotary enconder/pushbutton.
The display shows a certain menu. You can the selected item in the menu by rotating the rotary encoder and you can move into a submenu by pressing the rotary encoder (because it is also a button).
This is how the menu looks like:

The problem is that sometimes when rotating the encoder the menu doesn't refresh the screen properly and seems to have gotten stuck while drawing the screen. Though when rotating the encoder some more the screen gets properly rendered so the code isn't actually 'stuck'.
This is een example of a bad rendering after rotating the encoder. (Sometimes no text gets written, sometimes some text gets written):

I also made a video to make my problem more clear:
Video with rendering problem.
The code for my menu is rather big so I'll try to explain the working principle and attach the used Arduino code.
I attached an interrupt to the encoder signal and to the push button.

attachInterrupt(digitalPinToInterrupt(BTN_ROT), push_button_interrupt, FALLING);
attachInterrupt(digitalPinToInterrupt(ROT_A), rotary_enc_int, LOW);

In the interrupt function I update a 'virtual position' value. In my main loop I run a function that checks if the virtual position is different from the last seen position and updates the 'current_index'-value of the menu accordingly. It also sets 'refresh_menu' to True.
In the main loop the variable 'refresh_menu' gets checked and if true the screen gets redrawn with the menu item selected according to the value 'current_index'.
Link to full project code: Arduino due code. All the relevant code for this problem is in 'Menus.h'.
[Side note] I am not sure if my approach to build a menu is 'good'. It's not super responsive and the code is hard to maintain (changing a menu-item from position requires a lote of changes in the code). Any advice in a better approach is appreciated!

the video shows serious signal bounce ... rotary_enc_int should be called on signal transition, not on signal level .... increase the time difference in the ISR to 50 ms from 5 ms ... i think that you accidentally forgot the zero

Hi @jsotola, thank you for looking into my code and giving feedback. When I started the project I tested every component seperatly. I also thought I should use FALLING or RISING instead of a signal level. But for some reason - I didn't and stil do not understand - it didn't work but it worked when using the LOW state as I had seen in a tutorial.
I tried your feedback and this is what I got (it didn't transition properly jumped back and forth)
video: https://drive.google.com/file/d/1ELb0AcuUl-Lxjt6BBYF45CzOaRhEknRN/view?usp=sharing
(both rising and falling worked like this).

menus.h, line 122, lastInterruptTime = interruptTime; .... this needs to be inside the if block     ..................... the if may work better as if (interruptTime - lastInterruptTime > 50)

Thank you @jsotola, you are right about the position of lin 122. Thank you for your help, I positioned it inside the if block. As from what I experience I do not have any debouncing issues but I changed the debounce time to 50 an it still worked as before but when rotating fast it didn't see as many rotations as before. So I did reset it to 5.

As for my problem: I didn't find the bug in my program but I tried another approach: instead of redrawing the screen for every change of my index (which requires some time to do) I threw away the color indication of my index and just prepended the selected index with '>'. I do not refresh the whole screen when the index changes but I draw a cube over the old '>' and draw the new one. This also elminated the refreshflickering involved with redrawing the screen.

there are menu libraries available for the arduino


text:
Getting atsam3x8e (Arduino Due) to work
I decided to make a pcb based on the atsam3x8e (microcontroller used in Arduino Due). For the design I copied most of the layout that I found on this site and looked at the official Arduino Due schematic as well but decided that I didn't need everything. This is the schematic that I made and the pcb:

The problem is that my laptop doesn't see the "Arduino Due / atsam" when I connect the USB to my pc with a USB cable (with data lines). I understood that the chip chips with the SAMBA bootloader in ROM and that it should be programmable via native usb connection to the chip.
I supply 3V3 with a bench power supply.
Then I tried to follow the checklist for this microcontroller: checklist.
All voltages seem to arrive on the chip. VDDout makes a 1.7 voltage as it should.
I have a clocksignal on my 12Mhz crystal. I don't have a clock signal on my 32khz crystal but when measuring on an official arduino due I also didn't see a clock signal here so I guess this oscillator isn't always on.
I made some wire patches: decoupling cap were not ground referenced and one oscillator pin of 12 Mhz wasn't connected.
Any ideas on how I could further debug this?

check for unwanted solder bridges ... you have what looks like stray bits of solder on the board

did you solve this issue? I'm having a similar issue with my atsam3x8e design where windows show it up in device manager as an "Unknown USB Device (device descriptor request failed) and I can't work out why it won't show up as a com port. I verified that the chip is up and running fine by programming it over the TX and RX pins with a USB to serial converter. This might be a good place for you to start debugging your design, although you will have to add a 2 pin header connected to the TX&RX pin to your design.


text:
How to make a custom character on a TFT LCD display? (128x128)
I'm currently using the ucglib library. I'm new to arduino and I'm wanting to simply display a lcd smiley I made with the byte generator. I still have some of the original 'font hello world' stuff down the bottom but I'm curious how to make my character work.
I want to make different smileys in different colours but I'm unsure how to go about this as every guide is on a 16x2 lcd and not a tft one. I have an arduino nano that is just hooked up to that lcd display. I'm going to make pressing buttons change the smiley after I've figured out how to actually put a smiley into it. Hope someone can help.
 * LED =   3.3V
 * SCK =   13
 * SDA =   11
 * A0 =    8
 * RESET = 9
 * CS =    10
 * GND =   GND
 * VCC =   5V

    #include "Ucglib.h"  // Include Ucglib library to drive the display

// Create display and define the pins:
Ucglib_ST7735_18x128x160_HWSPI ucg(8, 10, 9);

int smiley = byte customChar[] = {
  B00000,
  B01010,
  B01010,
  B00000,
  B10001,
  B10001,
  B11111,
  B00000
};

void setup(void)  // Start of setup
{

  //ucg.begin(UCG_FONT_MODE_TRANSPARENT);  // It doesn't overwrite background, so it's a mess for text that changes
  ucg.begin(UCG_FONT_MODE_SOLID);  // It writes a background for the text. This is the recommended option

  ucg.clearScreen();  // Clear the screen

  ucg.setRotate180();  // Put 90, 180 or 270, or comment to leave default

  ucg.setColor(0, 255, 255, 255);  // Set color (0,R,G,B)
  ucg.setColor(1, 0, 0, 0);  // Set color of text background (1,R,G,B)
  ucg.setPrintPos(0,24);  // Set position (x,y)
  ucg.print("Welcome");  // Print text or value

  // Draw smiley:
  ucg.setColor(0, 255, 255);  // Set color (0,R,G,B)
  ucg.drawFrame(0, 58, 60, 30);  // Start from top-left pixel (x,y,wigth,height)

void loop(void)  // Start of loop
{

  Variable1++;  // Increase variable by 1
  if(Variable1 > 150)  // If Variable1 is greater than 150
  {
    Variable1 = 0;  // Set Variable1 to 0
  }

  // Convert Variable1 into a string, so we can change the text alignment to the right:
  // It can be also used to add or remove decimal numbers.
  char string[10];  // Create a character array of 10 characters
  // Convert float to a string:
  dtostrf(Variable1, 3, 0, string);  // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)

  // We are going to print on the display everything that is dynamic on the loop, to refresh continuously:

  // Write to the display the Variable1 with left text alignment:
  ucg.setFont(ucg_font_inb16_mr);  // Set font
  ucg.setColor(0, 255, 255, 0);  // Set color (0,R,G,B)
  ucg.setColor(1, 0, 0, 0);  // Set color of text background (1,R,G,B)
  ucg.setPrintPos(9,81);  // Set position (x,y)
  ucg.print(Variable1);  // Print text or value

  // There is a problem when we go, for example, from 100 to 99 because it doesn't automatically write a background on
  // the last digit we are not longer refreshing. We need to check how many digits are and fill the space remaining.
  if(Variable1 < 10)  // If Variable1 is less than 10...
  {
    // Fill the other digit with background color:
    ucg.print(" ");
  }
  if(Variable1 < 100)  // If Variable1 is less than 100...
  {
    // Fill the other digit with background color:
    ucg.print(" ");
  }

  // Write to the display the string with right text alignment:
  ucg.setFont(ucg_font_inb16_mr);  // Set font
  ucg.setColor(0, 0, 255, 0);  // Set color (0,R,G,B)
  ucg.setColor(1, 0, 0, 0);  // Set color of text background (1,R,G,B)
  ucg.setPrintPos(76,81);  // Set position (x,y)
  ucg.print(string);  // Print text or value

}  // End of loop

Simple: you don't.
You only need to create a "custom character" on character-only displays (where you are actively programming a new character into the display's internal character set).
With a graphical display there is no "character" - only graphics.  The graphics library has fonts, which it then uses to convert text into graphics.
To display something that isn't in your currently selected font, just draw it. That could be from a bitmap graphic (there will be examples in your chosen graphics library) or using primitives, like circles and lines.

ah I see, my bad. I'll try my best to search up it then. I'm assuming I could just 'print' :) and it would display on the screen okay?

You could change the font that you are printing with. Make a custom font. No idea how you'd do that with your chosen library though. There may be examples and tutorials, or there may not...

I'm more than happy to use a different library, this one just seemed right on the mark for what I wanted. I think they have a whole list of fonts so I may just choose a pixel one and try my best from there. I know this is a different topic, but if my arduino is completely off a breadboard and linked up to the lcd, can I use a button on a breadboard and just put a wire to it or is it best to attach the arduino nano to the breadboard itself to make buttons work?

Makes no difference.

Thank you Majenko. If you're still here, on a 128 x 128 screen, which y and x axis would be the middle? I've tried a few but i think the text is still off screen? Having trouble with that

64x64 is the middle of a 128x128 screen.

oh it's half. Ha I must be an idiot. Thank you, you've made my night so much easier! I shall leave you be =). Thanks once again


text:
Controlling a servo without the servo library
I am trying to control a servo without the "Servo.h" library.I am sending using analogWrite() some values to the servo.I know the servo takes input a continuous time signal however I dont know the necessary frequency of that signal so I am not producing any sensible movement.What else should I consider when trying to control the servo using analogWrite()s?

analogWrite() is not suitable for driving servos. What is your issue with the Servo library?

I dont know the necessary frequency of that signal ... it is not the frequency that is critical ... it is the pulse width that is critical

It can be done using digitalWrite() and delayMicroseconds().
A servo is driven by a pulse. The pulse is between 1 ms (0°) over 1.5 ms (90°) to 2 ms (180°), followed by a pause that makes the total duration of a cycle 20 ms.
The 20 ms correspond to a 50 Hz signal. analogWrite() uses frequencies from 490 to 1000 Hz (depending on your hardware), which is why that won't work unless you figure out how to change the frequency.


text:
IoT Explorer Kit registration process
how do I reinitialize an Arduino kit registration number for a new student using a kit previously registered?  We recently ordered 50 of the IoT Explorer Kits and they will be used in a robotics class that has frequent turnover, and the kits need to be used under different student accounts.

please ask the place where you register the kits ... make up names, something like kit001 ... as it stands, the question is about the usage of an internet service, not about Arduino