text:
SSD1306 unable to display Text and waveform cohesively.Why?
Here is my code I am collecting data using an ECG sensor and trying to enhance the incoming data by stretching it across the x axis. Which results in this.

After this the screen eventually just goes black. What am I doing wrong?
This is my code.
#include <U8glib.h>
U8GLIB_SSD1306_128X64 u8g(12, 11, 8, 9, 10);
int Buffer[128];int Buffer2[128];int max=0;
//int largest;
void pageECG();     // Page-1

const int pageCount = 2;
int p;
void (*pages[pageCount])() = {pageECG};
int duration [pageCount] = {10000};
void setup() {

  u8g.setFont(u8g_font_unifont);
  u8g.setColorIndex(1);
  p = 0;
  Serial.begin(9600);

}

void loop()
{
u8g.firstPage();
  do {
    (*pages[p])();
  } while( u8g.nextPage() );
  delay(duration[p]);
  p = p+1;
  if (p == pageCount)
    p=0;
}
void pageECG() {
for(int x = 0;x < 128;x++)
{
Buffer[x] =(analogRead(A0)*0.075);//This loop takes data input
delay(5);
if(Buffer[x]<32&&Buffer[x]!=2)
x-=2;
if(Buffer[x]>32&&Buffer[x]!=62)
x+=2;
Serial.println(Buffer[x]);
}

for(int x = 0;x < 127;x++)
{
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 60, "ECG");
u8g.drawLine(x, Buffer[x], x,Buffer[x+1]); //OP to OLED for BP

}}

Can you explain me what you are doing in the for loop where the data is read in? You manipulate the index variable x in a way that it is possible you get negative indexes. Also only three cases store a value subsequentially, i.e when the read value is 2, 32 or 62. In all other cases the index is recomputed. It's complete unpredictable, what this algorithm does. And the output you showed us is possible. The drawLine is also suspectable to me, shouldn't it be u8g.drawLine(x, Buffer[x], x+1,Buffer[x+1]);. I changed the 2nd x to x+1. And, I don't see code to clear the page before redraw.

Well, one problem is this: You have made an array of pointer to function, but only initialized the first of the two, to pageECG.
const int pageCount = 2;
int p;
void (*pages[pageCount])() = {pageECG};

The last line there roughly equivalent to:
void (*pages[pageCount])() = {pageECG, nullptr};

Later in loop() you have:
  u8g.firstPage();
  do {
    (*pages[p])();
  } while( u8g.nextPage() );
  delay(duration[p]);
  p = p+1;
  if (p == pageCount)
    p=0;

After the first execution of loop(), p is 1.  Since it was not 2, it was not reset by your if (p == pageCount) p=0;  So on the next pass through loop(), (*pages[p])(); is     (*pages[1])();  where pages[1] is nullptr.
In practice, what you're doing is generating and executing an AVR icall (indirect call) instruction to address 0x0000 (nullptr representation) to the reset vector.  So, your sketch starts over almost like a reset, except the hardware has not been reset.  Importantly, the interrupts are still configured as they were and the global interrupt flag is on, which means all manner of potential weirdness if one of them manages to execute before you get back ground setup().  So, it's difficult to say exactly why you're seeing what you're seeing.  But, it doesn't surprise me as a potential outcome.  And it may not be the only problem; just a problem.


text:
How to control multiple servo motors at the same time with protothreading using an I2C PCA9685 PWM board?
I'm trying to use protothreading to control two (and eventually four) servo motors over I2C using a PCA9685 PWM board.
To start, I am simply trying to sweep the two motors back and fourth at the same time.
Here is the code I am using:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#include <protothreads.h>

#define SERVOMIN  150
#define SERVOMAX  600
#define USMIN  600
#define USMAX  2400
#define SERVO_FREQ 50

int servo1 = 0;
int servo2 = 4;

////////////////////////     T H R E A D    1     /////////////////////////

pt ptServo1;
int Servo1Thread(struct pt* pt){
  PT_BEGIN(pt);
  for(;;){
    for (uint16_t microsec = USMIN; microsec < USMAX; microsec++) {
      pwm.writeMicroseconds(servo1, microsec);
    }
    PT_SLEEP(pt, 500);
    for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) {
      pwm.writeMicroseconds(servo1, microsec);
    }
    PT_SLEEP(pt, 500);
  }
  PT_END(pt);
}

////////////////////////     T H R E A D    2     /////////////////////////

pt ptServo2;
int Servo2Thread(struct pt* pt){
  PT_BEGIN(pt);
  for(;;){
    for (uint16_t microsec = USMIN; microsec < USMAX; microsec++) {
      pwm.writeMicroseconds(servo2, microsec);
    }
    PT_SLEEP(pt, 500);
    for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) {
      pwm.writeMicroseconds(servo2, microsec);
    }
    PT_SLEEP(pt, 500);
  }
  PT_END(pt);
}

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

void setup() {
  Serial.begin(9600);
  PT_INIT(&ptServo1);
  PT_INIT(&ptServo2);
  pwm.begin();
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);  // Analog servos run at ~50 Hz updates
}

void loop() {
  PT_SCHEDULE(Servo1Thread(&ptServo1));
  PT_SCHEDULE(Servo2Thread(&ptServo2));
}

I am noticing that Servo 1 turns to -90 and stops. While it has stopped, Servo 2 turns to -90 and then stops....then Servo 1 turns to +90 and stops and so on. They are not doing the sweeping at the same time.
Any help would be greatly appreciated!
Thank you,
H

Without knowing Protothread in detail: It is most likely handling the threadchange during PT_SLEEP(), which you are only executing after one "sweep" (one of the inner for loops), not giving any opportunity to change to the other thread.
Additionally this way you don't have any delay in the inner for loops, thus they get executed very fast. Faster than the motor really can follow. This means, that the servo just moves to the end position as fast as it can and the for loop is essentially useless. You need a delay inside the inner for loops for slowing the signal down.
Please try something like this:
pt ptServo1;
int Servo1Thread(struct pt* pt){
  PT_BEGIN(pt);
  for(;;){
    for (uint16_t microsec = USMIN; microsec < USMAX; microsec++) {
      pwm.writeMicroseconds(servo1, microsec);
      PT_SLEEP(pt, 50);
    }
    PT_SLEEP(pt, 500);
    for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) {
      pwm.writeMicroseconds(servo1, microsec);
      PT_SLEEP(pt, 50);
    }
    PT_SLEEP(pt, 500);
  }
  PT_END(pt);
}

Change the sleep time in the inner loop according to your wanted sweep speed.

Thank you for your answer! Curiously, once I add PT_SLEEP(pt,50) inside the for loop as you suggested, nothing happens. The motors do not move at all...is it possible that protothreading does not work with I2c perhaps?

You might have to make the sleep time significantly lower (havent registered before that you write the microsecond range from 600 to 2400 with step size of 1) or increase the step size from 1 to a higher number. With the current setting it might just take too long to notice the movement

source: Stack Exchange

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

sort: votes


text:
Flash HEX onto an Arduino board
The scenario: I have built a device off an Adafruit nRF52840 and I need a way to deploy firmware updates. I have delivered the device to my end user and will need to periodically send him updates.
I do not want to send him source, and he isn't technically savvy enough to compile and upload using the Arduino IDE anyway.
Searching around I see lots of suggestions to use avrdude command line to push a hex file to the board. The issue I have is my user is not going to be up for running command line... if its not a click next installer he's basically lost. I could create a BAT file and distribute a zip containing the BAT and HEX files... he double clicks the bat file and it pushes the hex to the board. This would be an acceptable solution.
My issue is the port number. Every example I am seeing of using avrdude command line includes a parameter along the lines of: "-PCOM21".
My user is not going to know what comm port the device is plugged into... and even if they knew that I dont think I can ask them to go edit the BAT file with the correct -PCOM value.
There has to be a simple solution to allow an end user to push hex firmware to Arduino boards? I am just not having much luck finding it. Is there a product that does this I should look at or could you point me to a solution?

In practice, does the port number change?

look at the Info section at https://github.com/dotKokott/listComPorts-csharp

turn on verbose mode in IDE and see the external command executed by the  IDE. you can use the same command

the UF2 bootloader allows drag and drop update https://github.com/adafruit/Adafruit_nRF52_Arduino#bootloader

There are several hex file loaders for the Arduino based Arduboy. Maybe the source for one of those can be modified to suit?

https://stackoverflow.com/questions/39043186/how-to-get-only-the-currently-used-serial-com-port-name-for-a-specific-usb-devic

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


text:
Arduino Uno to drive 2 unipolar stepper motors
I need to use two stepper motors to move microscope positioning knobs in the X/Y direction. The stepper motors I have are unipolar and are 6V rated (I think).
I know it's possible to drive a unipolar stepper motor via a ULN2003 using an Arduino Uno. I know I can wire it using the 2-wire or 4-wire method.
But my questions are:
Is it possible to drive 2 of them? What are the modifications I will need to make to the circuit? Will this harm my Arduino? Do I need a stepper motor shield?

No problem. Just use two ULN2003 chips, one for each stepper.
No need for a motor/stepper shield on these unipolar steppers.
It will not harm the arduino (if wired correctly).

Two fully independent unipolar-stepper axis will require two chips, as these have only 7 channels while unipolar steppers require four each.

@ChrisStratton Good catch. That's what I meant to say. Bad wording on my part. Edited it.

I'd suggest to have a look at the EasyDriver stepper motor drivers developed by Brian Schmalz. They are easy to set up and do support microstepping, which might be interesting for a more fine control of the microscope.

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


