text:
Program ATTiny85 running at 16 KILOhertz
I set the fuses of my attiny85 so it uses the internal 128khz clock, prescaled so it is 16kHz.
I set the CKOUT fuse too so I can check the clock using an oscilloscope on pin 3 and yes it is 16kHz.
Now my problem is I have no option in the Arduino IDE to compile my code for 16kHz clock speed.
The slowest I have is 128khz, which causes the "blink" sketch to run for 8 seconds up, 8 seconds low on my attiny instead of 1 second.
I tried with "attiny" from David A. Mellis using https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json (Slowest : 1Mhz) and "ATTinyCore" from Spence Konde using http://drazzy.com/package_drazzy.com_index.json (Slowest : 128khz).
Does someone know how I can set my Arduino IDE to compile the code for an attiny85 using the 16khz internal clock ?
(Please, no question "why use a 16khz clock ?". The point is, this chip may be set to 16khz clock, so it should be possible to program it to use such clock speed)
Thank you.

I suggest you pick whichever core is your favourite and then open a github (or wherever it's hosted) issue to add the relevent clock speed settings.

@Majenko Thank you for the suggestion. I hope there is already one providing this clock speed and someone will point it out here, but if not I will do as you say.

For the ATTinyCore, you can change in the boards.txt setting for the variant you're using  (https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/boards.txt#L409-L412). Modify f_cpu foremost. I don't know about clocksource = 3 though, look that up in the code. The boards.txt should locally be in C:\Users\<user>\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2

It should just be a matter of adjusting the boards.txt file for the core, but there may be some technical reason (calculations that fail) at that clock speed for why it's not implemented already.

@MaximilianGerhardt I modified the f_cpu and the low_fuses values to my values (16000L and 0x24) and it works ! Thank you ! I didn't modify the clocksource=3 as I don't know what it means.

https://arduino.stackexchange.com/questions/54484/adding-a-custom-board-to-the-arduino-ide/60660#60660

The Arduino core you've referenced (and pretty much all other AVR Arduino cores too) specify the clock frequency that a particular selected board is running at in the boards.txt file. The platform.txt file then retrieves that value and creates the F_CPU macro with the clock frequency in hertz as a value.
For the ATTinyCore by Spence Konde, the ATTiny85 board definition is the attinyx5 section. There, you can either add a new clock selection menu item or modify the settings of an existing one, e.g.
https://github.com/SpenceKonde/ATTinyCore/blob/f5eabc8fb97e8fd72f1782a5e97345729e42ec47/avr/boards.txt#L409-L412
attinyx5.menu.clock.128internal=128 kHz (internal WDT)
attinyx5.menu.clock.128internal.bootloader.low_fuses=0xC4
attinyx5.menu.clock.128internal.build.f_cpu=128000L
attinyx5.menu.clock.128internal.build.clocksource=3

The file is locally under C:\Users\<user>\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2.
There, f_cpu should be modified to 16000L for 16KHz, the low_fuses (lfuse) setting should be set to 0x24 and the text "128 kHz" should be adapted too. This is working per the comment on the question.
On a final note, you should create an issue at the core's repo to have a 16kHz added by default.
Also, you might find it easier to work with PlatformIO (+VSCode) instead of the Arduino IDE. A getting started page is here. In PlatformIO, instead of having to modify the internal boards.txt file, you can create a project configuration file (platformio.ini) in which you specify the same thing setting.
[env:attiny85]
platform = atmelavr
board = attiny85
framework = arduino
board_build.f_cpu = 16000L
; for upload settings, see
; https://docs.platformio.org/en/latest/platforms/atmelavr.html#upload-using-programmer

Thank you for all the informations ! A lot to read, a lot to learn, a lot to try ! :p


text:
How to get Bpm with 4 heart beat pulses
I'm trying to get an average from three intervals to get bpm. However, when I use the code below the bpm would slowly decrease when used with the sensor. Can anyone please check for what is wrong with the code and for reference I have to modify the below code from the link for 4 beats to get bpm. Getting BPM from the given code
#include <LiquidCrystal.h>

LiquidCrystal lcd(24, 25, 26, 27, 28, 29);

//global variables

int  ibeats, iInterval1, iInterval2, iInterval3, iCount = 1;
unsigned long iFirstPulse, iSecondPulse, iThirdPulse, iFourthPulse;
bool bIgnoreread = false;
bool bFirstPulse = false, bSecondPulse = false, bThirdPulse = false, bFourthPulse = false;

float BPM, fAverage;

void setup()
{
  //initialize USB serial port, I2C bus and LCD
  Serial.begin(115200);         //set this comm up in-case you want to troubleshoot

  lcd.begin(20, 4); delay(2);
  lcd.clear(); delay(2);

  lcd.setCursor(0, 0); lcd.print(" Patient Prober");

}

void loop()
{

  ibeats = analogRead(15); delay(5);//  Read the Pulse Sensor's value.

  lcd.setCursor(0, 3); lcd.print("BPM:"); lcd.print(BPM); lcd.print(" ");// displaying bpm value on LCD

  if (ibeats > 780 && bIgnoreread == false)     //once the signal is high and bIgnoread is false inital condition, inside if statment will start
  {
    if (bFirstPulse == false && iCount == 1)
    {
      iFirstPulse = millis();   // time when the pulse is high for the FirstPulse
      bFirstPulse = true;      // to turn off if statement
    }

    if (bSecondPulse == false && iCount == 2)
    {
      iSecondPulse = millis();
      iInterval1 = iSecondPulse - iFirstPulse;   // first interval
      bSecondPulse = true;
    }

    if (bThirdPulse == false && iCount == 3)
    {
      iThirdPulse = millis();
      iInterval2 = iThirdPulse - iSecondPulse;    //Second Interval
      bThirdPulse = true;
    }

    if (bFourthPulse == false && iCount == 4)
    {
      iFourthPulse = millis();
      iInterval3 = iFourthPulse - iThirdPulse;    // third interval
      bFourthPulse = true;
    }

    bIgnoreread = true; // to turn off when millis second is assign to variable Pulse  When the signal is high
  }

  // reseting all the bollean to intial condition
  if (ibeats < 300)
  {
    bIgnoreread = false;
    bFirstPulse = false;
    bSecondPulse = false;
    bThirdPulse = false;
    bFourthPulse = false;
    iCount++;               // incrment to help to diffrent if ststment above
  }

  //if(ibeats==0)iCount++;

  fAverage = ( iInterval1 + iInterval2 + iInterval3) / 3;         // Average for the interval
  BPM = (60000.0 / fAverage);                                    // Bpm calculation

  if (iCount > 4)iCount = 1;                                    // reseting icount to start the cycle again
}
//********************************************************************************************

your sketch contains no debugging code ... add some ... you cannot pinpoint the problem without it

you don't need to know when the second and third pulses occur ... get the timestamp of first pulse ... detect second pulse and third pulse ... calculate the BPM using the 1st and the 4th pulses

It sounds like you actually want to implement a rolling average for this. You want the average time of the previous four beats, (or rather the previous three time intervals), and each time you get a new interval you "forget" the oldest and add the newest, calculating the average of the three you have each time.

source: Stack Exchange

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

sort: votes


text:
LED not blinking when using a transistor
I want to control an led using a transistor. The led gets it‘s power from an external 5v dc power supply.
For the transistor I use an 1kΩ base resistor. The transistor is a BC547C (npn). The datashet is available here.
The led is red (3mm), draws 20mA of current and needs 2V.
I‘ve got a very simple Arduino sketch and wiring setup:
Code:
#define ledPin 6

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}

Wiring diagram:

Problem:

The led is not blinking but shining at full power constantly.
Disconnecting ledPin 6 from the Arduino (to mimic digitalWrite(ledPin, LOW)) still lets the led shine, just not as bright. The LED should be off in that case, not just dimmed to 50% brightness.

What I tried so far:

I tried using different base resistors. I tried 2kΩ, 3kΩ, 2.5kΩ, 470Ω, 1.5kΩ. The behavior did not change.
I tried using different leds. Same behavior. LEDs are shining constantly, not blinking, and are dimmed when disconnecting pin 6.
I used another BC547C to see if the first one was broken. It wasn’t. I still got the same behavior.
Connecting the led directly to the Arduino without the transistor and external power supply let’s the led blink exactly how it was defined in code.

Any ideas?
I several-times-checked the wiring in my setup. It should not be the problem.

You need to provide common ground. Add wire connecting negative '-' connector of your battery with GND in your Arduino.

@smajli that doesn't explain why the led stays on when the base is not connected to the gpio...

@WalterBeiter could you post a picture of your setup? Are you sure that you have assigned the correct pins at the BC547? From the info you provided and the troubleshooting you already did I don't see anything that could be wrong.

@Sim Son I agree, but we have to start somewhere...

https://majenko.co.uk/blog/importance-sharing-grounds

Is there something special about the diode? You seem to use a varactor in your schematic.

Nothing special with my diode. Varactor? No idea what that is.

@WalterBeiter So why have you drawn it with two dashes instead of one? See for example this image.

Sorry, didn’t know it better. Thanks for pointing it out.

Without a common reference (ground) between the Arduino power supply and the external power-supply, again, you have a floating base, as you can't know what the Arduino's 5v output (or local ground) looks like to the external circuit.
Connect the two grounds. That should correct the LED brightness with respect to the Arduino output pin level. Then, if you need the external circuit to behave in a specific way when the base is disconnected from the Arduino, add a 10K resistor from the transistor base to the external +5 if you want the LED to be on, or to ground, if you want it to be off. Again, I'm guessing at both the pullup/pulldown value (but 10K should be in the ballpark) and the switching sense ('On' or 'Off' for base at +5), but from the expectation state in your point (2.), I think I have it right.
Update: But see @EdgarBonet's comment to me about BJT's. I'd still avoid leaving an input floating as a matter of practice, but it seems not relevant in your circuit.

Re the floating base: The OP is using an BJT. Unlike a FET (which is voltage controlled), the control variable for a BJT is the current fed to its base. Leaving the base floating is a legitimate way of setting that current to zero.

I hadn't known that about BJTs, @EdgarBonet, so thanks for that. Fixing my answer...

Common reference ground fixed all the issues!

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


text:
Arduino Mega not recognized on Raspberry Pi 3b+
I'm developing an interactive LED table for an university assignment that is being controlled by an Arduino Mega2560 which gets the information about which LEDs should be lit in which colour from a Java application that runs on a Raspi 3b+. So far everything is almost finished and the program is running quite smoothly.
The whole time I've been developing the Java application on a PC and it worked just perfect. Now I wanted to move the application to the Pi to have a runnable demo for a meeting with my advisor. Therefore I wanted to check on which USB port the Arduino connects to the Pi so I can setup the corresponding part of the Java code correctly. As I also wanted to set a specific descriptive port name on which the Arduino is always accessible for the Java application I followed this tutorial.
In a previous attempt where I still used 2 Arduino Duemilanove that step worked however when I now try to find the Arduino Mega with dmesg | grep ttyUSB I get no results and ls -l /dev/ttyUSB* only tells me that there is no such path or directory. I also retried that with one of the Arduino Duemilanove in case the USB cable was defective but in that case it returned a valid result.
As the code that I need to run on the Arduino is too extensive for using 2 Arduino Duemilanove (due to the array size to represent the table) I definitely need to run this on the Mega. After many attempts to find a solution I didn't find anything that helps me in my situation as every thread on a similar topic was about a board that wasn't recognized on any machine (whereas my Mega gets recognized on my normal Windows PC). As the Duemilanoves get recognized seamlessly I conduct that it's probably not a problem caused by the Pi (or at least not only the Pi).
I read that using a powered USB hub could be a possible solution. However, as the Arduino itself is powered by a power supply  I suppose that using a powered USB hub would not help much in this case? However I'd be happy if someone proved me wrong in this case and solving the issue was as easy as that.