text:
ESP8266 01 doesn't react after baud rate change
Hello guys I have my ESP8266 connected to my Arduino. Then I typed in AT in the serial monitor. It confirmed this command with OK. After that I typed in  AT+UART=9600, 8, 1, 0, 0 which gave me the response ERROR. Then I googled what I could do, which told me that I should try change the baud rate permanently with the command AT+IPR=9600. I  did this but I got no response. After that I wondered if everything was ok so I typed in AT. No response. Now I'm a little bit sad because everything started to be great but I don't know how I can fix the whole problem. I also tried to upgrade its firmware with XTCOM Utility but it says it can't connect.
#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2, 3); // RX | TX

void setup() {
  Serial.begin(115200); // communication with the host computer

  //while (!Serial) { ; }

  // Start the software serial for communication with the ESP8266

  ESPserial.begin(115200);

  Serial.println("");

  Serial.println("Remember to to set Both NL & CR in the serial monitor.");

  Serial.println("Ready");

  Serial.println("");

}

void loop() {
  // listen for communication from the ESP8266 and then write it to the serial monitor

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

  // listen for user input and send it to the ESP8266

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

This is my code. I tried it with both 9600 and 115200 but if I use 115200 the serial monitor just shows some garbage signs. It's kind of frustrating because I can't even interact with the serial monitor as my typed commands don't show up anymore. Do you have any idea how I could fix this problem?

did you use ESPserial.begin(9600);?

Yes I tried that but it still gives me the same problem. It didn't gave me the rubbish like with 115200 but it still doesn't respond

It is quite common for changing the baud rate to cripple an ESP-01. The only cure is to reflash it.

If you feel lucky you can play around with different baud rates and see if you find one. The part has a default baud but I do not remember it but it is in the literature.

Alright so how do I reflash it?

I tried flashing it but it shows "Failed to connect"


text:
Connect ESP8266 with Android Studio App
Hey guys I have ESP8266 and want to remote control a sailboat with it. Till now it works fine but how is it possible to send continuous data between the Arduino/ESP8266 and my smartphone? If you need any further information just add a comment.
Thanks guys

Do you have an ESP8266 dev board like a NodeMCU or an Arduino plus an ESP8266 with AT firmware on it? The design of the project is up to you, but normally you would let the ESP create a wifi access point, connect with the smartphone and then send messages over the network via websockets or similar (also depending on the question above)

@chrisl, why 'web'? plain TCP socket or UDP will be faster

@chrisl I use Arduino Uno + ESP8266


text:
ESP8266 ESPAsyncWebServer LittleFS crashes
I am trying to write a simple web page to be served from my ESP8266 based on this tutorial: https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
However I got a warning saying:

SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.

So I thought I would try using LittleFS as a drop in replacement for SPIFFS, it seemed to be working fine but noticed issues with larger files straight away, the ESP8266 would crash frequently but not consistently, however image files even of smaller sizes would fail to load. Anyway I switched back to SPIFFS and everything seems to work fine as the tutorial suggested it would, can anyone tell me what issue with LittleFS I might be experiencing and if it can be fixed?
Also is it bad practice to use SPIFFS even though it seems to work fine?
Thanks

I still use SPIFFS, it works and there's nothing "wrong" with it, especially if you have a lots of little (<4kb) files or you want code that runs on the 8266 and 32 both. If you have large files, littleFS is about 5x faster to read and write. If you're directly shipping the whole file over wifi, the wifi part is going to be slower than either filesystem's access.


text:
Using L298n motor driver without jumper (Voltage Regulator)
When I am using 9V supply with motor driver and Jumper connected so the red LED was blinking but when I did the same using 9V and 15V supply removing the jumper LED didn't blink.
Neither the voltage nor the current drop across the motor was observed. And I didn't found any documentation for using L298n using without a jumper.

You need to provide a link to that specific driver board. The L298N is only the H-bridge chip on it. The circuit around it (including the jumpers and headers) is specific to that board. Please include that link in your question (by editing it)

The jumper controls whether or not the on-board 5V regulator is used to power the on-board logic. With the jumper removed the board needs an external 5V supply in addition to the motor power supply.

Is your Arduino ground connected to the 15V power supply ground?


text:
NRF24L01 modules fail to stay connected. Work intermittently
I am trying to get the NRF24 Modules to work but all I get is short lived moments of when it works. I am using the transmitter to send signals to the receiver, which in turn sends a signal to the Motor Controller module to spin the motor.
Both the transmitter and receiver are connected on Nano Every's. Currently they both Arduinos are powered with 9v batteries with the NRF24 modules connected to the 3.3v pin. Both NRF24 modules have 10uf caps connected. I double checked for connections issues and shorts.
Sometimes the Rx and Tx connect and the motor spins correctly and everything is fine. This lasts only a few moments before it stops responding again. Usually it happen when I connect the USB to the transmitter to see what the Serial console is printing. Once I open up the Serial monitor it might, if I am lucky, connect and work for a bit.
I don't have any reason to believe that it is a connection issue since it sporadically works as intended. I can post a diagram if needed. If anyone has any clue I'd appreciate the help.
Here is my Tx code:
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

const byte ledPin = 5;

RF24 radio(7,8); //CE, CNS
const byte address[6] = "00001";
const int button = 3;
int buttonPressed;

int joystick;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening(); //transmitter

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
radio.printDetails();

}

void loop() {

  // put your main code here, to run repeatedly:

  joystick = analogRead(A1);
  Serial.println(joystick);

  if(joystick > 530)
  {
    motorForward(joystick);
  }
  if(joystick < 480)
  {
    motorBackward(joystick);
  }
  if(joystick >= 480 && joystick <= 530)
  {
    motorStill();
  }

}

void motorBackward(int jsInput)
{
 //digitalWrite(motorPin1, LOW);
 //digitalWrite(motorPin2, HIGH);
 int motorSpeed = map(jsInput, 480, 0, 0, 255);
 int message[] = {2, motorSpeed};
 radio.write(&message, sizeof(message));
 //analogWrite(motorPWM, motorSpeed);

 delay(20);

}

void motorForward(int jsInput)
{

 int motorSpeed = map(jsInput, 530, 1023, 0, 255);
 int message[] = {1, motorSpeed};
 radio.write(&message, sizeof(message));

 delay(20);

}

void motorStill()
{

    int message[] = {0};
    radio.write(&message, sizeof(message));
}

Here is my Rx code:
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#define motorPWM 6

RF24 radio(7,8); //CE, CNS
const byte address[6] = "00001";

byte motorPin1 = 4;
byte motorPin2 = 5;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();

 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPWM, OUTPUT);

 //test motor
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPWM, 600);
Serial.print("Test motor started");
delay(2000);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, LOW);
Serial.print("Test motor complete");
radio.printDetails();

}

void loop() {

  // put your main code here, to run repeatedly:

if(radio.available())
{
   //0 = still, 1 is forward and 2 is backward
  int message[2];
  Serial.println("radio detected");
  radio.read(&message, sizeof(message));
  Serial.println(message[0]);
  Serial.println(message[1]);

  if(message[0] == 1)
  {

    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    analogWrite(motorPWM, message[1]);
    delay(20);
    Serial.println("move forward");
  }

  if(message[0] == 2)
  {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    analogWrite(motorPWM, message[1]);
    delay(20);
  }

  if(message[0] == 0)
  {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    delay(20);
  }

  Serial.println("radio available");

}

}

what kind of 9 V batteries are you using? ... these are only good for very low power applications, such as smoke alarms ... https://duckduckgo.com/?q=9v+block+battery&iax=images&ia=images

I am using recharable 600mAH 9v batteries. Would a USB connection be enough?


text:
How can I rename how my Arduino UNO (or any other Arduino) shows up on the computer?
I need to rename my Arduino UNO in a way that when it connects to the computer then it reads not as "Arduino" in device manager but as "My instrument name". I need to know how to do this on an UNO and Pro micro specifically but also on other arduinos. Please also suggest if there are other development boards available where names is not preprogrammed but programmable. Thank you.

For the Pro Micro, have you tried something like this (found by googling for "Arduino change PID")? For the Uno you would need to reflash the Atmega32u4 chip, that is responsible for the USB communication. Thats a bit more hacky, but there are tutorials for that online.

If "the computer" is a Linux computer you can create UDEV rules.  For example, you may, based on which USB port you plug your Arduino into, control most aspects of the USB connection.  In this way  you wouldn't have to change the PID or VID of the Arduino.  But the question should then be posted in a Linux stackexchange site.


text:
Controlling Bluetooth voice-controlled car with ultrasonic sensor
I am trying to use an ultrasonic sensor to stop a tiny voice-controlled car but I can't get it to work. once the motor starts moving it doesn't stop I'm trying to make the car stop moving even though it is already in motion. I need help writing a proper if statement or while loop to make the motor stop when there is an obstacle in its path.
#include <SoftwareSerial.h>

SoftwareSerial BT(0, 1); //TX, RX respetively
String readvoice;
int IN1= 3;
int IN2= 4;
int IN3= 5;
int IN4= 6;
int trigpin= 12;
int echopin= 11;
int pingTraveltime;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(trigpin, OUTPUT);
pinMode(trigpin, OUTPUT);

}
//-----------------------------------------------------------------------//
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
readvoice += c; //build the string- "forward", "reverse", "left" and "right"
digitalWrite(trigpin,LOW);
delayMicroseconds(10);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
pingTraveltime=pulseIn(echopin,HIGH);
Serial.println(pingTraveltime);
}
if (readvoice.length() > 0) {
Serial.println(readvoice);

if(readvoice == "*forward#")
{
while(pingTraveltime>500){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
}

else if(readvoice == "*back#" )
{
digitalWrite(IN1, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN4,HIGH);
}

else if (readvoice == "*left#")
{
digitalWrite (IN1,HIGH);
digitalWrite (IN2,LOW);
digitalWrite (IN3,LOW);
digitalWrite (IN4,LOW);

}

else if ( readvoice == "*right#")
{
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);

}

else if (readvoice == "*stop#")
{
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);
}

readvoice="";}} //Reset the variable

first thing to do, format the code properly ... please use correct indent levels for each block ... you can press ctrl-T in the Arduino IDE for auto format


text:
What is the advantage of higher priced arduinos to cheaper ones?
I just got an Arduino Mega ADK (which seems to be functional, based on my limited testing and knowledge) at a yard sale for under $5. I don't have any Arduino experience, but I'm into DIYing, so who not try it.
I noticed that this specific board has a noticeably higher price than the other models. That would be, comparing brandname models to others brandname models, OR offbrand to offbrand.
My question is, why would someone prefer the higher priced models over the more simple/cheaper ones? My guess would be power consumption, I/O, capabilities, or processing speed. But I think I heard that the processing speed of the slower boards is already enough to run most projects, or am I wrong?

why different cars, different computers, different phones, different houses ...

You are right in your guesses. The Mega specifically is often used for its many pins and for the 4 hardware serial interfaces. The Pro Micro is often used, because it has a native USB interface (can act as different USB devices) in contrast to the Uno, Nano and Mega. So the different boards have different capabilities, use different microcontrollers, have different forms, and are thus better for one purpose than for the other

People buy the board that does the job they want it to do and provides the support and reliability they need for their project.

the higher price of Mega ADK is because of ADK

Usually because they don't understand I2C or SPI and want to hook up mounds of the absolute cheapest parallel interface gear to the MCU without writing any code themselves.


text:
Connect 4 HC-12 transmitters to 1 HC-12 receiver
I am currently receiving data from HC-12 modules via USB-TTL that are working in pair . But I want to receive data simultaneously from 4 Hc-12 modules to a single HC-12 module via USB-TTL.

so, what is your question?

how can i connect 4 HC-12 transmitting modules to 1HC-12 receiving module

I don't really understand. Those are wireless modules, they're already "connected" as long as they are in range. What problems are you having receiving the signals ?

yes i am having problem receiving the signals. even though both the receiving and transmitting module have same channel FU and baud rate

Well show a schematic of how you have things wired up, and show the relevant pieces of code for the receiver and transmitter. (Please [edit] your question for that.) There's not enough information here.

there isn't coding for this . check data sheet for HC-12

https://www.elecrow.com/download/HC-12.pdf

The problem with multiple transmitter mostly resides in the collision risks. On networking contexts like Ethernet, There is a collision detection protocol making transceiver know that a problem arises, but that doesn't exist with HC-12, so you need something else.
In air contexts like this one, another solutions might to minimize chances of collisions restraining onself to a low bandwidth percentage (e.g.: not more that 10% of the total time) and just ignore lost packets.
However, if you cannot ignore lost packets, you need to implement a synchronisation protocol between receiver and transmitters. A solution would be to make some kind of token bus, where your receiver would poll each transmitter each on his turn to see if it has something to send.
However, since it is not recommended (and sometimes not even legal) to use to much time slices, you should avoid continuously polling all the transmitters.
In this case, what I suggest is that each transmitter can "wake up" the receiver by sending an unattended message. If this doesn't not cause reaction, this is interpreted as a collision detection. Then the transmitter wait for a specific delay (each one having a different delay value) - or a random delay.
When the receiver receives this packet it processes it, Then polls all the other transmitters, and then goes back to sleep mode, until the next time.
If the packets are long it might be better to have a short wake-up packet and to send the real data during the polling phase, and if the packets are short, you can just use the collision avoidance mechanisme alone.

When a HC-12 is transmiting all other HC-12 in his range (using same frequency) are receiving. So if you want your transmiter to talk to one specific HC-12 then to an other and so on, you have to create a kind of "message protocol".
Let's say you have an Arduino with a HC-12 and 4 buttons and want to turn on-off 4 lights, each connected to a HC-12. You can use a binary representation, so a byte, on which each bit as a meaning.
Bit 0 -> at 1 -> turn on the light at 0 turn off
Bit 1-2 -> give the number of the HC-12
So 00000111 -> message for HC12 number 4, tell it to turn on the light.
ALL HC-12 will receive the message. So each has to check the incoming byte to see if "it's for me" or nor.
If you want one HC-12 to receive from many HC-12, that's the same: the message must contain the "id" of "who is sending".


text:
HC-05 bluetooth module stops working when blinking
I'm using this HC-05 Bluetooth module to communicate between my Arduino mega 2560 and my laptop. I am using processing to send the data from my computer to the Arduino.
The module connects nicely and start blinking and when it is paired with my computer it blinks twice every seconds. The problem is that every time the module blinks twice, it ignores the data I am trying to send. Everything else seems to work fine.
Does anyone why this is happening and what I can do to avoid it?
Here is the arduino code:
/*
 * bluetooth_rbg_led.ino
 * Uses bluetooth communication to adjust the
 * values of an rgb LED.
 *
 * Sahibjot Singh
 * July 2021
 */

// Servo library to control servos
#include <Servo.h>

// Global variables
Servo servo;
const byte servoPin = 2;
int servoAngle;

// Exeuctes once, at the start
void setup() {
  // Attaches the servo to it's pin
  servo.attach(servoPin);
  servo.write(0);

  // Begins the serial communication with the
  // bluetooth module at pins 18 and 19
  Serial1.begin(9600);
}

// Loops infinitely
void loop() {
  // Reads the values from the serial port
  if (Serial1.available()) {
    servoAngle = Serial1.read();
  }

  // Writes the value to the led pin
  servo.write(servoAngle);
}

Here's the processing code:
/*
 * bluetooth_rgb_led.pde
 * Simple program to take user input and
 * write it to the serial port.
 *
 * Sahibjot Singh
 * July 2021
 */

// The library needed to write to the serial port
import processing.serial.*;

// Serial variables
Serial port;
int servoAngle;
int userInput;

// Slider variables
int sliderX = 100;
int sliderY = 195;
int sliderWidth = 400;
int sliderHeight = 10;

// Slider rect variables
int sliderRectX = 100;
int sliderRectY = 175;
int sliderRectWidth = 50;
int sliderRectHeight = 50;

// Executes once, at the start
void setup() {
  // Makes the window 600 pixels by 600 pixels
  size(600, 600);

  // Starts serial communication
  port = new Serial(this, "COM7", 9600);
  port.bufferUntil('\n');
}

// Loops infinitely
void draw() {
  // Gets the input from the slider
  if (mousePressed && mouseX > sliderX && mouseX < sliderX + sliderWidth &&
      mouseY > sliderY - 20 && mouseY < sliderY + sliderHeight + 20) {
      sliderRectX = mouseX - sliderRectWidth / 2;
      userInput = sliderRectX - (sliderX - sliderRectWidth / 2);
      servoAngle = (int)map(userInput, 0, 400, 0, 180);
  }

  // Writes the LED value to the serial port
  port.write(char(servoAngle));

  // Clears the window
  clear();
  background(200, 200, 200);

  // Draws the slider
  stroke(30);
  strokeWeight(2);
  fill(150, 150, 150);
  rect(sliderX, sliderY, sliderWidth, sliderHeight, 10);
  fill(255, 0, 0);
  rect(sliderRectX, sliderRectY, sliderRectWidth, sliderRectHeight, 10);

  // Draws the text on the side of the slider
  fill(255, 255, 255);
  textSize(32);
  text("0", 50, 210);
  text("180", 530, 210);

  // Draws the text about the led's brigthness
  fill(0, 0, 255);
  textSize(40);
  text("Servo Angle: " + Integer.toString(servoAngle), 100, 320);
}


text:
Arduino IDE Doesn't Detect Installed Library Dependency
I am trying to edit an old code for a dot matrix display. This code was written on Arduino IDE in Windows 10, for DOIT ESP32 DEVKIT V1. I never had a problem with libraries in the Windows environment but it started breaking up when I am trying to install the necessary libraries in Linux Mint 22.
I would prefer to install it using the LIBRARY MANAGER (rather than manually extract a zip file in the include folder) so the IDE knows in its own way which libraries are installed and to avoid having similar dependency conflicts in future.
Problem: When I press "Install" button on the MD_MAXPanel library, an error pops up saying, among other things, "MD_MAX72xx is not available". You can see it right there, version 3.5.1 already installed and reported by the same LIBRARY MANAGER that says it's not installed. There is a folder with that name in the libraries folder among others. I have restarted the IDE several times but it doesn't help. All my libraries and boards are installed up to date.
Question: How do I install "MD_MAXPanel" library through the Arduino IDE LIBRARY MANAGER?

Just guessing... This looks like a case-sensitivity problem to me:
the MD_MAXPanel library repost a dependency on MD_MAX72xx
(lowercase xx), whereas MD_MAX72XX explicity states its name is
MD_MAX72XX (upppercase XX). I guess Windows does not care, as
it uses a case-insensitive filesystem.
I suggest you report this inconsistency to the author of these
libraries, maybe with a pull request fixing the depands= line of
MD_MAXPanel. In the mean time, you may try to create a symlink in your
libraries directory, from MD_MAX72xx to MD_MAX72XX.

I don't think it's a case problem. I changed the library name to lower case xx in the file name, folder name, and in the library.properties file but it doesn't seem to work.

@pakieng: I would avoid renaming an existing library: this one is already known as MD_MAX72XX by the Arduino IDE (it should be listed in a file named library_index.json). You could try changing the depends= line in MD_MAXPanel instead.

@pakieng Edgar Bonet is completely correct about it being a case problem and a problem on the part of the library author. He is also correct about editing  library_index.json. Within about 45 minutes of you posting the question I'd verified this. But you asked how to do this in the IDE, and this is more work than using manually installing or using arduino-cli lib install --no-deps MD_MAXPanel (which also works), so I figured you wouldn't be satisfied with it as an answer. But since he's provided an answer and you haven't accepted it or voted it up, I will.