Did you try /dev/ttyACM0?

I didn't until you mentioned it as I'm not really familiar with Linux systems. But it seems that it found something. I'll have a look into what that ttyACM is exactly and will provide more information as soon as possible.

@Edgar Bonet Thank you so much, it works perfectly now. If you want to make your post an official answer I can mark it as accepted answer.

The newer Arduinos, like the Uno or Mega 2560, have a different way of managing the Serial ↔ USB translation, compared with the older Duemilianove. From the Linux side, you shouldn't see much difference, except that the device is now /dev/ttyACM0 instead of /dev/ttyUSB0.


text:
ESP8266 - ESP01S with relay. Toggling the relay with http (GPIO0) and GPIO2 at the same time
I have an ESP8266 module with a relay like this: https://aliexpress.com/item/4000348370586.html.
I have been able to control the module, I can deactivate and activate the relay by means of an http request, with the following code.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#ifndef STASSID
#define STASSID "wifi_name"
#define STAPSK  "wifi_password"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

ESP8266WebServer server(80);

IPAddress ip(192, 168, 0, 101); //ESP static ip
IPAddress gateway(192, 168, 0, 1);   //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0);  //Subnet mask
IPAddress dns(8, 8, 8, 8);  //DNS
const char* deviceName = "ligth101";

const int relayPin = 0;

void handleOn() {
    digitalWrite(relayPin, LOW);
    setCrossOrigin();
    server.send(200, "text/plain", "Ligth on");
}

void handleOff() {
    digitalWrite(relayPin, HIGH);
    setCrossOrigin();
    server.send(200, "text/plain", "Ligth off");
}

void handlePing() {
    setCrossOrigin();
    server.send(200, "text/plain", "ligth");
}

void configPin(){
    pinMode(relayPin, OUTPUT);
    digitalWrite(relayPin, HIGH);
}

void configWifi(){
    WiFi.setAutoConnect(false);
    WiFi.disconnect();
    WiFi.hostname(deviceName);
    WiFi.config(ip, subnet, gateway, dns);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    }
}

void setCrossOrigin(){
    server.sendHeader(F("Access-Control-Allow-Origin"), F("*"));
    server.sendHeader(F("Access-Control-Max-Age"), F("600"));
    server.sendHeader(F("Access-Control-Allow-Methods"), F("PUT,POST,GET,OPTIONS"));
    server.sendHeader(F("Access-Control-Allow-Headers"), F("*"));
}

void sendCrossOriginHeader(){
    setCrossOrigin();
    server.send(204);
}

void configServerPaths(){
    server.on(F("/ping"), HTTP_OPTIONS, sendCrossOriginHeader);
    server.on(F("/ping"), HTTP_GET, handlePing);

    server.on(F("/on"), HTTP_OPTIONS, sendCrossOriginHeader);
    server.on(F("/on"), HTTP_GET, handleOn);

    server.on(F("/off"), HTTP_OPTIONS, sendCrossOriginHeader);
    server.on(F("/off"), HTTP_GET, handleOff);

    server.begin();
}

void setup() {
    configPin();
    configWifi();
    configServerPaths();
}

void loop() {
    server.handleClient();
}

Now, I want to use the GPIO2 pin to also turn the relay on and off. The desired behavior is to change the state of the relay regardless of whether it comes from the button or from an http request.
I have tried the following modifications to the code:

const int buttonPin = 2;
int buttonState = 0;

void configPin(){
    ...
    digitalWrite(buttonPin, LOW);
}

void handleButton(){
    buttonState=digitalRead(buttonPin);
    if(buttonState == HIGH) {
        digitalWrite( relayPin, !digitalRead(relayPin) );
        delay(1000);
    }
}

void loop() {
    server.handleClient();
    handleButton();
}

With these modifications to the code, I have tested the following two modifications to the hardware:

Placing a switch between ground and GPIO2. As a result of this, each time I activate the push-button, the relay remains intermittent, going from one state to the other infinitely.
Placing a switch between ground and GPIO2, but adding a resistor between the switch and the GPIO2 pin, but this also does not work.

Is there a way to deactivate / activate the relay using GPIO2 with a push button and via http as well?
Thanks!

There are a number of issues here. 1) GPIO2 is the TX1 output of the first Serial Port. You can't use it if you also have serial output via Serial 1 (which might or might not be the case). 2) Why do you set buttonPin to LOW when you're using it as an input? 3) You're not debouncing the button in any way. 4) Do you use a pull-up or pull-down for your button, or neither? It's unclear from your description.

remove digitalWrite from handleOn(), handleOff() and from handleButton() ... only set or clear a flag in those three functions .... put digitalWrite (relay control) at the end of loop() ... if the flag is set, then turn on relay ... if the flag is cleared, then turn off relay .... you can then easily expand your code to set and clear the flag using a timer if you like

Contrary to esp-01, on the esp-01S io 0 and io 2 pins have a pull-up resistor.
Wire a button between io 2 and ground and you will read LOW if the button is pushed.
Use a state variable for the state of the relay, don't read back the pin (does it even work to read the state of an output pin with digitalRead on esp8266?).


text:
sensitive distance detection using 2 HC-05 module/ 2 arduino unos
Hi I am doing a project in which I use 2 HC-05 modules and 2 arduino unos driving them. 1 bluetooth module is master and the other is slave. Master module is stationary while slave is moving. If the distance between these 2 modules is less than 1.5 meter, master device turns on a led. If the distance is more than 1.5 meter, the led will not be turned on. This is the basic idea and it works but not as I wanted. I present the code
master device code:
#include <SoftwareSerial.h>
//master device code
SoftwareSerial BTSerial(5, 6); // RX | TX
#define LED 4
unsigned long timer = 0;
unsigned long timeDifference = 0;
char data;

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(9600);
  pinMode(LED, OUTPUT);
  delay(5000);
}

void loop()
{
  BTSerial.write('A');
  timer = millis();
  while(!BTSerial.available()){}
  data = BTSerial.read();
  if(data =='B'){
    timeDifference = millis()-timer;
  }
  Serial.println(timeDifference);

  if(timeDifference < 280){
    digitalWrite(LED,HIGH);
  }else{
    digitalWrite(LED,LOW);
  }
  delay(500);

}

slave device code:
#include <SoftwareSerial.h>
//slave device code
SoftwareSerial BTSerial(5, 6); // RX | TX

char data;

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

void loop()
{
  while(!BTSerial.available()){}
  data = BTSerial.read();
  if(data =='A'){
    BTSerial.write('B');
  }

}

So what happens here is that master device sends a char and starts timer. Slave receives the char and send another char to master device. When master device receives char, it stops timer and looks at how much time passed. The problem is that when I put those bluetooth devices together, the time difference is like 280ms. When I move away in the room with slave device, it is still like same. It is not sensitive. What can I do to make this more sensitive? I am waiting for your opinions