@pakieng Also, only editing the dependencies key in library_index.json in the arduino15 directory mattered. The library author would need to edit their library.properties in order to make the indexer produce the correct entries in library_index.json. Unfortunately editing library.properties locally has no effect.


text:
Always HIGHT line on Oscilloscope when UNO's Fast PWM TOP ICR1
I have been trying to get an answer my question for a 2 days already. It's good for knowledge collecting and playing with different things, but there haven't been a solution so far.
I'm trying to leverage the HXT500 Servo with the Fast PWM with a TOP ICR1
I'm using the DFRobot DFRduino UNO v3.0 (R3) analog of the Arduino UNO. Based on the Atmega 328P-PU
I have an Oscilloscope till 5 MHz as additional tool
Question

Why the Fast PWM, TOP ISC1 always has the HIGHT only on a oscilloscope
Why the Clock Prescaler doesn't work

My investigations & observations
I activated the PWM with TOP ICR1 but on my oscilloscope showed only a 5V straight line, I checked different diapasons (horizontal bases) (1a). Connected to pins 10 or 9. I assumed that my UNO works on 1 MHz (9.2.1 Default Clock Source on Page 37) and calculated ICR1, OCR1A:B for 0 and 180 degree.
     void setup() {
      // all as Ports (for outputs)
        DDRB=0xFF;
        DDRC=0xFF;
        DDRD=0xFF;

      // Table 16-4 on Page 141
      // Fast PWM TOP is ICR1
      TCCR1A|=(0<<WGM10)|(1<<WGM11);
      TCCR1B|=(1<<WGM13)|(1<<WGM12);
      ICR1=2499;

      // Table 16-2 on Page 140
      // Clear OC1A/OC1B on Compare Match, set OC1A/OC1B at BOTTOM (non-inverting mode)
      TCCR1A|=(1<<COM1A1)|(1<<COM1B1);

      // Table 16-5 on Page 143
      // clkI/O/8
      TCCR1B|=(0<<CS12)|(1<<CS11)|(0<<CS10); // (2a)
    }

    void loop() {
      digitalWrite(LED_BUILTIN, HIGH);
        // 90 degree
        OCR1A=299;
        OCR1B=299;
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
        // 0 degree
        OCR1A=49;
        OCR1B=49;
      delay(1000);
    }

There I noticed the following issues:

I tried different Prescales - there weren't any differences (2a)
I tried 1 MHz, 8 MHz, 16 MHz - straight HIGHT line

What I have tried next:

To use an Example for Servo leveraging from Arduino IDE. It worked but as I understood it worked via Interrupts, not a Hardware solution
To use Fast PWM, 9 & 10-bit. (2a) Prescales didn't work - I had movement
To use Fast PWM, 8-bit (with code adjustment and wrong angles). (2a) Prescalers didn't work - I had movement

A 5MHz oscilloscope likely can not resolve a 5MHz square wave.  What you may see is a distorted wave closer to a sin wave than a square wave.  You may not see anything but the DC component of higher frequency signals.  I don't know why you only see 5 volts when you are expecting a wave form or voltage less than 5 volts.  There maybe something wrong with the code, hardware, connections or you may have your oscilloscope AC coupled.

@st2000, thanks for your attention and comment
The wave explanation - yes, it makes sense,  I   didn't think in this way, thanks
Considering possible issues: connections - it's fine, because in another modes it works w/o changing these connections
hardware - possible, but I don't know how to check it, but with the Fast AWM 9-bit it works
Interestingly: there is the same/similar issue with Normal, CTC modes
Code - it would be easiest reason )

You might want to set the TCCR1A and TCCR1B registers to 0 before your code as the Arduino library sets the WGM10 bit. Or change the first |= to a =. By leaving the WGM10 bit set, you get fast PWM mode, with TOP set to OCR1A. Combined with your other code, this would result in both pins having a 100% duty cycle.
So use
TCCR1A=(0<<WGM10)|(1<<WGM11);
TCCR1B=(1<<WGM13)|(1<<WGM12);

or
TCCR1A=0;
TCCR1B=0;
TCCR1A|=(0<<WGM10)|(1<<WGM11);
TCCR1B|=(1<<WGM13)|(1<<WGM12);

Other than that, you code looks fine, and should give you a 800Hz signal.
PS "I assumed that my UNO works on 1 MHz"; no, the UNO runs at 16Mhz.

thanks. I very appreciate the time that you spent here.
I have tried and it started working, but with some shift, because there were that wrong assumption, that you mentioned, about the System Clock Speed
Currently, the fast PWM TOP ICR1, Prescaler work and the math is matched


text:
VCNL4000 Proximity/Light sensor
I want to use the VCNL4000 Proximity/Light sensor s.
http://www.adafruit.com/products/466?&main_page=product_info&products_id=466
In the package i've this 6 pin connector but the VCNL has 5 pins (i now i can connect it by myself with male jumper) but  what am i missing here?
I assume that it is not an "accident" that the thing has one more pin then the sensor ; )

You can just cut off the extra pin. Adafruit probably just had a bunch of 6 pin headers in their stock.

Many thanks, i thought i overseen something important :)

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


text:
Data Report Which Technology
I want to create a small position reporter for cars. I found some good GPS Modules with which i could collect data. But i'm unsure with what technology i should send the data.
A possibility would be to setup a service in the www which is feeded by the arduinos.
I want to track the data live. so i think GPRS should be the right choice ?
Or more better are there any shields which make this GPRS LOG and SEND as a package ?
Which GPRS hardware would you use ?
Would you use something else?
Any hints are very welcome

You can actually find all the information for what you want to do on the formal Arduino.cc website. They suggest a GSM shield:

But of course you can find many other GSM shields for purchase. Most of them works the same. Arduino.cc also offer a nice GSM Library, with which you can perform HTTP GET/POST queries to a remote webserver (visible over the web).
You can select whatever web server technology you prefer for receiving the data. Using NodeJS, PHP, MVC.NET or any other, you could expose a REST API to perform the update from the Arduino+GSM Shield side using HTTP.
The web server then could analyze the incoming data and display it in any way you like.

I would add that feeding datas in www through an internet access is going to put some undefined time delay in recording and forwarding datas online. And this is what he wants to achieve.

I think that the average GSM latency can be considered to be 'live', as much as any other online service/game you used on your smartphone

yes. With live i mean "where has it been in the last minute or so"


text:
NodeMCU serial port - use with computer and device at the same time
I'm trying to understand how serial communication for ESP8266 in NodeMCU actually works. I found a quote saying that normal Serial is mapped to ports GPIO 1 (TX) and GPIO 3 (RX). They are even labeled on the board like this, so I believe this is true.
However I'd like to understand the relationship between those pins and serial communication over USB. Does this work the same way as in normal Arduino where you can use either communication over USB or hardware serial on pins 0 & 1?
I did some tests and if I run simple program like:
Serial.begin();
//.......
Serial.println("Hello world");

I can see that in serial monitor on my PC. How does that impact serial communication on GPIO 1 & 3 ?

Yes, it is the same as Arduino. The TX and RX pins connect to a CH340G chip to convert the serial into USB. If you use USB serial you can't use the pins for anything else.


text:
Bluetooth module discovered by computer and not smartphones
I've been playing with Groove Bluetooth Module (HM-11) and for some reason my computer can see it, but none of my cell phones can.
I've tried two Huawei P7 (BL 4.0 + BLE) as well as some Samsung Galaxy & some older sony with Bluetooth 2.0. None of the cell phones can see the device. Any ideas?

If I'm not wrong cellphones need an app to search for BLE devices instead of the regular bluetooth manager of your phone

Are you configuring the module as a slave? A phone will typically act as a master, so it will only see slave devices.

I did configure it as master. I'll try with slave.

Handoko you are right - in order to discover BLE device you need an application. Usual android search is different from BLE search.

One other thing to note, some phones, the iPhone at least, will not show Bluetooth devices that do not advertise profiles supported by the phone. For instance, the HC-05 only provides the SPP profile which the iPhone does not support, so an HC-05 will not show up when scanning for BT devices.


text:
Lego Technic Servo Motor - 9V PWM
I want to control Lego Technic Servo Motor 88004.
The way it works is - Lego has a 4 cable connector. Two of them supply power (+9V & GND) and the other are optionally +9V and they are called C1 and C2.
Servo turns right or left max 90 deg when you supply PWM to either C1 ("left") or C2 ("right"). (or the other way round, but it doesn't really matter)
That basically means that what I need is a 9V PWM and be able to supply it to either C1 or C2. What is more the frequency has to be 1150 Hz.
Now the question is how do I achieve this goal?
I'm already using the L298N motor controller and happen to have one engine slot free.
1) If I can supply PWM from Arduino to "LNA" input in L298N - will it also cause the output to be PWM?
Because L298N has a transistor I have a feeling that the output is also going to be PWM unless there's something else there i.e. capacitor
Even if it's not does that matter at all - meaning is it going to still work?
2) How do I produce PWM with 1150 Hz from Arduino? My Arduino is 16MHz so I suppose that it should be possible to switch output with order of magnitude smaller frequency.
If what I'm trying to do makes no sense please try to point me to the right direction.

I'd be surprised if some web searching didn't turn up existing mentions of driving these motors from an MCU, perhaps even your Arduino's ATmega.  Even if you want to work it out yourself, this could be advantageous to research first as a cross-check on your beliefs about the signal properties.

My guess it that C1 and C2 will work just fine with only 5Volt.

The search did not return any instruction on how to drive the servo. There's a lot of articles about motors. Everything that I'm writing is based on research I did.

@gerben yes, but you can't do 90 deg and I'm worried about the max 5 mA current

Yes, the output will be a pwm. You can see it from the schematics.
you have few options, with different precision and complexity:

Configure one of the PWM HW blocks
Do it by sw in a loop
Use a timer to trigger a sw function - but it might be simpler to just configure the PWM HW block.
Use some existing library that will implement one of the methods I listed

I would recommend Option 1: it's not so difficult, you will learn something of the AVR internals and it will be the solution with the least overhead. You can have a look at this tutorial. There are also many others floating around.

Igor thank you very much for your answer! One more thing that bothers me - I suppose that when I'll be applying voltage to C1 then C2 should probably be floating and vice versa. If I simply connect C1 and C2 to outputs from L298N then the second one is going to be pulled to ground. I'll do some research to confirm if pulling the second one to ground is dangerous or not, but supposing it is - what would be the simplest option to avoid it? Using some kind of demultiplexer?

If you leave it floating, chances are that it can pickup some noise.
Checking the circuit is always he best course of action.
If you are worried about shorts, you can use a pull-down resistor, instead of connecting directly to ground.

According to this: https://www.youtube.com/watch?v=i_4d-XsgdA0 youtube video I can safely pull one of them to ground :) That means that using the motor bridge should be sufficient to be able to operate the servo :) About option 1 - the closest I can get to 1150 Hz is 1kHz but maybe I don't need to be precise about the frequency. Time will show..

If they work like the L298N (and that's a big if), they might even support the extra modes: both to ground for free spinning motor, both high for emergency arrest (the motor locks in place, beware of the current/voltage spikes).


text:
Read State from Variable
I am attempting to use radio modules to receive a value from a sensor, either 1 or 0, and complete an action. The only problem is that I would like the action to only complete once per state change, instead of every time (if it activates when the variable is 0, only activate again when the variable changes to 1.) Despite the != sign, the code inside the if statement will not activate even if the variables are reading 0 and 1.
// Keyboard - Version: Latest
#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_sv_SE.h>
#include <SPI.h>
#include "RF24.h"

RF24 myRadio (7, 8);
int mag = 2;
int prevState = 1; // 0=open, 1=closed

byte addresses[][6] = {"0"};

void setup()
{
  Serial.begin(9600);
  Keyboard.begin();
  delay(1000);

  myRadio.begin();
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ;
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}

struct package
{
  int val;
};

typedef struct package Package;
Package data;

void loop()
{
  if ( myRadio.available())
  {
    while (myRadio.available())
    {
      myRadio.read( &data, sizeof(data) );
    }
    // Serial.print("state: ");
    Serial.println(data.val);
    int state = digitalRead(data.val);
    // Serial.print("prevState: ");
    // Serial.println(prevState);
    // Serial.print("\n");

    if (state != prevState) {
      Keyboard.press(' ');
      delay(50);
      Keyboard.press(KEY_LEFT_GUI);
      delay(50);
      Keyboard.press('D');
      delay(50);
      Keyboard.releaseAll();
      Serial.println("Executed successfully.");

      prevState = state;
    }
  }
  delay(1000);
}

Try int prevState = -1; //-1= not initialized, 0=open, 1=closed

The payload of the radio packet appears to be the number of the digital pin on which the sensor is attached: int state = digitalRead(data.val); Is that what you intend?

please copy and paste the content of the serial console to your question above ... please no screenshots

Just out of curiosity, why are you including key definitions for the Danish, German, Spanish, French, Italian and Swedish keyboard layouts?

Consider using an enum for prevState instead of values 0, -1, 1; it makes the program easier to read/maintain.


text:
Using an I2C barometer
When buying a barometer for my current project at work, I chose the MikroElektronika click 3 barometer. However, as it turns out, the library for it doesn't exist for Arduino.
I know it uses I2C communication, so I tried connecting the board to my Arduino UNO R3 as follows:

simulate this circuit – Schematic created using CircuitLab
However, I do not know how to use the output of the sensor. Is there a way to access the raw data measured by the sensor and post-process it myself, or is a library needed?
Thanks for your help

Of course there is a way. There is a document called "Data Sheet" for your barometer IC and there should be everything about communication.

The datasheet for DPS368 is available at infinion site. You can use wire library to read the i2c data from it. There are also some information on Mikroe about the board configuration and some c snippets.

I have found MikroElektronika library for the barometer 3. You can get basic idea how to communicate with the sensor.
MikroElektronika c libraray
You can develop your own library based on that one for Arduino or you can read the data sheet of the sensor for more details.

You have an invalid link

I have fixed the link

Hi Arslan, thank you for your answer. However, it seems this library is only usable with MikroE compilers? Or is ther a way to import it on Arduino?

The code is in C, however, a quick looks at the library source file, it does allows to be compiled in C++.  So you need to copy the barometer3.c and barometer3.h into your arduino project file, copy the main.c to your project folder and rename it to barometer3.ino (or your project_name.ino), and modify it to the Arduino sketch format, and if compiler complains, do the modification to the source code or your sketch to make it work.

You need to modify the file to be able to use them


text:
Quaternion values from Arduino 9-axis motion shield seem very wrong
I am currently usinga BNO055 sensor fitted on the Arduino Nine-axis motion shield to measure ocean wave heights and periods. To do this, I'd like to use the quaternions provided, however I have a slight issue. A quaternion should be <cos(theta/2), Xsin(theta/2), Ysin(theta/2), Z*sin(theta/2)>, with X, Y and Z the coordinates of a unit vector and theta the angle of rotation around that vector. Therefore, I expect all three to be inferior to one.
However, when I run a simple code to see the raw data, the W given by my sensor when on the table is 16 375, and X, Y and Z values are in the high hundreds range...
This gives me a wave height of hundreds of thousands of kilometers :slightly_smiling_face:
Does anyone know why this happens? Do I need to divide the quaternion by it's norm to get the correct result? Or maybe I am misunderstanding the use of a quaternion?
Oh, and I have calibrated the sensor beforehand
Thanks in advance for your help

I am not familiar with this sensor, so I am just guessing.
The sensor is likely giving you fixed-point numbers. Judging from
the real part, there are most likely 14 bits right of the implicit
radix point. If that is the case, the actual quaternion can be computed
as:
float w = raw_w / 16384.0;
float x = raw_x / 16384.0;
float y = raw_y / 16384.0;
float z = raw_z / 16384.0;

You can check whether this is reasonable by computing the norm, which
should be very close to one.

Thank you so much, I didn't understand the explanation but your solution worked!


text:
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable
I have tried everything on this url
https://stackoverflow.com/questions/10165761/java-cant-connect-to-x11-window-server-using-localhost10-0-as-the-value-of-t
session output:
root@whale:/home/kermit# echo $DISPLAY
localhost:1.0
root@whale:/home/kermit# cd dev/sht30/
root@whale:/home/kermit/dev/sht30# arduino --upload sht30v1.ino --port /dev/ttyUSB0
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable.
        at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:102)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:61)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:101)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:83)
        at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:129)
        at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:231)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:588)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:583)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:582)
        at processing.core.PApplet.<clinit>(Unknown Source)
        at processing.app.Preferences.save(Preferences.java:735)
        at processing.app.Preferences.init(Preferences.java:249)
        at processing.app.Base.main(Base.java:117)

How do you run arduino in headless mode on a raspberry pi?

I know this doesn't solve your problem with the Arduino IDE, but if you want to do headless development on a raspberry pi, you might want to look into PlatformIO, which does not need a GUI and can be used from the CLI. (https://platformio.org/ and https://docs.platformio.org/en/latest/core/index.html).

It is probably a non-existant or stale auth cookie in your .Xauthority file.  This sort of thing happens when you're running your X session with one user but trying to run your X application as different user.  Doing sudo or su root (or really any other user) is a common way to get in that situation.  Running the IDE as root usually mean something else has already gone sideways.  The typical reason for that is you're running as root instead of fixing your permissions to the Arduino serial device file.

That said, if you want to run headless builds and uploads of Arduino projects, what you're looking for is arduino-cli.
cd /path/to/directory/containing/sht30v1.ino
arduino-cli -b arduino:avr:nano compile
arduino-cli -b arduino:avr:nano upload --port /dev/ttyUSB0

What version is arduino-cli in? I am 1.8.13

I'm not sure offhand what the latest version is.  Mine has been installed for some time now, I'm not sure its version will tell you anything.  The thing is though, the IDE version and the arduino-cli versions don't necessarily need to be related.  And the version number that largely affects your project is the version number of the (AVR) core, currently at 1.8.3. It's version number is also only-so-related to the IDE or arduino-cli.  Run the latest AVR core with the latest arduino-cli and you should be fine.

Just to give you a bit more info, I just ran their installer script (the curl to shell pipe) on their page to install the latest.  arduino-cli version now reports version 0.15.0 commit 0a034d73.  Again, this number has not a lot do with the others.

It looks like you've skipped over the command-line for compiling, the first of two in the answer.

I can get the sketch compiled and export the .hex files but it won't upload https://bpa.st/HYXCG

It is possible you need to use the the specific cpu option for the "old" nano, which connects at 57600 baud during bootloading.  In which case your -b option would need to be -b arduino:avr:nano:cpu=atmega328old

I honestly cannot tell if it worked or failed.  https://bpa.st/OXPQ I think it worked but I see a failure. Yes, it is an older boot nano

Let us continue this discussion in chat.


text:
How do I get an HTTP_POST response?
I have a function for HTTP_POST responses but it is never called when I post to it. I get the webpage instead.
I call on it with
server.on("/",HTTP_POST,response);