The approach you're using will not work. You're trying to use speed of light time measurement to gauge distance. There are a whole host of problems with that. First, the clock on the Arduino is not fast enough (high enough resolution). You need accurate, sub-nanosecond time resolution for that (see this video: https://www.youtube.com/watch?v=9eyFDBPk4Yw). Second, BLE is a packet protocol. The overhead and variability of sending packets will totally swamp the tiny difference in round-trip time due to speed of light delay.
The usual way to gauge distance with BLE is to measure signal strength. That is also error-prone, but you can at least get rough "immediate", "near", "middle" and "far" distance measurements.
Alternately you could use and ultrasonic range sensor.

hello how can I measure signal strength. What is the way to do so?

Have a look at this question. The RSSI describes the signal strength and thus can give you an indication of the distance.

See Chrisl's comment, which includes a link. Note that the signal strength based distance estimate is fairly crude, and influenced by things like reflective walls and obstructions.

Your approach is never going to work no matter how hard you try; it's like trying to use a hammer to bake bread!  If you need accurate time-of-flight distance measurements, use a sensor designed to do that, like the ST Micro VL53L0X time-of-flight IR LIDAR module.

In addition to the concerns above, your code won't work the way you want it to. You are initializing timer every loop so the time difference will always be 0. Instead, you should only write A from master device when it receives the response B and only then reset timer.
void loop()
{
  while(!BTSerial.available()){}
  data = BTSerial.read();
  if(data =='B'){
    timeDifference = millis()-timer;
    timer = millis();
    BTSerial.write('A');
  }
  Serial.println(timeDifference);

  if(timeDifference < 280){
    digitalWrite(LED,HIGH);
  }else{
    digitalWrite(LED,LOW);
  }
  delay(500);
}


text:
parallel communication simulation problem
Hi I am trying to send data(1 byte) from one arduino to another using parallel communication(a bus of 8 connections) and not using any library. However, the problem is the data gets corrupt all the time and what I am supposed to receive at receiver arduino is not what I send. The protocol that I made up is similar to uart protocol. There is ES pin and when it is low, transmission is started and when it is high, the transmission is ended. I think the problem could be related to wires that I use to connect two arduinos. There could be some noise induced that could flip bits in wires or the code is problematic. I am posting my code. Maybe you can help me get through this and help me to resolve my problem.
Sender code:
#define ES 8 //enable sampling
#define B0 0 //Bus 0
#define B1 1
#define B2 2
#define B3 3
#define B4 4
#define B5 5
#define B6 6
#define B7 7
const char dataToBeSent = 'C';
bool data_bit;

void setup() {
  pinMode(ES,OUTPUT);
  pinMode(B0,OUTPUT);
  pinMode(B1,OUTPUT);
  pinMode(B2,OUTPUT);
  pinMode(B3,OUTPUT);
  pinMode(B4,OUTPUT);
  pinMode(B5,OUTPUT);
  pinMode(B6,OUTPUT);
  pinMode(B7,OUTPUT);
  digitalWrite(ES,HIGH);
  delay(3000);
}
void loop() {

 digitalWrite(ES,LOW); //transmission is started
 delay(10);

 for(int i = 0 ; i<8 ; i++){
    data_bit = dataToBeSent & (0x80 >> i);
    digitalWrite(i,data_bit);
 }
  delay(10);
  digitalWrite(ES,HIGH); //end transmission
  while(true){}
}

Receiver code:
#define ES 8 //enable sampling
#define B0 0 //Bus 0
#define B1 1
#define B2 2
#define B3 3
#define B4 4
#define B5 5
#define B6 6
#define B7 7

char rx_data;
byte rx_byte= 0;
bool rx_pin;

void setup() {
  Serial.begin(9600);
  pinMode(ES,INPUT);
  pinMode(B0,INPUT);
  pinMode(B1,INPUT);
  pinMode(B2,INPUT);
  pinMode(B3,INPUT);
  pinMode(B4,INPUT);
  pinMode(B5,INPUT);
  pinMode(B6,INPUT);
  pinMode(B7,INPUT);
  delay(1000);

}

void loop() {

  byte rx_byte= 0;

  while(digitalRead(ES) == HIGH){}
  delay(15);

  for(int i = 0 ; i<8 ; i++){
    rx_pin = digitalRead(i);
    Serial.print(rx_pin);
    if(rx_pin == 1){
      rx_byte |= (0x80 >> i);
    }
  }

 rx_data = rx_byte ;

 Serial.print("Received data: ");
 Serial.println(rx_data);

 delay(15);

 while(digitalRead(ES)== HIGH){}

}

pins 0 and 1 are Serial on some Arduinos. if you would use pins of one port you could write the data at once

You problem is that you are only using one phase of your "ES" clock, when in fact you should be using two.
In the first phase, where ES is high, is where you set the IO pins to represent your transmitted byte. Only once that is done can you then progress to the second phase, where ES is low, to indicate to the receiver that "I have set up my outputs, it's now time for you to read them".
So your transmitted code would flow like:

Set ES HIGH
Set output pins to represent the byte
Set ES LOW
Delay
Set ES HIGH

If you look at any timing diagrams for any protocol there will be places where the data is being written to the bus, and places where the data is considered stable and able to be read by the receiver. It's the job of the clock signal to indicate where these points in the protocol - to synchronise the receiver.
For example, here is the Centronics (parallel port) protocol:

The data changes while nStrobe is HIGH, and only when that data is "settled" is nStrobe brought LOW to tell the receiver it can read the data. Once nStrobe is taken HIGH again the data is changed to the next byte to transmit.

thanks a lot I will give a try


text:
can I check if why my motor isn't working?
I am currently using the arduino Uno connected with L298N(green pcb) connected to a dc motor rated 12V. I provided dedicated 12v power supply to the dc motor and the arduino board's power is supplied by usb connected to my pc. I connected Pin 9 of arduino uno to 'ENA' on L298N , Pin 7 & 8 (UNO) to 'INA' & 'INB' of L298N. Connected '-' polarity of Motor power supply to GND of L298N, while also connecting the 'GND' of L298N to the GND of Arduino UNO. Last but not least, connecting the 'OUT B'to the dc motor. This is the picture of how L298N(green) look like https://sea.banggood.com/Green-Board-L298N-DC-Motor-Driver-Board-Stepper-Motor-p-974549.html?cur_warehouse=CN
Can i check why my motor isn't running? Thanks in advance.
char data = 0;
int enB = 9;
int InC = 8;
int InD = 7;

void setup()
{
    Serial.begin(9600);
    Serial.println("Motor test !");
  pinMode(enB, OUTPUT);
   pinMode(InC, OUTPUT);
  pinMode(InD, OUTPUT);

}

void loop()
{Serial.println("Entered loop, should start moving now !");
  digitalWrite(InC, HIGH);
  digitalWrite(InD, LOW);
   digitalWrite(enB, HIGH);
   analogWrite(enB, 255);
 }

the code that is inside the loop() block needs to run only once ... you can move it into the setup() block

Well, your wiring is OK, but I think the
'digitalWrite(enB, HIGH);
in the loop() code is causing your problem.  You don't want to try to use the same pin for both digital and analog functions.
I wired up a Uno here with your setup and a L298N, and got a motor to run fine with the following sketch that doesn't use the loop() at all - it does everything in setup().
char data = 0;
int enB = 9;
int InC = 8;
int InD = 7;

void setup()
{
    Serial.begin(9600);
    Serial.println("Motor test !");
    pinMode(enB, OUTPUT);
    pinMode(InC, OUTPUT);
    pinMode(InD, OUTPUT);

    Serial.println("motor should start moving now !");
    digitalWrite(InC, HIGH);
    digitalWrite(InD, LOW);
    //digitalWrite(enB, HIGH);

    for (size_t i = 0; i < 10; i++)
    {
        analogWrite(enB, 20*i);
        Serial.print("motor speed = "); Serial.println(20 * i);
        delay(2000);
    }

    Serial.println("quitting!");
    while (true)
    {

    }

}

void loop()
{
    //Serial.println("Entered loop, should start moving now !");
    //digitalWrite(InC, HIGH);
    //digitalWrite(InD, LOW);
    //digitalWrite(enB, HIGH);
    //analogWrite(enB, 255);
}

If you can't get your motor working with the above program, then you most likely have a connection or power supply or component problem that you'll need to troubleshoot.
Hope this helps,
Frank

Hi Frank, thanks for your help, after using the code you have shared, it still doesnt work. I'm suspecting that this green L298N is different from the regular "red" ones, On my L298N board only shows "5v" led lit up, all "A" "B" "C" "D" aren't.

Bypass everything and MOMENTARILY connect +12V to the motor Does the motor run?  Do you have a multimeter?  If so, you can ohm out the motor to see if you maybe have an open winding.  If the motor runs when connected directly to 12V, Try a different PWM output pin instead of pin 9.  Try connecting the motor to the other L298N output.  If you have a DVM, measure the DC voltage at the L298N motor output; it should read almost the full supply voltage when the program runs.  If you don't have a DVM, you should consider getting one - they are invaluable tools for troubleshooting ;-)

@user10748500 can you add another picture (the existing link doesn't work)? I only know the green one, not the red...


text:
Need documentation for Soil Sensor from DIYmore
Does anyone have any documentation on this device?
Im just curious how it work out of the box and how to reference the on board temp and soil sensors.
Its a (for lack of a better name)a "ESP32 DHT11 WIFI Bluetooth Soil Temperature Humidity Sensor18650"
SKU:012592
Item on DIYmore site

With a broken link to the manual on their website we're as clueless as you are.

@Majenko ...Right...I was just hoping someone somewhere once had one! I was hoping more data would come over the come post...but it not shedding much light.

You'll have to work out the schematic yourself by "buzzing out" the connections between the different components with a DMM.

The DHT11 is well documented with plenty of examples, if you can work out which pin of the ESP32 is used to communicate with it. The soil probe, likewise, looks like a simple pair of prongs with an op-amp for threshold detection - again well documented with lots of examples, if you can work out what pins it's on.

As Majenko said, without a manual or datasheet we cannot be sure (you can contact the seller about this), but it looks just like a ESP32 devboard, which already has some sensors on it. If it already "works" out of the box, I guess that means, that it comes with a working program flashed to it. Though you can also just write your own program in the Arduino framework. The sensors seem to be standard components. You would need to figure out, to which pins of the ESP32 they are connected. Thats again something, that the seller should be able to tell you.

@chrisl Well...though it "is" working...I cant see it (ble or wifi)..or communicate with it..Its actually comming to me via 3rd party...so it may have been flashed by others.

That looks like a copy of the HiGrow sensor from Hackaday.

@sempaiscuba Nice find. Chasing it down that rabbit hole leads, eventually, to TTGO as the originator: https://github.com/pesor/TTGO-T-HIGrow

@Majenko..that looks promising..

I am a bit old fashioned, as Ronald Reagan’s famous dictum, “Trust, but verify.” I always download it before ordering, there have been many suppliers that did not sell me stuff because the link was broken o data not available.

@Gil Good sound advice...It just happens that I got this device in a box with a bunch of other stuff...turns out I figured out all the thing and got a web server running with all the sensors.

Congratulations, a great job:-)


text:
How to automatically reset the NRF24L01 module
For my home-automation project I'm using several arduino nano's with each a NRF24L01+ module. Each module is able to both receive and transmit with one another. Everything seemed to be flawless for a couple of hours, but after a couple of hours it either stops transmission (completely frozen) of receives the last data repeatedly. In my design I'm using the RF24 and RF24Network libraries, I was wondering whether someone managed to automatically reset the NRF24L01 module using code, when one of these errors occured, and could share his/her code?
I already found this form, but this is only using the standard RF24 library, whereas I'm also using the RF24Network library. Furthermore, in this form it is having a seperate TX and RX side, whereas I like to have each module to be able to both send and receive.
Some extra side information, I use a stable power supply with a capacitor connected to the module, also the wires are soldered to the module.
I hope somebody can help me with this,
Guido

Are you sure the problem isn't on the Nano? It might be better to reset the Nano. Resetting the Nano would also reinitialize the NRF24.

@Gerben It is a known problem, and is especially prevalent with Chinese clones. One make even has the entire ACK bit inverted ... such quality...

This is a known problem with those chips (especially Chinese clones). It is caused when a chip gets stuck in TX mode waiting for an ACK that never arrives back.
The chips don't have a "reset", but switching them into low power mode and then back on again, which doesn't affect any register settings, aborts the current TX operation.
RF24Network is merely a protocol layer on top of the RF24 library. That RF24 library has powerDown() and powerUp() methods. Simply call powerDown followed by powerUp on your RF24 driver object.

I have tried your suggestion. However, I didn't get it to work. I indeed use these so called Chinese clones. I gave an explanation of my code used in next answer. I hope you could give me some useful advise on improving it.

Same issue; Simple work-around did it for me: (1) supply +3.3V power the nRF24L01 from a digital pin, using a forward bias diode/LED (with Vf in range 1.7-2.3V) to reduce voltage to compliant range (2.7-3.3V), then (2) in setup say, switch the pin to OUT/HIGH
pinMode(NRFPIN, OUTPUT); digitalWrite(NRFPIN, HIGH);
Notes:
A) If you have 3.3V device then you can skip voltage reduction in (2)
B) nRF24L01 power consumption peaks at 13mA (quiescent is miniscule) so well within spec for output pin
C) Of course you can do (1) with a voltage divider, or a level converter chip, etc, but the appeal of the LED (I checked Vf across 100 ohm @5V to find a decent match) is that it is simple, passive and in-line and has the nice added advantage of a faint flash when transmitting or receiving!
Look here also nRF24L01 reset

@Majenko thank you for your suggestion, I have been playing around a little bit with the powerDown() and powerUp() functions but unfortunately I haven't got it to work yet. Again, it seemed to work for a couple of hours and then again seem to get stuck. Therefore, I also included my code to see if I maybe made some major mistakes.
Furthermore, I assume that I'm having such Chinese clones of the NRF24L01+, as I have bought mine on Aliexpress.
I have included several parts of my code, the following part resets the NRF24L01+ module once a failure is detected. In here I also included the suggested powerDown and powerUp functions.
void NetworkReconnect()
{
  pinMode(CE_PIN, OUTPUT); digitalWrite(CE_PIN, HIGH);
  pinMode(CS_PIN, OUTPUT); digitalWrite(CS_PIN, HIGH);

  radio.powerDown();

  radio.begin();

  radio.powerDown();

  Network.begin(90, thisNode);

  delay(100);

  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_1MBPS);

  radio.powerUp();
}