But I only get the url in response.
void setup() {
    pinMode(led_pin, OUTPUT);

    Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
    delay(2000); // To be able to connect Serial monitor after reset and before first printout
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__));
    Serial.print(F("Ready to send IR signals at pin "));
    Serial.println(IR_SEND_PIN);

    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, 0);
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    Serial.println("");

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());

    if (MDNS.begin("esp32")) {
      Serial.println("MDNS responder started");
    }

    server.on("/", handleRoot);
    server.on("/test.svg", drawGraph);
    server.on("/",HTTP_POST,response);
    server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
    });
    server.onNotFound(handleNotFound);
    server.begin();
    Serial.println("HTTP server started");

}

void response(){
  //int khz = 38; // 38kHz carrier frequency for the NEC protocol

  if(server.hasArg("on") && (server.arg("on").length()>0)){ // TODO check that it's not longer than 31 characters
      Serial.print("Server was turned on:\t");
      Serial.println(server.arg("on"));

      ++CYCLE0;
      server.sendHeader("Location", String("/"), true); //how to do a redirect, next two lines
      server.send ( 302, "text/plain", "");
  } else if (server.hasArg("off") && (server.arg("off").length()>0)){
      Serial.print("Server was turned off:\t");
      Serial.println(server.arg("off"));

      ++CYCLE1;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");

   } else if (server.hasArg("up") && (server.arg("up").length()>0)){
      Serial.print("Server temp was turned up:\t");
      Serial.println(server.arg("up"));

      ++CYCLE2;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");

  } else if (server.hasArg("down") && (server.arg("down").length()>0)){
      Serial.print("Server temp was turned down:\t");
      Serial.println(server.arg("down"));

      ++CYCLE3;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");

  } else {
    server.send(400, "text/html", "
HTTP Error 400

Bad request. Please enter a value.
");
  }
}

How do you get an http post response back instead of a webpage?
POST response:

    <meta http-equiv='refresh' content='5' />
    <title>ESP32 Demo</title>

Hello from ESP32!

Uptime: 00:05:32

Turn air condistioner on

AC has been cycled 0 times

    <form name='frm0' method='post'> <input type='text' name='on' value=8000>
        <input type='submit' value='Submit'>     </form>

Turn air conditioner off 0 times

        <form name='frm1' method='post'> <input type='text' name='off' value=8000>
            <input type='submit' value='Submit'>     </form>

Turn temperature up 0 times

            <form name='frm2' method='post'> <input type='text' name='up' value=8000>
                <input type='submit' value='Submit'>     </form>

Turn temperature down 0 times

                <form name='frm3' method='post'> <input type='text' name='down' value=8000>
                    <input type='submit' value='Submit'>     </form>

Complete code
long version

You have:
server.on("/", handleRoot);
server.on("/test.svg", drawGraph);
server.on("/",HTTP_POST,response);

The first call using handleRoot species no particular method, and in this case it seems any method is acceptable.  You later specify server.on("/",HTTP_POST,response); specifically for POST requests.  These are added to a request handler list in the order given.  And apparently consulted in the order given.
In short, you need to specify HTTP_GET for handleRoot or just specify your HTTP_POST for response first and let handleRoot catch non-HTTP_POST requests afterwards:
server.on("/",HTTP_POST,response);
server.on("/", handleRoot);
server.on("/test.svg", drawGraph);

That was it. For some reason it still return the URL instead of the response get returned to the client, but I definitely see the post request hit. I set both btw      server.on("/",HTTP_POST,response);
server.on("/",HTTP_GET, handleRoot);


text:
incompatible types in assignment of 'const String' to 'char [32] using server.arg
I am trying to create a class and getting getting the error
incompatible types in assignment of 'const String' to 'char [32]

when I declare
char inString[32];

and try to set it as
inString = server.arg("x");

I tried
inString = server.arg(sizeof("x"));

and got the same error.
full code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

const char* ssid = "myssid";
const char* password =  "password";

char inString[32];

void webpage() {
  server.send(200, "text/html", "<form  name='frm'  method='post'><input type='text' name='x'   ><input type='submit' value='Submit'>   </form>");
}
void response(){
  if(server.hasArg("x") && (server.arg("x").length()>0)){ // TODO check that it's not longer than 31 characters
    Serial.print("User entered:\t");
    Serial.println(server.arg("x"));
    inString = server.arg("x");
    server.send(200, "text/html", "
Successful
Home");
  } else {
    server.send(400, "text/html", "
HTTP Error 400

Bad request. Please enter a value.
");
  }
}

void setup() {

    Serial.begin(115200);
    WiFi.begin(ssid, password);  //Connect to the WiFi network

    while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

        delay(500);
        Serial.println("Waiting to connect...");

    }

    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //Print the local IP

    //server.on("/body", handleBody); //Associate the handler function to the path
    server.on("/",HTTP_GET, webpage);
    server.on("/",HTTP_POST,response);

    server.begin(); //Start the server
    Serial.println("Server listening");

}

void loop() {

    server.handleClient(); //Handling of incoming requests

}

how to I match my datatypes when using server.arg?
The other post I find related to a pointer which I am not using.

server.arg returns String so use String inString;

@Juraj Worked like a champ! Post it as an answer and I'll give proper thanks.


text:
NFC hang after RF_ON command
We have developed our board with PN5180 NFC but I cannot make it work properly. After I send RF_ON command I am stuck on STATE_CHANGE_IRQ_STAT while waiting for TX_RFON_IRQ_STAT but the state never changes. In this moment I can see sinus vawes on the oscilloscope. If I ignore it I will be stuck waiting for the RX_STATUS register to reflect the TRANSCEIVE_STATE. If I ignore both, the TX_RFON_IRQ_STAT appears after few SEND_DATA sequences but card cannot be read. Has anyone experience this?
def init(self):

# 1. Loads the ISO 15693 protocol into the RF registers
self._send([LOAD_RF_CONFIG, 0x00, 0x80])

# 2. Switches the RF field ON.
self._send([RF_ON, 0x00])

answer = self.read_irq_status_register()
while ((TX_RFON_IRQ_STAT & answer) == 0):
  answer = self.read_irq_status_register()
  self.show_status(answer)

return 1

The solution is that PN5180 simply cannot work without BUSY pin connected.


text:
How to set the eeprom initial value when flashing an ESP32
As I use the EEPROM to persist data such as for provisioning the WiFi (SSID and password), I'd like to make sure that the very first time the ESP32 runs, it finds the initial '\0' for the SSID so that it does not run into the WiFi connection code block.
For this I need to set the initial values into the EEPROM when I flash the firmware.
I use platform IO.
How to do that?

You're probably better off using SPIFFS and a "eeprom.bin" file. The current partition scheme of the ESP doesn't provide a dedicated partition for the arduino-like eeprom and the ESP32 doesn't have an EEPROM...

you can set/wipe SPIFFS with default files when uploading.

first of all, the esp32 remembers the WiFi credentials by itself. you don't have to store it. example https://github.com/jandrassy/lab/blob/master/ConfigurationAP/ConfigurationAP.ino

The ESP32 does not have a real EEPROM; instead, the data is stored in the external flash in the non-volatile storage (NVS) partition. The problem is, that the structure of this partition is proprietary. Only the SDK knows "where to find what" within NVS and any access to this partition is done using the SDK.
Unfortunately, the EEPROM.h library uses the NVS partition to store its values.
As the way how data is stored within NVS is closed source, you can't build a flash image that is guaranteed to work in different sketches or different versions of the SDK.
So, if you need to upload pre-made non-volatile data, the EEPROM.h library is practically useless.
A convenient alternative is to put that data in a file and store that file in a filesystem like SPIFFS.h.
This way, you define how data is stored/accessed yourself, so it's much less likely you run into problems when the core experiences changes.
Data upload is straight forward using esptool.py.


text:
Noise in RF 434 transmitter and receiver
I'm working on RF transmitter and receiver modules using two Arduino UNOs. I'm getting an additional noise on the receiver side in serial.println.
To be more clear about the question. Hre is my transmitter code
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{
    // Initialize ASK Object
    rf_driver.init();
    Serial.begin(9600);
}

void loop()
{

    const char *msg = "Hello World";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    Serial.println((char *)msg);
    delay(1000);
}

Here is my receiver code
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{
    // Initialize ASK Object
    rf_driver.init();
    // Setup Serial Monitor
    Serial.begin(9600);
}

void loop()
{
    // Set buffer to size of expected message
    uint8_t buf[11];
    uint8_t buflen = sizeof(buf);
    // Check if received packet is correct size
    if (rf_driver.recv(buf, &buflen))
    {

      // Message received with valid checksum
      Serial.print("Message Received: ");
      Serial.println((char*)buf);
    }
}

And here is my Serial monitor in receiver side

So, can somebody help me to sort out this issue

You're treating a raw buffer as a string.
In C a string is an array of characters (11 in your case) terminated by a NULL character.  You receive 11 bytes into an 11 byte array and then try and print it - without any terminating character - so the output "overruns" into the memory following your array.
You need a buffer of 12 bytes not 11, and you have to make sure that the 12th byte (byte number 11) is zero.
Or use Serial.write(buf, buflen); function to write exactly 11 bytes to the serial.


text:
Stabilization of HX711 and Faster Sampling. Code improvements
Helllo,
I am using load cells in my research project. I have 4 load cells and have connected 4 HX711 modules (one to each load cell) and have connected them to the arduino uno.
I have taken the example code given for 2 load cells and modified it for 4 load cells. My complete code is available here. The original HX711 2 load cell library example code is available here.
I have referred the source code but still have the following questions:
Q1) The following part of the code:
boolean _tare = false; //set this to false if you don't want tare to be performed in the next step
byte loadcell_1_rdy = 0;
byte loadcell_2_rdy = 0;
byte loadcell_3_rdy = 0;
byte loadcell_4_rdy = 0;
while ((loadcell_1_rdy + loadcell_2_rdy + loadcell_3_rdy + loadcell_4_rdy) < 4) { //run startup, stabilization and tare, both modules simultaniously
    if (!loadcell_1_rdy) loadcell_1_rdy = LoadCell_1.startMultiple(stabilizingtime, _tare);
    if (!loadcell_2_rdy) loadcell_2_rdy = LoadCell_2.startMultiple(stabilizingtime, _tare);
    if (!loadcell_3_rdy) loadcell_3_rdy = LoadCell_3.startMultiple(stabilizingtime, _tare);
    if (!loadcell_4_rdy) loadcell_4_rdy = LoadCell_4.startMultiple(stabilizingtime, _tare);
  }

Is this written correctly?
Can this be removed or is this part necessary?
Q2) I wish to increase the sampling rate so I am going to increase the baud rate to 115200 or higher. Does this have any affect on the previous question? Since, the source code seems to have been written for 10SPS.

You don't need 4 ADCs to measure 4 load cells, you need to configure the 4 load cells as Wheatstone bridge and measures it with one HX711 ADC. SparkFun has a good introduction on Getting Started with load cell which explain the details.

Also the higher the sample rate, the noisier the data it become. For a weight scale, accuracy is more important than speed, what is the point of increasing sampling rate. BTW, HX711 sampling rate requires hardware configuration changes. Read Olkal's HX711 library README for more information and why 10SPS is chosen.

@hcheung I am not talking about 4 strain gauges in a wheatstone on a single load cell. I need to measure 4 different forces hence I am using 4 different load cells.

It is better to use a chip from Analog Device AD7799. It has relatively high accuracy and no swimming, compared to the HX711. When connecting 2 load cells of 50 kg on the pavement
the scheme has an accuracy of 10 grams. I use the AD779x library.h and an example program that appears in the file-examples menu in arduino, after installing the library. When hx-711 is connected to the same
the accuracy of my sensors was 30 grams, I measured the accuracy of both ADCs for 10 minutes. I ordered AD7799 on Ali for 2-3$ . You need to take it together with the adapter for the ssop16 c chip
the distance between the terminals of the adapter is 0.65 mm. You also need to take "solder paste with solder", because the conclusions are too small and close. I took the SMD capacitors from the damaged matplate, measuring them
capacity by tester. When the load cell is warmed up with a hairdryer, the data changes greatly. Perhaps you need to put a digital ds18b20 thermal sensor on the thermal sensor on the thermal watch. With even a short - term
when you touch the load cell with your finger, the readings also change greatly due to the sensor warming up from body heat. If you touch through several layers of folded paper, the sensor does not warm up and
the readings do not change. Those who will test load cells by pressing them with their finger should remember that in a few seconds, after touching the load cell with their finger, the heat will reach
the sensor's sensing element along its metal body and the values will float up or down by tens of grams, depending on the connection scheme, sensor type, duration
touching. Press the sensors with any objects, not with your hand directly. L The inductance may or may not be set. It is possible to connect without a reference voltage source
TL431, and directly from the arduino 5v with a filter of 2 capacitors (as shown in the diagram). I first connected without it and the readings were quite normal. We need to try... The power source used
from Hi-link.


text:
ATTINY 85 - use host laptop's internet
Suppose I enable USB tethering (internet) on my laptop. Will it be possible to use that internet on an ATTINY 85 connected to USB.

no, the processing power of the microcontroller is insufficient ... your laptop has to act as a gateway between a serial port and the internet

Since there are uncounted applications for an internet connection, what specifically do you want to do?

No, the attiny85 is simply too slow and not powerful enough to process your laptop's internet connection and begin something with it. If you only have to make API Request, you can hard code them into the firmware, and send the api-request-string to your computer, make your computer execute the API-request and then send the API response from the computer to the attiny to process the response there.
Regards
Dario


text:
SNMP Manager - Multiple IP address -issue
I have multiple SNMP devices on the same network and I am trying to request, via OID numbers, each SNMP device and assign the response into an array.
When I request a single IP, I get the correct response as expected.
Problem:
If I run the same code in a for loop (multiple ip's 192.168.1.150, 192.168.1.151, etc), I get duplicate info.
I might be using the wrong callback method, or the SNMP Manager can not dynamically change the ip address..
I have researched a lot of topics and tried many avenues, but I can't get past this point.
If anyone can assist me, it would help a lot!!

Example Output:
The model name and serial should be different on each ip
----------------------
192.168.8.150
KONICA MINOLTA bizhub C658
A79J021002278
----------------------
192.168.8.151
KONICA MINOLTA bizhub C658
A79J021002278
----------------------
192.168.8.152
KONICA MINOLTA bizhub C658
A79J021002278
----------------------
192.168.8.153
KONICA MINOLTA bizhub C658
A79J021002278
----------------------
192.168.8.154
KONICA MINOLTA bizhub C658
A79J021002278

Here is the code
#if defined(ESP8266)
#include <ESP8266WiFi.h> // ESP8266 Core WiFi Library
#else
#include <WiFi.h>        // ESP32 Core WiFi Library
#endif

#include <string.h>
#include <WiFiUdp.h>
#include <Arduino_SNMP_Manager.h>

//************************************
//* Your WiFi info                   *
//************************************
const char *ssid = "Workmin_Sales";
const char *password = "workmin92429242";
//************************************

//************************************
//* SNMP Device Info                 *
//************************************
const char *community = "public";
const int snmpVersion = 1; // SNMP Version 1 = 0, SNMP Version 2 = 1
// OIDs
const char *oidModelName = ".1.3.6.1.2.1.25.3.2.1.3.1";               // OctetString SysName
const char *oidSerialNumber = ".1.3.6.1.2.1.43.5.1.1.17.1";              // OctetString SysName
//************************************

//************************************
//* Settings                         *
//************************************
int pollInterval = 20000; // delay in milliseconds
//************************************

//************************************
//* Initialise                       *
//************************************
// Variables
char *modelNameArray[5];
char *serialNumberArray[5];

char modelName[50];
char *modelNameResponse = modelName;
char serialNumber[50];
char *serialNumberResponse = serialNumber;

// Blank callback pointer for each OID
ValueCallback *callbackSerialNumber;
ValueCallback *callbackModelName;
//************************************

unsigned long pollStart = 0;
// SNMP Objects
WiFiUDP udp;                                           // UDP object used to send and receive packets
SNMPManager snmp = SNMPManager(community);             // Starts an SMMPManager to listen to replies to get-requests
SNMPGet snmpRequest = SNMPGet(community, snmpVersion); // Starts an SMMPGet instance to send requests

//************************************
//* Function declarations            *
//************************************
void getSNMP();
//************************************

void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to SSID: ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  snmp.setUDP(&udp); // give snmp a pointer to the UDP object
  snmp.begin();      // start the SNMP Manager
}

void loop()
{
  // put your main code here, to run repeatedly:
  snmp.loop();
  if (millis() - pollStart >= pollInterval)
  {
    pollStart += pollInterval; // this prevents drift in the delays

    getSNMP();
    // doSNMPCalculations(); // Do something with the data collected
  }
}

void getSNMP()
{
  for (int i = 0; i < 5; i++) {
    // Build a SNMP get-request add each OID to the request
    IPAddress router(192, 168, 8, i + 150);

    // Get callbacks from creating a handler for each of the OID
    callbackSerialNumber = snmp.addStringHandler(router, oidSerialNumber, &serialNumberResponse);
    callbackModelName = snmp.addStringHandler(router, oidModelName, &modelNameResponse);

    snmpRequest.addOIDPointer(callbackSerialNumber);
    snmpRequest.addOIDPointer(callbackModelName);

    snmpRequest.setIP(WiFi.localIP()); // IP of the listening MCU
    // snmpRequest.setPort(501);  // Default is UDP port 161 for SNMP. But can be overriden if necessary.
    snmpRequest.setUDP(&udp);
    snmpRequest.setRequestID(rand() % 5555);
    snmpRequest.sendTo(router);
    snmpRequest.clearOIDList();
    delay(1000);

    modelNameArray[i] = modelNameResponse;
    serialNumberArray[i] = serialNumberResponse;
    Serial.print("192.168.8.");
    Serial.println(i + 150);
    Serial.println(modelNameArray[i]);
    Serial.println(serialNumberArray[i]);
    Serial.println("----------------------");
  }
}

I think I see multiple issues with the example above.

The snmpRequest.sendTo(router); will send the SNMP packet out. But you need to call snmp.loop() to read the incoming replies to your request. So you need to restructure the code so that you can call loop() potentially many times in order to wait for the incoming replies before you read and store the values.
serialNumberResponse is a pointer to a character array serialNumber (likewise for the model). If the callback returned serial number 123ABC the first time, and the next device was called 1XD then the array would have a value of 1XDABC. So if you plan to re-use the variable, you'll need to clear it between uses something like: memset(serialNumber, 0, sizeof(serialNumber));
As you might not always get a successful response, or a response within the time allowed, the value may be still blank, if you're looking to store the values in another variable, you may want to ensure they aren't empty, as this would overwrite the value you may have had back on a previously successful call. If you were dealing with numbers, the value might also be that of a previous call. As pointed out in the answer above, you're dealing with pointers, so if you want to store the value you need to copy the value out, otherwise, you'll just point to the same pointer.

I hope this helps point you in the right direction. I've added an example to the library to show how multiple devices can be queried and the results stored in an array, see: https://github.com/shortbloke/Arduino_SNMP_Manager/tree/master/examples/ESP_Multiple_SNMP_Device_Polling. It stores the responses directly into the array. This might cause values to be cleared in the event of a timeout, I've not tested it completely.
Martin