The following code I have in my void.loop(), every 5 seconds I check the network connection, by calling NetworkCheckConnection() (see last part of included code). Which tries to figure out whether the module has crashed, I found this failure detection as a suggestion at a discussion form on the RF24 library on GitHub Discussion. Furthermore, the while loop is limited to only 500ms to avoid being in an infinite loop, if this is exceed, the function NetworkReconnect() is called again.
void loop()
{

  Network.update();

  if (millis() - Timer > 5000)
  {
    NetworkCheckConnection();
    Timer = millis();
  }

  if(radio.failureDetected){
    radio.failureDetected = false;
    delay(250);
    Serial.println("Radio failure detected, restarting radio");
    NetworkReconnect();
  }

  if (Network.available())
  {
    uint32_t failTimer = millis();
    while (Network.available())
    {
      if(millis() - failTimer > 500)
      {
        radio.failureDetected = true;
        Serial.println("Radio available failure detected");
        break;
      }

      ... The usual Network.read stuff ...

    }
  }

  ... Remainder of code ...

}

And lastly the NetworkCheckConnection() code, this code is based on the RF24 Failure handling example and the principles used for checking connectivity of the RF24Mesh network link (see line 140).
void NetworkCheckConnection()
{
  if (radio.getDataRate() != RF24_1MBPS)
  {
    radio.failureDetected = true;
    Serial.println("CheckConnection FailureDetected");
    return;
  }
  // see line 140 of: https://github.com/nRF24/RF24Mesh/blob/master/RF24Mesh.cpp
  bool ok = 0;
  if(radio.rxFifoFull() || (Network.networkFlags & 1))
  {
    return;
  }
  RF24NetworkHeader header(otherNode, NETWORK_PING);
  ok = Network.write(header,0,0);
  if(ok) { Serial.println("Network Connected");       return;}
  if(!ok){ radio.stopListening(); NetworkReconnect(); return;}
}

Lastly, I also call the NetworkReconnect() function if any of my Network.write functions fails.
I hope that you can give me some suggestions on how to get this module to work more reliable, any suggestion is welcome!
Thanks in advance :)

If you encounter a radio failure, what do you get as the output of printDetails()?


text:
Waking up a NodeMCU when force load is applied to device
I am currently designing a device that will take measurements from a load cell that  is in tension. I am using a v1.0 NodeMCU device that features an HX711 load cell amplifier and is running off of battery power. In order to conserve that power, I am wanting to be able to put as many parts of the device as possible into a sleep of some level when there is not a load on the cell. Then, I would like the device to be a be able to wake up when a load is applied and it goes into use. Going into a sleep will be simple enough, if the device is getting a reading around zero for a period time, it can enter sleep. Other notable hardware involved on the device will be a real-time-clock and an accelerometer.
From what I have already tried to look up, there doesn't seem to be any good way to use the load cell to get this action. The only idea I have been able to come up with for how to activate the device without having to wake it up extremely often other than a manual switch or checks very often came from this question. It suggests using a vibration sensor like this, which is how bathroom scales put themselves to sleep.
While I think it might be possible to use a vibration sensor to wake up the device, I am not sure if the loads involved and use case will disallow me from using one. Are there any other sensors or methods that could be used to achieve goals that I have for this device?

use a switch that closes when the scale deck is loaded

use an ESP32 and a ULP processor routine to monitor the input.

@dandavis After doing some research, that does seem like a really good option. The only issues that I can see running into is that the HX711 uses digital inputs and I have no idea how I would use assembly code to measure off of the HX711. What are your thoughts?

well it does make it a lot more complicated. the latest arduino lib helps somewhat, giving you some macros for common situations, one of which is reading an input state. i've not used it though, so i can't really explain it, i'm just aware of the broad possibilities it provides.


text:
Turning on controller with button and turning off with a timeout
I am making a device controlled by an ESP 8266 and am wanting to save power by having it power down when not in use. The desired behavior is for a momentary button press or vibration sensor activation to cause the device to turn on and stay on until it is done being used for a period of time. The ESP 8266 can sense when the device is not in use and can reset a software or hardware timer as necessary to begin the timeout process once the device stops being used. After the timeout is complete, I would like the device to power off with as little current draw as possible.
Some of the options seem to be a circuit like this: https://www.youtube.com/watch?v=L55QrKQQZJk
That would be great but to be honest, if I could find an COTS solution, it would be much better. The best thing I found was this breakout board on Adafruit: https://www.adafruit.com/product/3435. It would take care of the powering on with the button and vibration sensor and be able to power off on command as well. The main issues I would run into is the fact that the device would power on every two hours without needing to and timeout after being on for two hours as well. Even though my software timeout will probably be around 10 minutes, if the device is used for two hours straight, I don't want it to shut off mid-operation. Are there any COTS solutions here better than what I found? Or could I easily modify the TPL5110 to do what I am wanting to do?
Thank you!

you set esp8266 to deep sleep in code. esp8266 can be wake-up from deep sleep with reset button

That's what I'm trying to avoid though, I don't want to use deep sleep for this. Stuff like the ESP 8266 still uses a fair amount of power, and even then, it would be difficult to get this to work with my desired functionality.

it is off in deep-sleep. only the RTC runs and consumes ~ 20 μA according to datasheet. same amount as the TPL5110


text:
LCD on top of SD datalogger flickers help!
I have a problem with my 16,2 with buttons lcd shield.(LCD Keypad Shield). It is connected on top of an SD dataloger. I came to the conclusion that every time the sd shield logs data and completes the loop it switches off and on,flickering the lcd, and moves on with the loop. Is there any way to stop the flickering while the sd shield logs??

Which LCD is that? I think the problem is that both boards use some of the same pins, creating a bit of conflict.

It says that it is a 1602 keypad lcd shield. I bought it from here: https://www.cableworks.gr/ilektronika/arduino-and-microcontrollers/displays/lcd/lcd-keypad-shield-with-16x2-for-arduino/

If it is this one then pin D10 is the backlight control. D10 is often used as a chip select pin, and is most likely the chip select for your SD card.  The only cure is physical modification of the LCD shield to remove pin 10 and connect it elsewhere (or leave it disconnected for always on by the looks of things).

I connected the lcd externally through a breadboard avoiding the d10 and it work like a charm!!! Thanks guys!

Some of these boards have solder-jumpers on the back, to change some of the pins. In your case, I'd snip the D10 header pin on the LCD shield. And then add a small wire from one of the free pins to (the now emasculated) D10 pin


text:
Connecting LEDs and push buttons 12 feet away from Arduino UNO
I have a PCB (let's call it remote PCB) on which I have 4 LEDs and 4 buttons mounted. The remote PCB is far away from my desk (about 12 feet away). The LEDs are used to indicate the status and the buttons are for various state inputs.
All of them are connected to UNO directly.

I am planning to use a 10 pin IDC connector and IDC ribbon cable for the same.
THe LEDs' current is about 2 mA each (white LEDs)
The push buttons will make a ground connection when pressed, else the internal pull-up of the UNO will keep the GPIO at a high level.
I have put a capacitor of 10 nF across the switch to address denounce.
I have a series resistor of 1-kilo ohm for all four Switches on the remote PCB

I would like to know if this is okay? Will there be any problem due to the length. The LEDs are for indication and won't blink faster than 200 ms at any point in time. They will be used to indicate status which is very slow signals.
Thanks in Advance!

This might work.  I would occasionally expect there will be "unexpected" events.  If this is for security or safety defiantly consider an alternative.  If this is for fun, go for it.  If it works as expected great.  If not try something else.

That is a big no-no. You are adding extremely long antennas to the Arduino asking for problems. At a minimum on the inputs add a 10K series resistor at the Arduino pins.  My preference would be to put the capacitors at the arduino pins to help decouple noise etc as well as the pull up resistors on the wire side of the 10K resistors. Use a buffer of some type for the LEDs, a transistor would work. This may work but for how long and how many processors can you destroy over time.


text:
Long term stability of bluetooth connections
I have two Arduino Megas with HC-05 on Serial1 connected to a Raspberry Pi 3b+ via bluetooth, using the HC-05 and the RPi's built-in bluetooth, and python's pySerialTransfer library to make the connections.
For reasons I am still trying to root cause, the bluetooth connection gets severed a few times an hour. Ideally, I'd get hours to perhaps a day between severed connections; is this a realistic goal?
Over a course of a few days, my testing has shown:

Mega#1 median connection duration is 10 minutes & 88 minute max duration; 25 bytes sent by RPi->Arduino, and by Arduino->RPi every 0.2sec
Mega#2 median connection duration is 38 minutes & 153 minute max duration; 4 bytes sent by RPi->Arduino, and by Arduino->RPi every 0.2sec

During this testing, they're completely stationary within about 12" of each other, so range should not be an issue.
My RPi code detects a lost connection by virtue of failure to receive a message within 5 seconds, and attempts to reestablish the connection, and that is successful about 80% of the time.  I have a second-tier of lost-connection recovery - resetting the HC-05 via an Arduino-triggered MOSFET - if a message isn't received by the Arduino in ~20 seconds, that works in the remainder of the cases, so I'm ultimately able to systematically recover within a max of about 30 seconds.  However, this lost connection for ~10-30 seconds every 10-60 minutes causes a poor user experience for my remote controls.
The Python errors given for about 95% of the failures are a lack of a receipt of a heartbeat message from the Arduino to the RPi python; about 5% give a unspecific [Errno 5] Input/output error error.
While I'm running down multiple theories via day-long stability tests (longer byte transmissions are more error prone? there's some bug in my Arduino code causing crashes, so remove all logic except the send/receive code to test?), I've read a few posts about how finicky & fragile bluetooth can be, and so I'm curious for some thoughts about the general goal / attempt to get a longer-term (hours to a day or more) connection.
Have folks been able to achieve this with the HC-05 on Arduino?  Or is a dropped connection every 10-60 minutes just something one needs to deal with through robust code?  Thank you.

Speaking only from my personal experience, I've found the Bluetooth implementation on RPi (the 3B+ in particular) to be virtually useless. I've spent hours troubleshooting, but it was never relaible, and in many cases would not connect at all. From reading other Q's on RPi SE I've formed the opinion that others have had similar experiences. Also, I think it's true that RPi 3B+ has only a single antenna for WiFi and BT - which of course makes things difficult if you need them both.

I ultimately found a solution, but for the benefit of others, wanted to share the tests that also did not prove fruitful. TL;DR: Reducing message rate from Arduino's to RPi solved the problem.
My hypotheses to test:

Hypothesis: Faulty Arduino code written by myself. Test: Remove all logic except read / write.
Hypothesis: Something to do with message size. Test: Add an extra arbitrary 80 bytes to the Mega#1 message.
Hypothesis: Too many small messages for RPi to deal with. Test: Reduce message frequency.
Hypothesis: Timing problem or other HC-05 fault as suggested by @stefan-wyss. Test: Swap modules with a 3rd one.
Hypothesis: Faulty RPi python code written by myself. Test: Return to basic python test harness that does nothing except exchange bluetooth messages.