Thank you so much, Martin. I tried the example and it is working seamlessly! When I get money, I am gonna buy you a few beers :)

You're not storing the data in your array, you're storing a pointer to the storage where the callback stores its data. So every entry gets the same pointer to the same storage, which gets its content changed. So all the array entries see the same (last) content.
It took me many years to properly get my head around C pointers.
Instead of just assigning (=) the value you need to copy the content.
Since you just have an array of pointers that can be done with strdup() which allocates a new block of RAM and copies the contents to it. Be sure to use free() on that allocated block when you've finished with it.

strdup


text:
D1 mini esp8266 error: esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
I am pretty sure this device worked yesterday. I tried to short GPIO0 to ground (flash), nothing.
I have a second ESP that uploads fine, but this one does not.
Is their another way to get this bootloader to open up? Or am I the owner of a brand new door stop?

show the complete wiring. is it a board or a basic module?

"doorstop", heh; maybe for a dollhouse ;) Does serial monitor show anything, like garbage, when you reset it attached?

@Juraj It's USB. I should have been more specific. There is no way to screw it up.

@dandavis Yes, I see a single line of garbage going across the screen in the serial monitor.

sorry I missed D1 mini in the tile. is something wired to the board?

@Juraj Nope. My friend. Just the USB

I'm not sure if this will help EVERYONE, but I hope it at least helps someone.  I had the same issue with several different boards (3 Nano's, 2 NodeMCU ESP8266's, and 1 Uno).  I searched and searched for an answer and I kept reading about this pin or that pin being "pulled low" or "pulled hi" interfering with uploading sketches.  Well, since I couldn't find a solid answer anywhere I decided to disconnect all of the peripherals hooked to my board (except for powers and grounds) and Wah Laa!!!  The sketch uploaded like it was supposed to.  So, I believe if you just unhook all of the sending and receiving pins from all of your peripherals during upload, the sketch should upload just fine.  I hope this helps you.

I would just like to thank you for the surprising solution. I was on the verge of going bonkers searching for a solution.

You're welcome!  I'm glad it helped.  It is definitely tied to one of the I/O pins.  It depends on what board you're using, but these boards usually have at least one pin that will not let any code upload if "pulled" up or down (depending on what it's expecting).  I believe you can look these pins up through the board data sheets/specs.

You must use the Arduino only as a pass-thru! -> So  for programming the the esp8266, you need  to BRIDGE  the Arduino-RESET to GROUND!

why? it is enough to not have Serial activated in the ATmega


text:
esp32-cam stuck in repeat boot
I am trying to bring the esp32 example code live. I am able to upload the image error free but when I remove the jumper and then press the reset switch, instead of seeing it logon to my network via serial monitor, I just get this repeating over and over and over again.
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
ets Jun  8 2016 00:22:57

How do I boot an esp32-cam correctly?
code:
#include "esp_camera.h"
#include <WiFi.h>

//
// WARNING!!! Make sure that you have either selected ESP32 Wrover Module,
//            or another board which has PSRAM enabled
//

// Select camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
#define CAMERA_MODEL_AI_THINKER

#include "camera_pins.h"

const char* ssid = "getAjobFool";
const char* password = "andreasd1";

void startCameraServer();

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();

  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  //init with high specs to pre-allocate larger buffers
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }

  sensor_t * s = esp_camera_sensor_get();
  //initial sensors are flipped vertically and colors are a bit saturated
  if (s->id.PID == OV3660_PID) {
    s->set_vflip(s, 1);//flip it back
    s->set_brightness(s, 1);//up the blightness just a bit
    s->set_saturation(s, -2);//lower the saturation
  }
  //drop down frame size for higher initial frame rate
  s->set_framesize(s, FRAMESIZE_QVGA);

#if defined(CAMERA_MODEL_M5STACK_WIDE)
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);
#endif

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  startCameraServer();

  Serial.print("Camera Ready! Use 'http://");
  Serial.print(WiFi.localIP());
  Serial.println("' to connect");
}

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

Brownout detector was triggered Did you look into what the brownout detector is?

The message:

Brownout detector was triggered

is being generated by your ESP32 because there is a problem with the Vcc power to the module.
Check the following:

Your USB cable.  Some cables are just plain cheap and can't supply the power the ESP32 needs.  Get a better one.

Some PCs are not able to supply enough power from their USB ports to supply the ESP32, try a powered USB hub and/or a different PC.

Some ESP32 modules are poorly made and may have bad solder joints or low quality components.  Your only real option here is to buy a better ESP32.

If you are powering other components from the ESP32's power supply, stop it.  Power any accessories separately.

I am connecting to the esp32 directly via ftdi. I tried both 3.3v and 5v and tried putting a 470uf capacitor right next to the vcc thinking it needed a bypass. I got zero change. The ftdi device is connected to a powered USB hub. I am not trying to power any other components. Joints look fine.

For... here, I'll vote it up.

"Directly" is not the word I'd have used with an FTDI but where is the power for the ESP32 coming from?  Via USB through the FTDI.  So everywhere I said "USB" you can change to "FTDI".  It's still via USB.  Try powering the ESP32 directly, that is with a known good power supply.  And the part about having a bad ESP32 still applies too.  Many of these are poorly made.

I've come across this issue and I've had good results with a 10-100uF capacitor directly between the GND and 3.3V pins on the ESP32Cam board. It stopped random reboots.

I used a different ftdi and it worked. You were dead on it. Thank you.

@brad Glad to help.


text:
How to you initialize a reset on a sht30 digital thermometer?
I have a sht30 that will output correct temperature readings for about 5 min and then will drift off.
So I'm trying to hit the reset every few seconds to keep the readings accurate.
I am on a nano connecting d4 to the sht30 reset pin, but I don't appear to be resetting. My temp still drifts.
How do you correctly hit the reset on a sht30?
code:
#include <Wire.h>

// SHT31 I2C address is 0x44(68)
#define Addr 0x45

int reset_pin = 3; // reset pin is set to d4 on board.
int counter = 0; //reset counter

void setup()
{
  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise serial communication, set baud rate = 9600
  Serial.begin(115200);
  delay(300);
}

void loop()
{
  unsigned int data[6];

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Send 16-bit command byte
  Wire.write(0x2C);
  Wire.write(0x06);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(300);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 6 bytes of data
  Wire.requestFrom(Addr, 6);

  // Read 6 bytes of data
  // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
  if (Wire.available() == 6)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
  }
  // Convert the data
  int temp = (data[0] * 256) + data[1];
  float cTemp = -45.0 + (175.0 * temp / 65535.0);
  float fTemp = (cTemp * 1.8) + 32.0;
  float humidity = (100.0 * ((data[3] * 256.0) + data[4])) / 65535.0;

  // Output data to serial monitor
  Serial.print("Temperature in Celsius :");
  Serial.print(cTemp);
  Serial.println(" C");
  Serial.print("Temperature in Fahrenheit :");
  Serial.print(fTemp);
  Serial.println(" F");
  Serial.print("Relative Humidity :");
  Serial.print(humidity);
  Serial.println(" %RH");
  delay(500);
  if(counter == 25){
    digitalWrite(reset_pin, HIGH); // sets the digital pin 13 on
    delay(1000);            // waits for a second
    digitalWrite(reset_pin, LOW);  // sets the digital pin 13 off
    delay(1000);
    counter  = 0;

  }
  counter++;
  Serial.println(counter);
}

The RESET pin is active low, not active high.

I'm hitting both so it should be resetting. Interesting.

Except you end up on LOW so it remains stuck in reset. You need to end up on HIGH.

You should really be asking yourself why it's drifting though... it's rated at 0.03C/year drift according to the datasheet...

@Majenko It will drift 10 degrees in a matter of 15 min. I gave up on that and ordered different units all together. This is a last ditch effort to get something useful out of the device.

You need to give a brief LOW pulse, not a long HIGH pulse:
In setup:
pinMode(reset_pin, OUTPUT);
digitalWrite(reset_pin, HIGH);

When you want to reset:
digitalWrite(pin_reset, LOW);
delay(1);
digitalWrite(pin_reset, HIGH);


text:
How to connect an lcd i2c using only pins A0 and A1 (SDA, SCL, GND, and VCC are given)
I want to know how to connect an lcd i2c, with an led 8x8 matrix at the same time. The problem is, all the analog in pins are used, except A0 and A1. Using this tutorial:
https://www.makerguides.com/character-i2c-lcd-arduino-tutorial/
It says I must have analog pins A0-A2 with nothing connecting, except I have A2 connected, which is why both screens don't work right. So how can I use only pins A0-A1 with an lcd i2c? Thanks.

You may be finding Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered) confusing.  These refer to the I2C address selection lines of the IO expander (the PCF8574T) used on the I2C LCD display and not to the A0-A2 analog pins of the Arduino itself.

The note // Wiring: SDA pin is connected to A4 and SCL pin to A5. is referring to the analog pins of an UNO (or Nano) because these pins also happen to carry the ATMega328P's I2C ("Wire") signals.
So there's nothing about using the I2C display that prevents you from using the Analog A0-A2 pins of the Arduino for other purposes.  Only the  Arduino's A4 and A5 pins are used to carry I2C/Wire.


text:
consecutive analogRead()
Has anyone noticed that if calling analogRead() in a consecutive way that the value drops by a bit as opposed to just doing a single read?
And is this to be expected?
I am using a Seeeduino XIAO.

You need a short delay between analog reads, more about it here: https://www.quora.com/Why-is-a-little-delay-needed-after-analogRead-in-Arduino

@Nino Thank you. That would explain it! (Add it as answer and I mark it as solution.)

You need a short delay between analog reads due to the time it takes to complete a reliable ADC reading. In depth technical explanations can be found here, note that it refers to AVR architecture.