Hypotheses #1 & #2 led to no appreciable difference in failure rate or failure mode.
However, hypothesis #3 was the winner, with both Arduinos running for 12+ hours so far with no severed communications.  (So I did not bother to test #4 & #5).
Specifically, in the original "problem code", there were 20 messages sent every second (and 40 read attempts; I have "overclocked" the receiving in relation to the sending make sure buffers don't fill up due to slight variations in RPi vs. Arduino clocks):

5 sends of 25 bytes by Mega#1 to RPi per second
5 sends of 25 bytes by RPi to Mega#1 per second
5 sends of 4 bytes by Mega#2 to RPi per second
5 sends of 4 bytes by RPi to Mega#2 per second

Some of those didn't really need that frequency to achieve my design goals; so I changed to:

1 send of 25 bytes by Mega#1 to RPi every 2 seconds
5 sends of 25 bytes by RPi to Mega#1 per second
1 send of 4 bytes by Mega#2 to RPi every 2 seconds
5 sends of 4 bytes by RPi to Mega#2 per second

So now, instead of the RPi receiving 10x/second, it receives 1x/second.  (It's still attempting to read 10x per second on each of the two Arduinos to minimize latency, but most of those return no data received). The RPI still has to send 10x/second (5x to each of the two Arduinos).
This simple change fixed the problem. I have no insight as to why the RPi couldn't handle the faster rate of message receipt; some benchmarking on my Python code showed that processing of the received heartbeat messages was not a bottleneck. But the important part, at least for me & the project, is that the problem is solved.

Bluetooth communication works with fixed time intervals that both communication partners have to agree during the advertising and connection phases. Such an agreement could be: "While connected, lets' meet every second. If one does not show up during 3 meetings, let's leave the connection state".
From this you can see that timing is a very important factor in bluetooth communication. So both communication partners need a very accurate clock. No two clocks have exactly the same speed, one is always lagging the other.
It could be that one or multiple of the clocks of your HC-05's do have too much clock drift, so the connection will be lost. Maximum clock deviation allowed for a bluetooth clock is ±40 ppm (i.e. ±40 parts-per-million!) over the entire temperature range.
You could check this theory with multiple HC-05s. If individual modules lead to individual connection lengths, then this could be your problem.

Thanks, Stefan - I'll add that to the test list, and will report back (even if to share still unknown) in a few days after I've run each test for a day or so. Appreciate it.

You can also measure the clocks directly at the crystal if you have access to a timer/counter measurement device and a low capacitance (<1pF) probe.


text:
NFC library for M24SR64
Im currently working on a project where i build an NFC device and needed some guidance in regards to the library needed for the NFC chip to work on the Arduino IDE. The chip is an M24SR64 chip and i've looked online for the library related to the chip but i couldn't find it. Although i did found a library for the M24SR64-y chip, though i'm not sure if its possible to use it, or whether it will work. If anyone has an idea or any help it would be much appreciated

Here you will find a lib for all M24SR NFC tags
In this test sketch you find details how to connect and test the tag with Arduino. If it helps mark as accepted to help others.


text:
Can I run 3 devices on Arduino Uno with different power sources?
I'm pretty new to these types of projects I'd like to work on a greenhouse project with an Arduino Uno. The goal is to be able to sense temperature and control a heating lamp, detect humidity and control a humidifier, and connect a soil hydration sensor and connect a small water pump for irrigation.
Could the Uno support all of this power that could theoretically run at the same time? How would controlling the 3 isolated functions look in the Sketch?

Your question is 2 fold:

Power requirements: The actual power requirement depends on the devices, but the Arduino will certainly not be able to provide power for a heating lamp. It just cannot provide that much current (you would fry the Arduino). But the Arduino is also only powered from outside. I guess you have a power source, that can provide enough power for all the devices. Then you can connect these devices in parallel to the power source (meaning + and - of the heating lamp power goes directly to the power supply). That way the current for the devices doesn't flow through the Arduino. The Arduino will only use control signals, which don't have high current. Sensors are normally either analog sensors (which connect to the analog pins with only neglectable currents) or use communication interfaces, which are also ok. The current hungry output devices (humidifier and heat lamp) either have a digital control pin, a communication interface, or they must be controlled via a relay (depends on the actual devices).
Controlling all the devices: The Arduino can only do 1 thing at a time. But that is no problem, since you can do things sequentially very fast. For example write one function for every device, that you want to control. In that function you communicate with/control the device according to some variables (like the measured temperature). The loop() function can then look as simple as:
void loop(){
    measure_temperature();
    measure_humidity();
    measure_soil_hydration();
    control_humidifier();
    control_headlamp();
}

If you want to only do this periodically (not all the time), you can either add a delay() or - better - use millis() like in the BlinkWithoutDelay example (there are also many tutorials about millis() on the web). Make sure, that the individual functions are not blocking. They should do, what they need to do, and exit quickly. No long staying in loops or waiting for an event there.

Yes, you can run all of those from an UNO, but you'd probably be better off using an ESP32 so that you can add a web portal to your project for relatively the same cost.
You would be able to run the HDT or similar sensor and temperature sensor as well as the hydration sensor directly from an MCU. The other components would require something else, like NPN MOSFET low side power switch (like an FDS3890) that could be controlled by the MCU. You will need to look at the datasheets for each component you buy, find the power ratings, and make sure you have components rated to support the voltage and current of your devices (A good rule of thumb is twice the expected use, so if you have a 12V pump that can sink 3A of current, you should get a MOSFET that can handle 24+ volts and 6+ Amps.
Each sensor will likely have a library you will use and has samples. Googling each one and working on one individual function at a time is a great way to learn and progress your project.
Some MCU only have one core and everything is placed into a loop. Others (like that ESP32) have multiple cores, and can use a RTOS for task scheduling.


text:
Arduino Visible Light Communication(Audio transmission)
I think this is a broad question. I'm currently implementing visible light communication with Arduino. I'm using a laser as my transmitter and LDR as my receiver. I'm able to transmit a text from one side to another. But I would like to go further on this project. I want to modify the system to transfer an audio file and live stream(play) on the receiver's side.
In order to play the stream in real time, data communication must happen much faster than simple text transfer.
(Like audio with 8KHz sampling rate with 16 bit per sample).
Need transmission speed of 8*16/8= 16,000 Bytes/s
I have identified a few barriers to achieve such as

Arduino has a 64-byte buffer.(can lead to buffer overflow)
LDR response time(min delay for the pulse is 10ms for text transmission project)

I wonder If this is a possible project to do with Arduino. If it's possible, I would like to know about changes to reach that kind of transmission speed. I'm sorry for my poor writing skills.
Thank You!

You should move to a better microcontroller board (there are many commonly used ones depending on your other requirements; you could try a Pi Pico for only about 4€) and you should use a phototransistor instead of the LDR (the response time is the reason why the receivers for IR remotes, which is a similar use case, use phototransistors).

"Arduino has a 64-byte buffer." - What buffer do you mean here? The buffer of the Serial object? I believe you can increase that. Though the speed will be your bigger problem.

@chrisl Yes, the buffer of the serial object. If I can consume the buffer with much speed, then there will be no overflow(I guess).  Thank you very much for the advice.!!


text:
Fatal exception preventing flashing ESP8266 ESP-01
My issue arose when attempting to flash several of my ESP8266 ESP-01 module (https://www.aliexpress.com/item/33010444450.html?spm=a2g0s.9042311.0.0.27424c4dNkKYQZ). In the past and with the first chip I got it working just fine with the loader from the Espressif website, but the second and third proved to be stubborn.
The problem:
The issue I am struggling with is that during flashing the software does not recognize/synchronize with the chip. When attempting to do this, the indicator blue-led on the chip is constantly on. When checking the communication with the chip in normal mode (at Baud 15200) the chip responds normally to AT commands and presents version number etc. When in flash mode, however, the chip responds at Baud 74880 by flooding TX with
Fatal exception (0):
epc1=0x400fffa8, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

From research, I gathered that this could be a faulty flash in the past causing a wrong configuration in flash mode but I still haven't found a solution to this problem as the chip does not respond when attempting to re-flash.
The setup
As a setup, I have both an Arduino Uno with the chip removed(https://www.instructables.com/Flash-or-Upgrade-Firmware-on-ESP8266-ESP-01-Module/) as well as an ESP-dongle(https://www.aliexpress.com/item/32693314450.html?spm=a2g0s.9042311.0.0.506e4c4ddAqtwB) with a switch soldered on between GND and GPIO0. Furthermore:

Vin -> 3.3V
CH_EN -> 3.3V
Tx -> Tx
Rx -> Rx
GPIO_0 -> GND
GND -> GND

As software, I tried that from the Espressif website (latest version and that of Jan 2021) as well as NodeMCU Firmware Programmer. Again, the first chip responded after a while (also not ideal), but the second and others fail to do so.
The question
My question is thus what could be causing this problem, what I can do to rectify the issue, and finally what the most secure way to flash such chips is as my previous one clearly did not work.
Thanks for any tips in advance,
Cheers

try to pull-up io 2

Try using a lower baud rate. Maybe 57600. I have found that some chips that are difficult to program at 115200 will reliably program at a slightly lower baud rate.


text:
Can a power cut damage the software?
When unplugging the power source of a device that is writing some data "A" to an SD card, also other data "B" might get corrupted. (This is detailed here.)
Regarding Arduino projects without an SD card, is it OK to remove the power source of Arduino microcontrollers anytime because the memory inside them uses a different technology than SD cards do (what are the names or differences of the respective technologies)?
Or are there several entirely independent memories - one for data and one for software/sketches?
Or do Arduino projects have to be programmed such that there are periods without data-writing and an LED indicates when it is safe to cut off the power?

First we need to look at the different memory technologies in a microcontroller:

First you have the flash memory. This is where the program is saved, but it can also be used to hold user data. On AVR based Arduinos it can only be written while programming or by the bootloader. But boards like the various ESPs can also have a little file system in it. Here you can get problems with a power loss while write operations happen.
The RAM holds the current value of all variables. But it also always looses all data when unpowered. This is normal behavior because it is volatile memory. A power loss won't change anything here.
That leaves us with EEPROM, a non-volatile memory type. You can corrupt your data with a power loss during write operations.

Then we need to look at the data structures. Most memory in Arduinos and similar boards a organized as a simple array of bytes. EEPROM is usually handled this way. If you write a data structure and have a power loss during that time, you must view this data structure as corrupt (for example writing a string with 20 characters, but while writing the 6th byte the power goes out). Other data is not harmed. On the other hand when you use a filesystem in flash like SPIFFS a write action in a file also involves handling a filesystem table. Outage during handling of the table might corrupt your filesystem integrity, thus can also harm other files.
SD cards are a special case, since their internal controllers move the data around to some unknown algorithm to implement wear leveling. This is not done with standard microcontrollers (you would need to implement it yourself if needed). The actual memory technology is also just flash, but you don't want to disturb the SD card while its handling its wear level algorithmus. That might corrupt the SD card completely. Also the linked answer talks about the SD card of a Raspberry Pi, which has a complete OS running on it. Running an OS involves way more changing non-volatile data than a microcontroller typically needs. So its way less likely to have the same situations with a microcontroller.

Or do Arduino projects have to be programmed such that there are periods without data-writing and an LED indicates when it is safe to cut off the power?

Normally that is not needed, though it depends on your application and how the sketch handles the data. Are you saving data to non-volatile memory? How often do you do it? How often do you cut the power? If you are writing to byteswise memory like EEPROM, can you tolerate specific data corruptions? How much data are you writing each time?
Without assessing all these questions you cannot really say. Typically beginners just start without precaution in that direction. When you see problems after replugging, then you still can add an activity LED to the project.

TL;DR If the sketch doesn't write to non-volatile memory, it is safe to pull the plug at any moment.

Thanks! Regarding "Outage during handling of the [filesystem] table": I guess "handling" means writing. So if I want to regularly write some data A1, A2, A3 and avoid damaging existing data "B", is it good to allocate one big empty file "A" and regularly write data into it (kind of a "filesystem within a filesystem"), instead of regularly creating several small files?


text:
Keyboard.h not found on Arduino nano
I am trying to use keyboard on my Arduino nano, but i get this error:
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

As per the answer in Keyboard.h not found, I tried change the board to Arduino Leonardo, even though the script gets compiled it doesn't get uploaded (keeps on saying uploading for a long time).
This is the code I use:
#include <Keyboard.h>
void setup() {
  Keyboard.begin();
}
void loop() {
}

If you also change the board itself, it'll work. The Uno has different MCU and it doesn't have physical USB interface in it.

As said above you cannot use the Keyboard library on the Nano. It just doesn't have the necessary hardware

To convert the comments into an answer:
You cannot (!) use the Keyboard library on the Arduino Uno/Nano/Mini. It needs a native USB interface to configure it as a HID device, but the Uno/Nano/Mini all use the Atmega328p, which doesn't have a native USB interface. These Arduinos use an additional chip on the board which acts as USB-UART-bridge.
You can compile the code for the Leonardo, because it has a native USB interface. But you cannot (!) upload code, which is compiled for the Leonardo, to an Uno/Nano/Mini. Its a completely different chip.
What to do now: Get an Arduino board which has a native USB interface, for example the Leonardo or the Micro.


text:
Arduino Turn Signals
Could I use an Arduino to power run the following lights? Here I have a project in mind, and although I am new to electronics, I am a computer programmer (C, C++, C#, Java) by profession so the coding side doesn't worry me, what I am confused about is what power supply I need etc.

If you look at the specs of those lights, they draw 1 watt at 12 volts. That is both too much current and too much voltage for an Arduino. (You're only supposed to draw about 20 mA from a single pin, and somewhere between 500 mA and 1 amp from the 5V regulator. (It is heat limited, and typically not very well heat-sinked. Er, heat-sunk?)
An Arduino only puts out 3.3v and 5V.
If you're looking to drive these from a car/motorcycle, you should be able to power them directly from the 12V battery of the vehicle. Failing that, get a 12V power supply that can put out as much current as you need for ALL of the lights you need, plus 10%-20% extra, for "slop".
What you should do is to buy a MOSFET power transistor designed for switching logic level signals for each turn signal you need to control. These would work well:
https://www.adafruit.com/product/355
You'd then use logic lines from the Arduino to control the gates of the transistors, and each transistor would switch the power for one of your turn signal lights.

If you mean you want to power it directly from a GPIO pin from an Arduino: no, for two reasons:

It doesn't show the current needed, but it's likely more than 20 or 40 mA which is maximum for a GPIO pin. So you need to use a transistor, which can be used to turn on something with higher current, with the current of a GPIO pin. Search for 'Transistor as a switch' for more info.
Also, it's 12 V and the Arduino delivers 5 V.

What you need is a separate 12V adapter, with a current capability MORE than what that light needs. I cannot find the current (mA) in the link, so you might need to measure it (e.g. with a digital multimeter). If you don't have a digital multimeter, buy one, you need one anyway if you will do electronics. You can even buy a 3 euro one from China if you want (for now).


text:
MLX90129 - SPI protocol
I don't know if someone has already worked with the MLX90129. Right now, I'm trying to establish the SPI protocol between MLX90129 and an Arduino. I'm using the example that it is showed in the datasheet respecting the SPI protocol where I send a write command, the address targeted, and the 2-byte data to write and then wait the required time for data writing.
So, I'm sending 0xABCD (hexadecimal) to the slave(MLX90129), and then it is supposed to read in the same wrote address and getting back 0xABCD. It happens that I don't get the desired 0xABCD on the MISO line, and all I get is 0xFF. Here's the code:
#include <avr/io.h>
#include <util/delay.h>
/*-------- SPI -------------
SS => PB2 => OUTPUT
MOSI => PB3 => OUTPUT
MISO => PB4 => INPUT
SCK => PB5 => OUTPUT
---------------------------- */
#define PORTSPI PORTB
#define SS      PB2
#define MOSI    PB3
#define MISO    PB4
#define SCK     PB5

#define SS_H   PORTB=(1<<SS) // SS line with high level output
#define SS_L   PORTB=(0<<SS) // SS line with low level output

#define DDR_SPI    DDRB // set the pins of PORTB as Input or Output
#define DD_SS      DDB2 // set the pin PB2 as Input or Output
#define DD_MOSI    DDB3 // set the pin PB3 as Input or Output
#define DD_MISO    DDB4 // set the pin PB4 as Input or Output
#define DD_SCK     DDB5 // set the pin PB5 as Input or Output

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

}

void loop() {
  SS_H;
  SPI_MLX90129_write(); // write 0xABCD in EERPOM #11
  SPI_MLX90129_update();// update register file
  SPI_MLX90129_read(); // read in Register #11
  Serial.println("-");
}
/*--------------------SPI_MasterInit---------------------*/
void SPI_MasterInit(void)
{

/* Set SS, MOSI and SCK output, MISO input */
DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
/* Enable SPI, Master, set clock rate fck/16 = 1MHz */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
//SPSR = (0<<SPI2X);
}
/*-------------------------------------------------------*/

/*-------------------SPI_MasterTransmit------------------*/
char SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
/* Return Data Register */
Serial.println(SPDR, HEX);
return SPDR;
}
/*-------------------------------------------------------*/

/*-------------------SPI_MLX90129_write------------------*/
void SPI_MLX90129_write(void)
{

char write_command;
char address;
char data_MSB;
char data_LSB;
// Write EEPROM at address 0x11 with data 0xABCD
write_command=0x0E;
address=0x11;
data_MSB=0xAB;
data_LSB=0xCD;
SS_L; // SS low selects the slave for the communication
//_delay_us(0.6);
//_delay_us(1500); // delay only when MLX90129 is in sleep mode
SPI_MasterTransmit(write_command);
SPI_MasterTransmit(address);
SPI_MasterTransmit(data_MSB);
SPI_MasterTransmit(data_LSB);
//_delay_us(0.5);
SS_H; //SS high deselects the slave and end the communication
_delay_ms(17); // delay to write EEPROM
//_delay_ms(11); // delay to write EELAtch
//_delay_us(0.5);
}
/*-------------------------------------------------------*/

/*-------------------SPI_MLX90129_read-------------------*/
void SPI_MLX90129_read(void)
{
char read_command;
char address;
char data_MSB;
char data_LSB;
// Read Register at address 0x11
read_command=0x0F;
address=0x11;
data_MSB=0xFF;
data_LSB=0xFF;
SS_L; // SS low selects the slave for the communication
//_delay_us(1500); // delay only when MLX90129 is in sleep mode
// send read command and targeted address
SPI_MasterTransmit(read_command);
SPI_MasterTransmit(address);
//_delay_us(50); // delay to read EEPROM
_delay_us(2); // delay to read Register file
//_delay_us(2); // delay to read EELAtch
//_delay_us(430); // minimum delay to read ADC output
// send 0x00 (or other random data) to generate SPI clock
// and get the slave answer
data_MSB=SPI_MasterTransmit(0x00);
data_LSB=SPI_MasterTransmit(0x00);
SS_H; // SS high deselects the slave and end the communication
Serial.println(data_MSB, HEX);
Serial.println(data_LSB, HEX);
}
/*-------------------------------------------------------*/

/*------------------SPI_MLX90129_update------------------*/
void SPI_MLX90129_update(void)
{
char update_command;
// Update command =0x1C
update_command=0x1C;
SS_L; // SS low selects the slave for the communication
//_delay_us(0.6);
// send the update command
SPI_MasterTransmit(update_command);
SS_H; // SS high deselects the slave and end the communication
_delay_us(1500); // delay for the update of the registers
}
/*-------------------------------------------------------*/

I'm reading the value from the serial monitor, and I get slightly different values when I change the baud rate. Can that be the problem? Should I use a display to see the data coming out from the MISO line? Can the MLX90129 be damaged? I don't think the problem is the code because that code is made available by the chip producers.
MLX90129's SPI lines only support 3.3V, and as I was using an Arduino with an operating voltage of 5V, I thought that was the problem. But I also tested with an Arduino DUE, which has an operating voltage of 3.3V, and I wasn't successful. I can't figure out where the problem is.

Is there a specific reason why you're not using the SPI library?

Are you saying that you had it connected to 5V at one point?  It may be fried then.

I have also tested with the SPI library, and it gives the same result. I didn't connect it directly to the Arduino. I used a level shifter to drop down the voltage from 5V to 3.3V. However, this MLX90129 was used by another person before me. Possibly it's damaged. I don't know what this person made with the MLX90129. @Delta_G

I have also tested with the SPI library, and it gives the same result. I didn't connect it directly to the Arduino. I used a level shifter to drop down the voltage from 5V to 3.3V. However, this MLX90129 was used by another person before me. Possibly it's damaged. I don't know what this person made with the MLX90129. @Majenko

Not your problem at the moment, bit a hint for the future: set a bit by SS_H|=(1<<SS), clear a bit by SS_L&=~(1<<SS). Otherwise you clear all bits in the register.


text:
Controlling Brickstuff with Arduino
I don't have much experience with electronics (I'm ok with programming). I have some Brickstuff lights in a Lego set. The lights are powered by 3 AA batteries. The Brickstuff documentation says that I should not connect then directly to an Arduino, as the current exceeds the Arduino limit. I want to use an Arduino to power the lights and activate them with a button, but I want to use the same power supply to feed the Arduino and the lights.
Any suggestions about what components I should use, and how to connect them? Thanks.

You need a transistor.  Google, "using a transistor as a switch".

Transistor is likely what you want for simplicity.
Be sure to add up all your amperage requirements and then add some extra when selecting a supply.  Having too little available will make your circuit misbehave while having a supply capable of giving you more doesn't hurt.
For voltage 3×1.5V = 4.5V if the batteries are in series.  Arduino runs on 5V (USB).  I suspect you'll probably be using a 5V supply.  Both circuits have a little margin, lights usually more so.


text:
SD card with arduino UNO
I am trying to use a micro SD card in order to store data sent from an arduino UNO.
My setup consists of:

Arduino UNO (5V logic), powered directly from USB cable
Digilent Full-sized SD Card Slot
Simple microSD to SD adapter
Transcend 4GB microSD card SDHC
TXB104 Logic Level Converter
USB-powered PSU, that provides both the 3.3Volts and the 5Volts

The above components are connected as mentioned below:
Pins 1 to 4 of the Digilent SD module are driven to the 3.3Voltage side of the logic level converter. Also the SD module is powered with 3.3Volts. The 4 signals (SS, MOSI, MISO, SCK) are then taken from the 5Volt side of the logic level converter and are driven to the arduino UNO pins 10, 11, 12 and 13 respectively. Also, all the components have a common ground. The card is formatted to FAT32 using the SD card Formatter from sdcard.org.
In the arduino, I upload the SdInfo sketch of the Sdfat library. The result I get is the following:

Let me know if I can provide any more info.

I doubt the SDHC card is supported.
I don't have the same card slot reader, however, mine only worked with 'old' SD cards, not SDHC, SDXC etc.
So try an old one to see if it works (at least you rule out this option).


text:
Sparkfun canbus shield with LSM6DS33 dual SPI problem
Hello fellow arduino users! I have a question regarding using the Sparkfun Canbus shield in conjunction with the LSM6DS33 sensor on a dual SPI configuration. I have managed to get theese two to initialize but after reviewing the data it seems that the accelerometer is sending wrong readings... I am guessing the SPI devices mess with each other. Any idea on how to fix this? I am using an UNO R3 and here is the code:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <Canbus.h>
#include <TinyGPS++.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <Keypad.h>
#include <Adafruit_LSM6DS33.h>
#define LSM_CS 9
#define LSM_SCK 13
#define LSM_MISO 12
#define LSM_MOSI 11
Adafruit_LSM6DS33 lsm6ds33;
TinyGPSPlus gps;
SoftwareSerial ss(3,2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad membrane = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String s;
int IATMP;
float MAF;
int VSPD;
int RPM;
float MAF2=0.0;
float DeltaMAF=0.0;
char iatbuffer[64];
char mafbuffer[64];
char vspdbuffer[64];
char rpmbuffer[64];
unsigned long currtime;
unsigned long deltatime;
const unsigned char UBLOX_INIT[] PROGMEM={
0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A
};

//********************************Setup Loop*********************************//
void setup() {
  ss.begin(9600);
  //Initialize Serial communication for debugging
  Serial.begin(115200);
  while (!Serial){
    delay(10); }
  for(unsigned int i=0;i<sizeof(UBLOX_INIT);i++){
    ss.write(pgm_read_byte(UBLOX_INIT+i));
    }

  if(Canbus.init(CANSPEED_500))  /* Initialize MCP2515 CAN controller at the specified speed */
  {

    Serial.println(F("CAN Init Ok"));
    delay(1500);
  }
  else
  {

    Serial.println(F("Can't init CAN"));
    return;
  }

if (!lsm6ds33.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) {
    Serial.println(F("Failed to find LSM6DS33 chip"));
    while (1) {
      delay(10);
    }
  }

Serial.println(F("LSM6DS33 Found!"));
lsm6ds33.setAccelRange(LSM6DS_ACCEL_RANGE_2_G);
lsm6ds33.setGyroRange(LSM6DS_GYRO_RANGE_125_DPS);
lsm6ds33.setAccelDataRate(LSM6DS_RATE_12_5_HZ);
lsm6ds33.setGyroDataRate(LSM6DS_RATE_12_5_HZ);
lsm6ds33.configInt1(false, false, false);

/*int i=0;
char input = membrane.getKey();
char usrid[4]={0};
while(!input){}
if (input){
  usrid[i]=input;
  i++;
  }
input = membrane.getKey();
while(!input){}
if (input){
  usrid[i]=input;
  i++;
  }
input = membrane.getKey();
while(!input){}
if (input){
  usrid[i]=input;
  i++;
  }
input = membrane.getKey();
while(!input){}
if (input){
  usrid[i]=input;
  i++;
  }
s= String(usrid);
*/

}

//********************************Main Loop*********************************//
void loop(){

while(ss.available()>0){

gps.encode(ss.read());
if(gps.location.isUpdated()){
sensors_event_t accel;
sensors_event_t gyro;
sensors_event_t temp;
lsm6ds33.getEvent(&accel, &gyro, &temp);
currtime=millis();
Serial.print(s);
Serial.print(",");
Canbus.ecu_req(MAF_SENSOR,mafbuffer);
      MAF2=MAF;
      MAF = atof(mafbuffer);
    DeltaMAF=MAF-MAF2;
     // Serial.print("Engine RPM: "); //Uncomment for Serial debugging
      Serial.print(mafbuffer);
      Serial.print(F(","));
      Serial.print(DeltaMAF);
      Serial.print(F(","));
      delay(10);
Canbus.ecu_req(VEHICLE_SPEED,vspdbuffer);
    VSPD = atoi(vspdbuffer);
    //Serial.print("Engine RPM: "); //Uncomment for Serial debugging
      Serial.print(vspdbuffer);
      Serial.print(F(","));
      delay(10);
Canbus.ecu_req(IAT,iatbuffer);
    IATMP = atoi(iatbuffer);
    //Serial.print("Engine RPM: "); //Uncomment for Serial debugging
      Serial.print(iatbuffer);
      Serial.print(F(","));
      delay(10);

Canbus.ecu_req(ENGINE_RPM,rpmbuffer);
    RPM = atoi(rpmbuffer);
    //Serial.print("Engine RPM: "); //Uncomment for Serial debugging
      Serial.print(rpmbuffer);
      Serial.print(F(","));
      delay(10);
     if (RPM>800){
      Serial.print(F("idling"));
      Serial.print(F(","));
      }else{
        Serial.print(F("running"));
        Serial.print(F(","));
        }

Serial.print(accel.acceleration.x);
Serial.print(F(","));
Serial.print(accel.acceleration.y);
Serial.print(F(","));
Serial.print(accel.acceleration.z);
Serial.print(F(","));
Serial.print(gyro.gyro.x);
Serial.print(F(","));
Serial.print(gyro.gyro.y);
Serial.print(F(","));
Serial.print(gyro.gyro.z);
Serial.print(F(","));
Serial.print(temp.temperature);
Serial.print(F(","));
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
Serial.print(F(","));
deltatime=millis()-currtime;
Serial.println(deltatime);

}
}
}


text:
esp8266 esp01s EEPROM and flashing
which flash option do I need to take to use EEPROM?
Can I flash with 1MB and no SPIFFs and still write data to EEPROM?
thanks T

Can I flash with 1MB and no SPIFFS and still write data to EEPROM?

Yes. The EEPROM emulation is saved into different part of the flash, not to SPIFFS.
|--------------|-------|---------------|--|--|--|--|--|
^              ^       ^               ^     ^
Sketch    OTA update   File system   EEPROM  WiFi config (SDK)

the memory map is from esp8266 SPIFFS docs

which flash option do I need to take to use EEPROM?

There is no special option in Tools menu for EEPROM emulation. Only use the library.


text:
about receiving float on matlab from ATmega32 Avr
****i am using ATmega32 to send float and want to receive it on matlab,i send 4.85 from ATmega32 but on matlab i receive 4.260233679216239e-31...can any one help me..thanks in advance**
**
    //Atmel studio code++++code for sending float from Atmega32
    union abc{ float fo; unsigned long lo; };
 union abc data;
int main(void)
 { usart_init();
 data.fo=4.85;
 while(1) {
for(int i=0; i<=24; i+=8)
{
    uart_send(data.lo>>i); }}}

 //Matlab code for receiving float
s=serial('COM1','BaudRate',9600);
fopen(s);
out=fread(s,1,'single');
 fclose(s);

i found the solution for this problem, i set a header before sending the data from ATmega32,and on Matlab i check the frame ,if it received correctly,i receive the data
//ATmega32 code
    float x =215.5;
    unsigned char *ptrx;
    int main(void)
    {   usart_init();
        //data.fo=12.85;

        ptrx=( unsigned char *) &x;
          while(1)
       {
        uart_send(0xAA);//equals to 170
        for(int i=0;i<4;i++){
        uart_send(*(ptrx+i));}

        x++;}}
    //on Matlab
    s=serial('COM1','BaudRate',9600);
    fopen(s);
     i=1;
    while i<1000
        header =fread(s,1,'uint8');

        if header==170//equal to 0xAA

     out=fread(s,1,'float');
    data(i)=out;

     i=i+1;
        end
     end
    fclose(s);

The binary representation of 4.260233679216239e-31 is 0x0d0a40a3. The
first two bytes (in big endian format) are 0x0d and 0x0a, which
happen to be the ASCII characters CR and LF. These characters, in
tandem, are often used as line terminators. My guess is that
uart_send() is not doing what you think...
I suggest using Serial.write() instead. This way you won't have
unwanted line terminators. And it will also make your problem on-topic
with respect to this site.
Also, do not send the bytes repeatedly, send them only once, on demand.
If you send them continuously, Matlab may catch the serial stream in the
middle of a number, and assemble the bytes in the wrong order.


text:
Decoding RC transmitter data
I would like to use my FSi6 transmitter but not the receiver that comes with it (I´m trying to save weight), for that I was planning to get one of this NRF24L01 breakout boards. The problem is, how do you interpret the incoming traffic? After some googling, I couldn´t find any information from flysky.
I would think that this is a common thing to do, as you could pair the transmitter with another receiver (perhaps other brand) so there must be a standard protocol.
Any ideas?
Thanks!

why do you think that the FSi6 can communicate with the NRF24L01?

I expect that as both use 2.4 it would be possible, I´ve been doing some more research an apparently fs uses AFHDS 2A  kind of receives, so I think I was completely wrong assuming any receiver could speak with my i6...

Unless the FSi6 (whatever that is) uses an nRF27L01+ as its transmitter, then no - you can't.
The nRF24L01+ chip will only communicate with other nRF24L01+ chips.  It contains its own custom protocol within the chip and it can only talk that protocol and no others.


text:
Setting up 433 MHz Transmitter and Receiver in the same Arduino sketch using Radiohead
I have set up a 433 MHz transmitter and receiver pair on one Arduino Uno board. Using the RCSwitch library, I could successfully send and receive signals. Using the Radiohead library however, I could only send and got no reception. I am curious why and grateful for any help.
Here is the sketch. Both receiver and transmitter draw power from Arduino 5V and GND. The DATA pin of transmitter is attached to pin 12 of Arduino. The DATA pin of receiver is attached to pin 11. These appear to be "hard-coded" in the Radiohead library. My reciever has an additional chip select (CS) pin which I have wired to pin 10.
Using the serial monitor, it looks like transmitter and receiver are initialized without problem and message is sent. I have used the RCSwitch library with transmitter and receiver on the same board and that worked, (i.e. messages sent were received correctly) so I am curious why the issue with Radiohead.
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependent SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_receiver;
RH_ASK rf_transmitter;

void setup()
{
    // Initialize ASK Object
    if (!rf_receiver.init())
        Serial.println("Failed to initialize receiver.");
    if (!rf_transmitter.init())
        Serial.println("Failed to initialize transmitter.");

    Serial.begin(9600);

    digitalWrite(10, HIGH);   // enable CS on some receiver devices
}

void loop()
{
    const char *msg = "Hello world!";
    rf_transmitter.send((uint8_t *)msg, strlen(msg));
    rf_transmitter.waitPacketSent();
    Serial.print("Message sent: ");
    Serial.println((char*)msg);

    uint8_t buf[12];
    uint8_t buflen = sizeof(buf);

    if (rf_receiver.recv(buf, &buflen))
    {
      Serial.print("Message received: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.print("No message rec'd: ");
      Serial.println(*&buflen);
      Serial.println((char*)buf);
    }

    delay(1000);
}

The answer can be found in the source code 0f RH_ASK.h (you should read the well made documentation before using this library):

At present only one instance of RH_ASK per sketch is supported.

So you will have to write such an extension yourself, use two Arduinos or use another lib for testing.


text:
Arduino Micro 5V Vin and 3v3 pins
I am very confused with the pins on the arduino micro. What are the 3v3, 5v, and Vin pins used for? Are they for power input, or power output, or both?

Vin is a power INPUT. It is connected to the input of the voltage regulator, which enables you to power the Arduino with voltages between 6V and 12V, while the Arduino itself is running on 5V.
The 5V pin can be both an power INPUT and OUTPUT. It is connected to the general 5V power rail inside the Arduino and thus to the power inputs of the microcontroller. This rail/pin needs to be provided with 5V power to let the Arduino work. Where this power comes from (from the voltage regulator, from USB or from your own external 5V power supply connected to the 5V pin) is irrelevant for the Arduino. The 5V pin can even be used to provide power to other components in your circuit (though with certain limitations, see below).
The 3V3 (meaning 3.3V) pin is a power OUTPUT. It is connected to the output of another voltage regulator, which brings the 5V from the 5V rail down to 3.3V. It can be used to power external parts, that need 3.3V to work.

Up to this point I only wrote about voltage. But depending on your circuit you also need to consider the current. The different electrical parts on the Arduino can only handle a specific power (measured in Watts). Thus with a given voltage you can only draw up to a specific amount of current through them, before you destroy them.
As an example, let's assume you provide the Arduino with 9V through Vin and you want to drive a middle sized motor. Motors in general can draw a lot of current. When you now drive the motor from the 5V pin of the Arduino, the motors current will flow through the Arduinos voltage regulator. Thus the regulator will go into emergency shutdown and cut the power (applies for a genuine Arduino) or it will get destroyed (applies for most cheap Arduino clones). To prevent that, you need to connect the motor directly with the power supply (or through an extra voltage regulator, suitable for the needed current), so that the current for it is no longer flowing through the Arduino.
This explanation is only to prevent you from destroying your board. That is always very annoying, when it happens.

Ahh, this makes much more sense! Thank you very very much! :)

Upvoted (also because of the last line, which is quite an understatement).

Excellent answer. One point I would add is that if you are going to supply 5V to the 5V line, you need to make sure it is regulated 5V. If it strays too far from 5V it will cause the board to malfunction and may damage or destroy it.

VIN is power input. IN means INput.
Generally 5V and 3.3V are used for power output, but the 5V one can also be used for power input if you want to power the board from 5V.
But since they are just power they have no "direction" as such, only a voltage level.


text:
What happens to the board if you connect the +5V pin directly to a digital input configured as input
I have maybe a very stupid question but connecting the +5V pin to a digital input pin programmed as input ( let's say pin2) . Will it destroy the board? Cause after i did this my board doesn't work anymore and i can also not upload a sketch to it. it does nothing anymore, yet nothing has burned or no smoke.
??
Thanks

Will it destroy the board?

No, it will just read HIGH. That's what HIGH is - 5V.

Cause after i did this my board doesn't work anymore

Then you probably did something else.

OK. in that case, what happens if you would add +5V from an external supply that is also powering the arduino by +12V . Meaning connecting +12V to Vin and 0V to Ground and than connecting a +5V to an input pin? Cause one way or another i fried these boards but i just don't understand how. I managed to break 2

Ok. I just measured. I have feeded +12V to the digital pin set as input. So will this frie the board irreperably or can i get the board to work again by replacing a part?

You may be able to replace the main mcu

Yes, if you feed +12V into an input pin you will likely damage or destroy the board. I did this with 9V on an Arduino Mega 2560 and it only destroyed that one input pin. The higher the voltage, the more likely it is to damage something, and the more severe that damage is going to be.


text:
How can I identify GPS sattelites in TinyGPS++?
I can see about 15 satellites (about 10 GPS + 5 Glonass) in u-center, but I see only about 10 satellites using TinyGPS++. I suspect that TinyGPS++ can see GPS only. I see lines containing $GNRMC $GNVTG $GNGGA $GPGSV $GNGLL $GNVTG $GLGSV in the input, so there are information from both constellation. But how can I check which constellations TinyGPS++ takes into account for the output:

Sats=10 Nums=1 3 8 10 11 14 20 22 24 27 28 31 32 36 40  Elevation=46
  17 45 31 69 59 1 43 5 24 9 1 60 36 32  Azimuth=304 255 215 66 267 137
  77 263 28 184 316 140 89 181 150  SNR=12 0 0 17 8 20 0 11 0 11 0 0 21
  0 0

TinyGPS++ is just a text parsing library you can read and examine

https://www.gpsinformation.org/dale/nmea.htm#GSV SNR=0 means the satellite can be seen but may not be being used for your positional fix.

There is a bug in TinyGPS++ as it only counts GPS satellites. See https://github.com/mikalhart/TinyGPSPlus/issues/52
PRN numbers are used to identify satellites:

GPS = 1 to 32
SBAS = 33 to 64 (add 87 for PRN number)
GLO = 65 to 96


text:
Pulsein() function blocks other tasks from running silmultaneously
I am using a zumo bot with a reflectance sensor used to follow a black line. I want to use an arduino to make the zumo bot stop once it gets a certain distance from an obstacle.
I have an ultrasonic sensor (HC-SR04) which ive connected to the bot.
Both of these tasks work independently but once i merge the code together(so it follows the line aswell as stoping when it detects an object using the ultrasonic sensor), it doesn't work properly.. (the zumo bot no longer follows the line)
I THINK it is to do with the pulsein() function blocking any other tasks but not sure.
My code is below. Can anyone help please?

#include <Wire.h>
#include <ZumoShield.h>

ZumoBuzzer buzzer;
ZumoReflectanceSensorArray reflectanceSensors;
ZumoMotors motors;
Pushbutton button(ZUMO_BUTTON);
int lastError = 0;

// This is the maximum speed the motors will be allowed to turn.
// (400 lets the motors go at top speed; decrease to impose a speed limit)
const int MAX_SPEED = 400;
#define echoPin A4
#define trigPin A5

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement

void setup()
{
  reflectanceSensors.init();

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

  // Initialize the reflectance sensors module

  // Wait for the user button to be pressed and released
  button.waitForButton();

  // Turn on LED to indicate we are in calibration mode
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // Wait 1 second and then begin automatic sensor calibration
  // by rotating in place to sweep the sensors over the line
  delay(1000);
  int i;
  for(i = 0; i < 80; i++)
  {
    if ((i > 10 && i <= 30) || (i > 50 && i <= 70))
      motors.setSpeeds(-200, 200);
    else
      motors.setSpeeds(200, -200);
    reflectanceSensors.calibrate();

    // Since our counter runs to 80, the total delay will be
    // 80*20 = 1600 ms.
    delay(20);
  }
  motors.setSpeeds(0,0);

  // Turn off LED to indicate we are through with calibration
  digitalWrite(13, LOW);

  // Wait for the user button to be pressed and released
  button.waitForButton();

  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
  Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
  Serial.println("with Arduino UNO R3");

}

void loop()
{

  unsigned int sensors[6];

  // Get the position of the line.  Note that we *must* provide the "sensors"
  // argument to readLine() here, even though we are not interested in the
  // individual sensor readings
  int position = reflectanceSensors.readLine(sensors);

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Our "error" is how far we are away from the center of the line, which
  // corresponds to position 2500.
  int error = position - 2500;

  // Get motor speed difference using proportional and derivative PID terms
  // (the integral term is generally not very useful for line following).
  // Here we are using a proportional constant of 1/4 and a derivative
  // constant of 6, which should work decently for many Zumo motor choices.

  int speedDifference = error / 4 + 6 * (error - lastError);

  lastError = error;

  // Get individual motor speeds.  The sign of speedDifference
  // determines if the robot turns left or right.
  int m1Speed = MAX_SPEED + speedDifference;
  int m2Speed = MAX_SPEED - speedDifference;

  if (m1Speed < 0)
    m1Speed = 0;
  if (m2Speed < 0)
    m2Speed = 0;
  if (m1Speed > MAX_SPEED)
    m1Speed = MAX_SPEED;
  if (m2Speed > MAX_SPEED)
    m2Speed = MAX_SPEED;

  motors.setSpeeds(m1Speed, m2Speed);

  //if (distance <20){
  //  motors.setSpeeds(0,0);
 // }

////////////////////////////////////////////

  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

}

It is quite likely due to blocking. The description of the pulseIn() function in the Arduino site's reference section says:

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is
HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts
timing, then waits for the pin to go LOW and stops timing. Returns the
length of the pulse in microseconds or gives up and returns 0 if no
complete pulse was received within the timeout.

If you can limit the range within which you want to stop the vehicle, try setting a timeout on pulseIn() that will return control once the maximum sound travel time has passed. Maybe that will give you enough response to correct the vehicle's steering. Slowing the vehicle's velocity will help, too (it won't be able deviate as far from it's path as quickly).
Otherwise, you'll probably need a non-blocking equivalent to pulseIn().

There’s an article on this topic here https://roboticsbackend.com/arduino-pulsein-with-interrupts/

Thank you so much! this answer really helped and finally fixed the issue using your advice. Thanks again!


text:
how to set the arduino due adc automatic trigger
How do I trigger automatic conversion on the ADC on the DUE? If this was the uno, I could just do
 sbi(ADCSRA,ADATE); sbi(ADCSRA,ADSC);
but for the due, I seem to have to use
adc_configure_trigger(ADC, ADC_TRIG_SW, 0);
Though I am not seeing an auto trigger option, only software/external triggers. Will it just know to start conversion once it sees data coming through?

Adc has register ADC_MR (adc mode register) and also flag FREERUN...

so would setting adc_configure_trigger(ADC, ADC_MR, 1);  set up automatic trigger?

I'm not sure, maybe. Or maybe adc_configure_trigger(ADC, ADC_TRIG_SW, ADC_MR_FREERUN_ON);