text:
Problem with LCD keypad shield and Arduino Uno R3
I have a problem with powering my LCD Keypad Shield from a DC cable (4 AA batteries or 9V battery). Everything looks good, but the LCD screen doesn't display anything. When I used a USB cable, the screen works as it should.
What is the problem?

Can you please give us more than "it doesn't work?" That's really hard to diagnose. Please edit with circuit diagrams. Thanks!

OK. First of all, have you tried adjusting the contrast? I don't know why that would change between power sources but it might. This image labels the thing you need to turn to adjust the contrast. Turn it slowly from one side to the other until you can see something. Also: the AAs can't provide enough voltage- even when completely full. (They're in series, right?) Add two more in series to achieve 9V at full power. Also, try replacing the 9V if needed since they drain quickly. Also, connecting to VIN and GND for sure?

Sorry. I plug the LCD Keypad Shield to my Arduino Uno R3. I connected Arduino to computer by USB cable and load example cod from this page: http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29 Everything worked perfectly. When I disconnected Arduino, and instead of USB cable I used DC cable display didn't worked. The power led and LCD backlight was on but there where no letters or any other mark on display. When I changed cable back to USB it worked normal again.

You originally mentioned a battery, so I was giving advice on a batter. Can you please post a picture of your wiring for the battery to the Arduino? Thanks!

I tried to change the contrast and to change the power supplier but it dosen't work. With 9V display only blinks from time to time. I'm affraid that something isn't right with my Arduino.

Do you have a wall adapter that's 9V? I still think the battery might not be full.

Neither 4xAA nor a typical 9V battery is really suited to powering an Arduino.  Fundamentally, the board is not engineered for battery usage, but if you must, try at least 5 Alkaline or 6 rechargeable AA cells (and 7 wouldn't be bad).

Are you powering the arduino externally with a 9V battery or the LCD with a 9V battery. Most LCDs have lower voltage ratings. Can you be more specific about what kind of DC cable you are using, and how it works in you circuit? The problem seems to come from faulty wiring, or could just be damaged cables.

try this, turn the potentiometer more then 10 times clockwise: [1]: https://www.youtube.com/watch?v=ZA5vlDdpbkw

I do not have an answer... but it might be power consumption problem, ou voltage stability problem. I use a LCD shield with an RFID card reader (contactless card reader like you can find in the subway). When I plug the thing to a 9v battery the contrast is higher than when I connect it to an USB cable.

authors: Влад Верпетов


text:
Sending a floating point number from python to arduino
I am trying to send a floating point number from a python script to an Arduino.  I am not sure how to do this, especially in a pythonic way.
A little bit of research brought me to this very similar question:
How to send numbers to Arduino UNO via Python 3 and the module serial
I vaguely understand why this would work for an int but don't know how to modify it.
1) In this question it makes sense to convert to a char, send, and then convert back to a int by casting on the Arduino, I can't think how to do that for a float.
2) Why do they convert to a Char anyway?
3) What code do I run on the arduino to get this back into a float?
4) Can I use bitwise operators on floating point numbers?
I'm new to python and also to low level programming. I am also aware that python and low level don't mix to well. I am using Linux but ideally I need a cross platform solution. Although I would prefer to get it working then worry about cross platform later.

In this question it makes sense to convert to a char, send, and then convert back to a int by casting on the Arduino, I can't think how to do that for a float.

Instead of using a format specifier of B for an unsigned byte, use f for a single-precision float. AVR-GCC doesn't support double-precision floats, so don't bother with d.

Why do they convert to a Char anyway?

You don't. You convert it to bytes (hence the b prefix on the representation of the value) so that the byte-oriented serial protocol can transmit it. On Python 2.x str is already bytes, so no prefix is required there.

What code do I run on the arduino to get this back into a float?

Use Serial.readBytes() to dump the bytes from the serial connection into a float variable.
float f;
 ...
if (Serial.readBytes((char*)&f, sizeof(f)) != sizeof(f)) {
   ...

Can I use bitwise operators on floating point numbers?

... Well... no... because they may not necessarily remain valid floating point numbers afterwards.

Thanks for such a quick answer, this is exactly what I want, but this line doesn't work: I'm not really sure what I am doing wrong here, err msg: ser.write(struct.pack(@f,volt_out))
^
SyntaxError: invalid syntax

The format must be specified as a string. struct.pack('...', ...)

Thanks, it works :) I changed the arduino side code while(!Serial.available()); float f; Serial.readBytes((char*)&f, sizeof(f)); the if statement seemed a little redundant in my setup

Floating point numbers are (should) be stored in IEEE 754 format.
If you simply write the binary bytes of a floating point number down the serial line, it should be possible to unpack them at the other end.
To do this (Arduino C/C++), make a pointer from your variable, by casting the address of it to char*. Void* would probably work too.
 float my_value = 22.812;
 my_port.write((const char *)&my_value, sizeof(float)/*4*/);

And the unpacking - there's a few ways to do this, but I like:
 float incoming_value;
 unsigned char buffer[4];

 // If we read enough bytes, unpacked it
 if (my_serial.readBytes(buffer, sizeof(float)) == sizeof(float))
     memcpy(&incoming_value, buffer, sizeof(float));
 else
     // I/O error - no data, not enough bytes, etc.
     incoming_value = 0

On the other end (python), bytes are best handled with the struct module.  This will handle the packing and unpacking for you.
import struct
...

try:
    ieee754_data = my_serial.read(4)
    my_float = struct.unpack('f', ieee754_data)
catch:
    # I/O Error, or junk data
    my_float = 0.0

And packing:
 ieee754_data = struct.pack('f', my_float)
 try:
     my_serial.write(ieee754_data)
 catch:
     pass #TODO - I/O Error

One more note - You might consider using doubles instead of floats for extra precision.  Python floats have the precision of a C/C++ double already.

source: Stack Exchange

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

sort: votes


text:
Error code 10 for arduino device driver
How can I fix error code 10 while installing the device driver for Arduino in Windows 8.1?
The LED on the board is blinking after connecting it to the laptop, so I don't think so that the board is damaged. What is the cause of this issue?

"The board" is more than just the LED and the part that makes it blink.

First of all, test if you even need a new driver. On Windows, the Arduino drivers for my Uno and my Mega were installed automatically by Windows. I'd advise to restart your computer, using the actual restart button, not manually shutting off and turning on... this is very important with Windows 8.1 and its Hybrid Boot default!!! A normal reboot doesn't fully reload all of the drivers. Next, open the Arduino IDE, and then see if you can successfully upload the "blink" example sketch.
If that doesn't work, let's try something else.
First of all, open up Device Manager and find your device:

It should be under the Ports (COM & LPT) section. After that, right click and click on Properties.

Then, let's go to the Driver tab and click on Update Driver. Then, click on Search Online Automatically for this Driver.

First, try seeing if an automatic update finds any drivers capable. If not, I've found previously that there's sometimes a Reinstall or Fix button somewhere if the driver isn't working correctly.
In addition, you can also update it manually using Device Manager. Instead of clicking on Search Online Automatically for this Driver, click Browse My Computer Manually. For me, there was a Mega driver under the Let me pick from a list of compatible device drivers on my computer and there was a Mega driver for me (although I don't know if that's because I have it installed already).
You can also use that same menu to point it to the location of the installation of the Arduino IDE and it will search for any compatible drivers.
Rolling back the driver is another option if the Arduino IDE tried to install a faulty driver that somehow got corrupt over a working driver installed by the computer.
The last thing I would suggest trying as a last resort is using the Uninstall Driver button and then trying to reinstall the driver manually. I've never done this with an Arduino board, although there have been some times with other drivers that this has helped to remove the faulty driver.
If none of this works, it may be a faulty board.

I had the same issue. The drivers, which shipped with Arduino IDE didn't work for me.
Actually, the reason was that I was using Arduino UNO clone. And it required another driver.
This video helped me to find the answer: https://www.youtube.com/watch?v=r9MGJ16pRLc
In my case I had to install the CH340 chipset usb driver. The driver can be downloaded from this page: http://www.microcontrols.org/arduino-uno-clone-ch340-ch341-chipset-usb-drivers/
After I installed CH340 driver, the upload from Arduino IDE started working perfectly.

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


text:
How to transmit characters or just use xbee like serial monitor
I have an arduino mega and an uno, mega has an xbee s2c as coordinator and uno an xbee s2c as router, both in AT ( transparent ) mode. When I send integers from uno with Serial.write() coordinator receives just fine, but when i try float, negative numbers and chars, i get still integers but as I found out sending chars it is in ASCII. I tried Serial.print() but no result. Is there a way to send a negative float from one xbee to the other in AT mode?
Coordinator code
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial1.begin(9600);
  Serial.println("Comersing test!");
}

void loop() {
  if(Serial1.available()>0){
         Serial.print(Serial1.read());
    }
}`

UNO code
#include <SoftwareSerial.h>
 SoftwareSerial xbSerial(8, 7); // RX, TX
void setup() {
  xbSerial.begin(9600);
  xbSerial.write("First data sent!");

}
int x=4;
void loop() {
  // put your main code here, to run repeatedly:
      xbSerial.write(x);
      x++;
      delay(1000);
      delay(1000);
      delay(1000);
}

if I change x in Uno to float, negative or char, I get weird values.

If you can send ASCII and you have control over both ends of the data then you could send the numbers as text strings (not very efficient).  If the number have a limited range i.e. -127 -> +127 then you could send 0 when you wanted to transmit -127, 1 for -126, etc.

XBee cannot send negative integers, as it is working in hexadecimal and it has range between 0-255

I'm afraid that's not true, if it was then no computer would be able to represent negative numbers.  It all depends on the encoding.


text:
What is the difference between python and arduino programming?
I am a Python programmer and want to learn Arduino programming so want to know what are the main differences between Python and Arduino C++ programming?
Is Arduino C++ more complex than Python programming?
Are there any similarities that will help me?
Are there any formatting  restrictions like in Python?
Etc...
According to this page(printing hello), Aurdino programming looks easy to me.

What is the difference between python and arduino programming? -- Everything.

Heh.  As usual, @Majenko is correct.  This is like asking what the difference is between FORTRAN and COBOL.  From this question it sounds like you don't really know either Python nor C++

@SDsolar I know python but not C++

@ShopiMacros - If you know one language learning a second is easier than learning a first.  Start with small examples and work up.

@CodeGorilla , Got It

I agree with the Gorilla.  If you really want to have fun, look at this link.  It shows how to say "Hello, World" in 28 different languages..  It is interesting to see the similarities and differences.  Both Python and C++ are in there.   https://excelwithbusiness.com/blog/say-hello-world-in-28-different-programming-languages/

Python works great on everything except Arduino, where you use C++.  It is amazingly easy to use Arduinos.   Start with the built-in examples, like Blink.  Here is an article on that subject:  https://www.arduino.cc/en/Tutorial/BuiltInExamples

@SDsolar Its interesting alot.

Have fun with it!   The best thing about programming is that you have the freedom to control everything.  The worst thing about programming is that you have to control everything.  That was the joke when I was in CS school.

btw, please edit your question here and make it very clear that you are a Python programmer and want to know how hard of a leap it might be to use C++ on Arduino.  You have said plenty in the comments that, if included in the question, might even get the hold released.

@SDsolar is there anything missing now?

Your edit only makes this question worse.  Fundamentally, it does not fit here.

Arduino uses a language that is derived from Processing, which looks like C++.
Python is a different language, although both have similarities (both Object Oriented for example).
What is 'complex' depends on what your background is. C++ is in general more complex than Arduino, but most people using Arduino program in C++, so most examples can be found in C++, which makes support from other users easier.
If you are new to programming, I suggest using the 'standard' Arduino IDE.
To be complete, Arduino is not a programming language, it is a platform. In general, every language can be used to write Arduino code, but only a few have compilers for creating Arduino (machine) code.

Arduino uses the gcc compiler which is 100% 'c++'. The 'c++' includes automatically 'c' (although some would say that is is no longer pure 'c' because there are very tiny differences for example with keywords that are needed in 'c++'). On top of the 'c++' the Arduino platform has put an extra sauce. That extra layer can be a blessing or a curse or just confusing. In my opinion it is a little of each of those three things. Newer Arduino boards have faster processors and more memory, so there is no more holding back to use 'c++' to the full.

@Jot> well, there are C constructs that do not exist in C++. C++ doesn't include C, only a subset of it.

It sure is easy to get sidetracked by discussions about languages.  For Arduino I say just do what @Michael says and use the Arduino IDE (and the built-in examples) to get into the mindset.

I tried to make my answer suitable to the one who asked ... Jot is right mostly that C++/C and the Arduino 'language'  are similar, but from a start point of view, it's best to start simple (which is the Arduino IDE).

Understood.  I like your answer so upvoted.  It was a challenge to answer it as asked.  @Chris improved the body but I still think the title is not compelling enough for people to find this one after it is not new and goes inactive.

@SDSolar Thanks ... and also it's partly opinion-based (what is complex or not). E.g. for me electronics is more complex than programming, since I have more experience in the latter. Some people like OO, others prefer non-OO etc.


text:
Using 2 GY521(mpu6050)s with Arduino Uno R3
I am working on creating a motion sensor based on an Arduino and MPU6050 interface. I'd like to retorfit my code to be able to read 2 mpu6050 devices. Besides defining a 0x69 address and setting AD0 to high on one and AD0 to low on the other, what additional changes to I need to make to my code? I posted my original code below. Thanks in advance!
//Basic code to setup and read raw values from mpu6050
//matt_m 7-9-2017

#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU6050 0x68 //Device address
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address

//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s

int16_t  AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

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

void loop() {
  read_mpu6050();
  Serial.println(AcX);  //value to display
}

//setup MPU6050
void angle_setup()
{
  Wire.begin();
  delay (100);
  writeTo(MPU6050, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU6050, ACCEL_CONFIG, accSens << 3); // Specifying output scaling
  of accelerometer
  writeTo(MPU6050, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling
  of gyroscope
  delay (100);
}

void read_mpu6050()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU6050);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050, 14, true);  // request a total of 14 registers
  AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);
  Wire.write(toAddress);
  Wire.write(val);
  Wire.endTransmission();
 }

*edit: This below is the code with my best guess of how to implement 2 sensors, alas, my the output on my serial monitor keeps spitting out erraneous -1s and 0s
#include <Wire.h>

//Registers: Accelerometer, Temp, Gyroscope
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48

#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C

#define MPU60501 0x68 //Device address #1
#define MPU60502 0x69 //Device address #2
#define ACCEL_CONFIG 0x1C //Accelerometer configuration address
#define GYRO_CONFIG 0x1B //Gyro configuration address

//Sensor output scaling
#define accSens 0 // 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g
#define gyroSens 1 // 0 = 250rad/s, 1 = 500rad/s, 2 1000rad/s, 3 = 2000rad/s

int16_t  AcX1, AcY1, AcZ1, Tmp1, GyX1, GyY1, GyZ1;
int16_t  AcX2, AcY2, AcZ2, Tmp2, GyX2, GyY2, GyZ2;
void setup() {
 pinMode(0, OUTPUT);
 digitalWrite(0, HIGH);
 pinMode(1, OUTPUT);
 digitalWrite(1,LOW);
 Serial.begin(115200);
 angle_setup1();
 angle_setup2();
}

void loop() {
  read_mpu60501();
  Serial.println(AcX1);  //value to display
  read_mpu60502();
  Serial.println(AcX2);  //value to display

}

//setup MPU60501
void angle_setup1()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output
scaling of accelerometer
  writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output
scaling of gyroscope
  delay (100);
}

void read_mpu60501()
{
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60501);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
  AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

//setup MPU60502
void angle_setup2()
{
  Wire.begin();
  delay (100);
  writeTo(MPU60502, PWR_MGMT_1, 0); //wakeup from sleep
  writeTo(MPU60502, ACCEL_CONFIG, accSens << 3); // Specifying output
scaling of accelerometer
  writeTo(MPU60502, GYRO_CONFIG, gyroSens << 3); // Specifying output
scaling of gyroscope
  delay (100);
 }
void read_mpu60502()
 {
  // read raw accel/gyro measurements from device
  Wire.beginTransmission(MPU60502);
  Wire.write(0x3B);                  // starting with register 0x3B
(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU60502, 14, true);  // request a total of 14 registers
  AcX2 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C
(ACCEL_XOUT_L)
  AcY2 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E
(ACCEL_YOUT_L)
  AcZ2 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40
(ACCEL_ZOUT_L)
  Tmp2 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42
(TEMP_OUT_L)
  GyX2 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44
(GYRO_XOUT_L)
  GyY2 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46
(GYRO_YOUT_L)
  GyZ2 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48
(GYRO_ZOUT_L)
}

void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device);
  Wire.write(toAddress);
  Wire.write(val);
  Wire.endTransmission();
}

`

You have Wire.begin() twice. I think it might work, but it is not nice programming. Your code might work, but having the same code twice makes it very hard to detect a bug. A good programmer uses code that does a certain job just once. You can use function with the I2C address as parameter or a class for the MPU-6050 (as @CodeGorilla already wrote).

When ever you start looking at multiples of an object you should think of classes and structures to do things.
If you wrote a class:
class MPU6050
{
public:
    // Class constructor
    MPU6050 (const byte& address = 0x68)
      :m_Address(address)
    {
    }

    // Class destructor
    ~MPU6050()
    {}

    //setup MPU60501
    void angle_setup (void)
    {
      // Wire.begin();              // This should be called in main setup.
      delay (100);
      writeTo(MPU60501, PWR_MGMT_1, 0); //wakeup from sleep
      writeTo(MPU60501, ACCEL_CONFIG, accSens << 3); // Specifying output scaling of accelerometer
      writeTo(MPU60501, GYRO_CONFIG, gyroSens << 3); // Specifying output scaling of gyroscope
      delay (100);
    }

    void read_mpu6050(void)
    {
      // read raw accel/gyro measurements from device
      Wire.beginTransmission(MPU60501);
      Wire.write(0x3B);                  // starting with register 0x3B (ACCEL_XOUT_H)
      Wire.endTransmission(false);
      Wire.requestFrom(MPU60501, 14, true);  // request a total of 14 registers
      AcX1 = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
      AcY1 = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
      AcZ1 = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
      Tmp1 = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
      GyX1 = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44(GYRO_XOUT_L)
      GyY1 = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46   (GYRO_YOUT_L)
      GyZ1 = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48   (GYRO_ZOUT_L)
    }

    // Data member that could be private and have access functions, but...
    int16_t     AcX1;
    int16_t     AcY1;
    int16_t     AcZ1;
    int16_t     Tmp1;
    int16_t     GyX1;
    int16_t     GyY1;
    int16_t     GyZ1;

private:
    byte m_Address;
};

You could then have any number of sensors by going:
MPU6050  SensorOne;  // Address is optional and defaults to 68.
MPU6050  SensorTwo (0x69);

To access the data or functions in them:
SensorOne.angle_setup();
Serial.println(SensorOne.AcX1);

You could put the sensor in an array and then use loops everywhere, but there isn't much of a saving for two instances.


text:
Power ESP01 in forest
I want to do WiFi GeoChaching box. I'll use cheap ESP01, but problem is it will work in forest 24/7 in cycle of 1 min of work 5 in deep sleep and waiting for those who will find that.
How I can get power?

Either solar, or a very large battery. Or change the batteries every week. But I don't think Wifi is the best idea for this. I'd go with a Bluetooth Low Energy solution.

is there any cheap "board" like ESP01 with BT 4.0 and how big area i can cover?
Any idea what i can do in dark places like abonded tunels etc?

Why not just play Pokemon Go like the rest of the universe?

The BBC MicroBit might be a viable option - built in BLE.

What is your energy budget (how much energy - milliWatt Hours, or average current at what voltage - will be needed during the one minute on-time)? And how often are you willing to change its battery pack?

I think that in this case you will need multiple solutions for generating the power.

You need to know how much power you need.  This depends on you solution, I can't help there.
You need a backup battery, ideally one that doesn't mind constant trickle charge and deep discharge.  Sealed lead acid are probably the best.
Your battery must have enough power over a long enough time.
You need a power generator, wind, solar, water, chemical. And they should all have a common interface so you GeoCache is modular, so the GeoCaches can be plugged into any of the power sources, maybe even more than one source.

The problem with the power source is it is going to be a visual clue to where the cache is, probably also an audio clue.
The battery, if SLA, is going to be a great big lump that could be dangerous if damaged.
The caches are not going to be cheap, just because of the power source and battery, so I hope you have deep pockets.
Rather than looking for a ESP01+BT4 module look for any microprocessor with BT built in, it maybe a better way to go.

Tell me about that chemical generator pleas @Matt

Petrol, coal, nuclear which are probably not very practical in this situation.  https://en.wikipedia.org/wiki/Electricity_generation


text:
Using a 4*4 keypad to enter an integer value
I have a 4*4 keypad and I want to use it to enter a number.  I will then use this number as a delay to a LED or a motor to run for the specified time.
This is my sample code:
#include<Keypad.h>
#include<LiquidCrystal.h>
const byte numRows = 4; //number of rows on keypad
const byte numCols = 4; //number of columns on keypad

char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'X', '0', 'Y', 'D'}
};

char value[4]="";
int index = 0;

byte rowPins[numRows] = {22,23,24,25}; //Rows 0 to 3
byte colPins[numCols]= {26,27,28,29}; //Columns 0 to 3

Keypad key= Keypad(makeKeymap(keymap), rowPins, colPins, numRows,numCols);

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
lcd.begin(20,4);

lcd.print("       WELCOME      ");
delay(100);
}

void loop() {
char keypress = key.getKey();
while (keypress != NO_KEY){
  if (keypress == 'X'){
      lcd.clear();
      for(int j=0;j<=4;j++){
        value[j]=0;
      }
      index=0;
      }
   else if (keypress == 'Y'){
      int amt = atoi(value);
      digitalWrite(13, HIGH);
      delay(amt);
      }
   else
      value[index]=keypress;
      index++;
    }
}

How do I read the value returned by the keypad as an integer?  (When I press 3 I want to read 3 not "3").

Hello and welcome! What is your actual question?

from this code i should be able to get the input from the keypad and pass the value to delay the led

Am I missing something, any reason you can't initialize keymap to contain 3 rather than '3'? It's an array of 8 bit values, why not set it to be the numbers you want rather than text characters?

You can easily read by this line of code
value = anyDigitFromKeypad - 48

e.g value = "3"-48 = 3

I would write '0' rather than 48. The two are equivalent, but the former makes it clearer that you are subtracting the code point of the digit zero.

Your problem is that you have your keypress matching inside a while loop. That means it will, once matched once, continue matching over and over again as infinitum. You need to replace your while with an if so it only runs once for each keypress.


text:
Arduino Compiling Error
I recently format my  Windows 8 and installed Windows 8.1 . In Windows 8, I was using Arduino IDE and there was no error in compiling.But then I installed Windows 8.1 and re-installed Arduino IDE.I tried various codes for motor drivers and everything but they didn't compile.So, I tried to compile blink LED example first and even it didn't compile.It shows the following error on UPLOADING BLINK LED Example-
Arduino: 1.8.2 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Program Files\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\Arduino\hardware -tools C:\Program Files\Arduino\tools-builder -tools C:\Program Files\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files\Arduino\libraries -libraries C:\Users\Admin\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10802 -build-path C:\Users\Admin\AppData\Local\Temp\arduino_build_754363 -warnings=none -build-cache C:\Users\Admin\AppData\Local\Temp\arduino_cache_657645 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\Arduino\hardware\tools\avr -verbose C:\Program Files\Arduino\examples\01.Basics\Blink\Blink.ino
C:\Program Files\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files\Arduino\hardware -tools C:\Program Files\Arduino\tools-builder -tools C:\Program Files\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files\Arduino\libraries -libraries C:\Users\Admin\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10802 -build-path C:\Users\Admin\AppData\Local\Temp\arduino_build_754363 -warnings=none -build-cache C:\Users\Admin\AppData\Local\Temp\arduino_cache_657645 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\Arduino\hardware\tools\avr -verbose C:\Program Files\Arduino\examples\01.Basics\Blink\Blink.ino
Using board 'uno' from platform in folder: C:\Program Files\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Admin\AppData\Local\Temp\arduino_build_754363\sketch\Blink.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Admin\AppData\Local\Temp\arduino_build_754363\sketch\Blink.ino.cpp" -o "C:\Users\Admin\AppData\Local\Temp\arduino_build_754363\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Admin\AppData\Local\Temp\arduino_build_754363\preproc\ctags_target_for_gcc_minus_e.cpp"
exit status 1
Error compiling for board Arduino/Genuino Uno.

I tried RE-installing the software and drivers.It didn't work
Why is this happening?What is the Solution?

Right click on the Arduino icon, select properties. Under the compatibility tab, check "Run this program in compatibility mode" and select Windows XP. You might also want to run it as administrator.
This should hopefully solve the issue.
Source

I suspect also installing the IDE as a user rather than admin and running it as that user will also fix the problem. (But I have no evidence of that)

Uninstall Arduino. Then find the Arduino folder in your Appdata folder and delete it. Then reinstall Arduino. This is happening because after a library import, there might have been a clash in the Appdata and since uninstalling doesn't delete Appdata, just reinstalling wouldn't help. This happened to me when a PPM and Servo library clashed!
Note: Do this only after you try uploading a blank sketch and it still fails! Also be careful while in the Appdata folder.

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


text:
How to burn the bootloader onto a bare chip without using an Arduino board
How do I burn the UNO bootloader onto ATMEGA328P-PU without using an Arduino Uno board. That is burn directly from my PC or Android device??
I've tried nothing, I don't know a thing about microcontrollers ☺

Start by using an AVR programmer (ex: USBasp from Ebay for a few bucks)  to burn the bootloader to an Arduino Uno or Nano first--so you can see the expected process and outcome, then try the standalone tutorial posted by MatsK.

The short answer is, you need a AVR programmer
It is a tutorial on the Arduino website:
https://www.arduino.cc/en/Main/Standalone
And the section Bootloading your chips OPTIONAL will answer the question.

A AVR programmer is aka ISP programmer


text:
How to connect an Arduino to WIFI using an ESP8266
Hi I am trying to make Arduino Uno on local network with the help of ESP8266 wifi module.
I tried to search on internet, found mostly they are making ESP8266 as web server.http://circuits4you.com/2016/12/16/esp8266-web-server-html/
Can anyone help me how to add Arduino Uno on network with the help of ESP8266.

Have the idea of searching this very same site with the words "Arduino" and "ESP8266" ever come to your mind?
Please have a look at https://arduino.stackexchange.com/questions/13470/arduino-with-esp8266 and also https://arduino.stackexchange.com/questions/30837/setup-arduino-uno-with-esp8266-esp-1. By refining your search you might also find additional answers to more detailed questions that might arise as you move forward with this project.

@RobertoLoGiacco I see those examples but they are sending some commands to ESP8266 and reading it. I have done this example. I want something like get the dynamic ip from wifi network with SSID and password and assign it to arduino so i can access it from network

getting a dynamic ip from wifi is DHCP client. You cannot assign an IP to an Arduino, only the ESP8266 has some knowledge of being on the network.
Your question is so broad and vague it would require a series of blog posts to get covered in all its aspects. You didn't even explain your wiring between ESP8266 and Arduino, so we are assuming you are using an hardware serial connection, but yous "assign Arduino an IP" made me doubt about this.

This was closed as unclear. I have re-opened it at the OP's request. I think it might be classed as "too broad" but let's see where the answers take us.

Sending the following commands to the ESP should get you started:
AT+RST                         # Reset
AT+CWMODE=1                    # Set to station-mode as a client
ATE0                           # turn off command echo
AT+CWLAP                       # optional: list access points
AT+CWJAP_DEF="SSID","PASSWORD" # Always connect to this SSID

(I made-up the comment syntax; don't try to send those.) The full
ESP8266 AT Instruction Set has the complete set of commands and a functional description of each one.
Update:

... do I need to connect RX of ESP8266 to RX of Arduino, TX of ESP8266 to
  TX of Arduino, Ground of Arduino to RESET ?

Rx & Tx must be cross-connected with the corresponding Arduino pins and the ESP's reset pulled high (3.3v).

For this approach do I need to connect RX of ESP8266 to RX of Arduino, TX of ESP8266 to TX of Arduino, Ground of Arduino to RESET ?

No you still need to cross them over.

I have this code https://pastebin.com/C4ZUmVc0 when I am sending AT commands to ESP8266 it is working and blue light blinks.. now I have coded as you suggested.. now I want to know allocated IP address of it ? any way of it ?

Here is my logs Sending an AT commands
Got response from esp8266: AT+CWMODE=1
Got response from esp8266: ATE0
Got response from esp8266: busy p...
Got response from esp8266: AT+CWLAP
Got response from esp8266: busy p...
Got response from esp8266: AT+CWJAP_DEF=Moto,reset1234
Got response from esp8266: busy p...
Got response from esp8266:
Got response from esp8266: OK

All of the commands are documented in the manual I linked, but "AT+ CIFSR" seems like the one you want.

I am facing some issues while connecting ESP8266 with WiFi with AT commands. I asked here do you know what is the issue https://arduino.stackexchange.com/questions/37976/error-on-sending-atcwjap-def-commands-to-esp8266 thanks for suggesting to use AT commands. +1

It depends on how you want to approach it.  I know of two options:

Use AT commands.
Program the ESP.

When you are using AT commands you need to program the Arduino to open a serial line to the ESP (ensuring rx and tx are crossed over).  You tell the Arduino to send the AT commands you need to the ESP and wait for each one to be acknowledged.  Then the Arduino sends its network data via the serial connection, to the ESP and the ESP will forward it to the network.
You can program the ESP in EXACTLY the same way as you would the Arduino.  You could write some code to accept data from the Arduino over either Serial, SPI, I2C or your own proprietary communication method.  The ESP has libraries to be a DHCP client, DNS, HTTP client, etc. (most of which you have probably seen already).  If you then write a simple application that establishes the connection to the network and then waits for a packet of data from either the Arduino or the network and forwards it as appropriate.
I can't tell you which option is best, because I have never tried either method.  I just program the ESP to do everything that the Arduino would have done anyway and simplify the code.

I was trying to program ESP8266, have some kinda setup like I connected Arduino to my laptop, connected RX of ESP8266 to RX of Arduino, TX of ESP8266 to TX of Arduino, Ground of Arduino to RESET. But I was doing something like https://arduino.stackexchange.com/questions/37798/error-espcomm-open-failed I pasted my error logs also there..

I hope my setup was correct ? What could be cause of errors ? Would you care to answer there please ..

Arduino Rx <- ESP TX and ESP Rx <- Arduino TX.  The Arduino transmits on the Tx and the ESP listens for it on the Rx, and vice versa.  If you do Tx to Tx and Rx to Rx it won't work at all.  BTW Most people make that mistake first time.  Also the Gnd of the Arduino and ESP must be connected together, otherwise you can get a floating ground, which will result in them not knowing what Low and High are.  You should also use a bidirectional level shifter for any connections (except Gnd) between a 3.3v device (ESP) and a 5V device (Arduino)

I have connected and ESP8266 is able to receive command whatever I am sending like this https://pastebin.com/YYSjASZe now can you please suggest what changes do i need to make to get allocated ip address so i can access it from network I have selected "Arduino Uno" as board in Arduino IDE


text:
Is it possible to create a standalone exe which can burn the code into a Teensy 3.1?
So here's the scenario.
I have sent my teensy 3.1 circuit to a client of mine
And now I need to update the code burned onto teensy without providing client access to the code
So is it possible to create an exe or an installer of a kind which on execution simply upload the new code onto the teensy?
Since the code is finally a hex file uploaded onto the controller I hope this must be possible
But on doing a quick google search i was not able to find any valid resource which would guide me how to go about it.

Yes, but note that while you can avoid distributing your source code, it will be hard to prevent the recipient from loading the hex file into multiple boards.

Yes.  Teensy has a command line loader available at https://www.pjrc.com/teensy/loader_cli.html or https://github.com/PaulStoffregen/teensy_loader_cli
Given the hex file, the teensy_cli client could upload it without giving your client the source code.  For non-teensy devices, avrdude could be used similarly.
Alternately, one could fork the cli code, modify it to use an embedded copy of your hex file data in a hard-coded or encrypted constant, and then deliver that modified single-purpose executable file to your client.

So here it has been mentioned in 'Required command line parameters' that valid options for Teensy 3.2, Teensy 3.1 and Teensy LC are only applicable for mac and linux. Does that mean I cannot make this loader on windows?

Also here the hex files   for blink slow for Teensy 3.2, Teensy 3.1 and Teensy LC have been provided only for Linux operating system. Does that imply it is not possible on windows at all?

The hex files should be specific to the teensy/AVR hardware, not the host system.    As for the cli program not being able to work on Windows, I'm sorry I missed that--Mikael Patel's answer of the windows GUI solution might be best.

The simplest solution is to ask you client to install the TeensyLoader application. https://www.pjrc.com/teensy/loader.html
Send the new HEX file to the client. The client should then connect the board to the computer. Run the TeensyLoader and upload the HEX file. The TeensyLoader will recognize the board when the reset button is pushed. The HEX file will need to be located on disk (after download or mail attachment).
Cheers!

Yes, it is perfectly possible.
You will need three things:

The HEX file you want to program
The programming utility for your chosen board (would be in the IDE folder somewhere - not sure what Teensy uses off hand)
A text editor.

Then, using the text editor, you create a .BAT file which executes the programming utility with the right parameters to program the board.
It can help to do an upload in the IDE in verbose mode so you can see exactly what command and parameters are being executed.


text:
9v adapter burned out Leonardo style board
My first experience with Arduino ended in a tragedy. I bought a Leonardo from ebay and upon arrival, attached it to my laptop. Programmed a simple blink demo with the onboard LED. It started working. Then detached it from USB and plugged in a 9v adapter. The board started smoking and it doesn't work anymore. I measured the voltage of the adapter and it reads 9.7v. So, what is the reason of this tragedy?
Edit:
I think that the smoke was from a component close to the processor. Right now, when I attach a 9v battery to the board, both the ON LED and the L LED remains on. The processor also warm.

I hate to sound like a prick but if you bought a knock-off then it could be absolutely anything.

If you bought it on eBay then it's a knock-off. They are very, very good at making exact copies. Except where it counts, as you've discovered.

Did you check the polarity of the adapter? If it's reversed the diode (SMT version of a 1N400x) will overheat.

I checked the polarity of the adapter and it seems OK. When I attach the COM cable of the multimeter to the inner contact of the adapter, it shows +9.7v. Does it confirm that the polarity if OK?

Common to inner, V to outer? If it reads +9.7 it's the reverse of most adapters.

Sorry, I made a mistake in my previous comment. It reads -9.7v. So, it's correct. And the center pin is marked as positive on the adapter too. So, it looks fine.

Post a picture. Perhaps seeing what failed will give a clue.

@Craig: I am not sure if a picture helps or not, since the board looks totally normal. I think that the smoke was from a component close to the processor. Right now, when I attach a 9v battery to the board, both the ON LED and the L LED remains on. The processor also warm.

While it is possible someone shipped a board with a fake regulator or under-rated or reverse polarity filter cap, I'd be inclined to suspect an "evil" 9v adapter first.  Once zapped it may be nothing but a heating element - potentially a mild one if a weak-current source like a 9v "transistor" battery is used.

On the assumption that is now worthless, could you put your volt meter (set to Volts, DC) black to GND, red to 5V pins (you may need hookup wire), plug it in and read the voltage; then do the same on 3.3V, and VIN, and post the results here.


text:
CH340 max serial speed
With an Arduino-like board using a CH340 USB Serial chip, I'd like to send text lines as fast as possible to a Raspberry Pi through USB using the Serial.println() function. The problem is that when I set the serial speed to values above 230 400 with the Serial.begin(speed) function, the Arduino console crashes and the C program on the Rapsberry Pi displays garbage in its console, even though I set the same serial speed.
Short examples :
Serial.begin(230400);
Serial.println("Test !"); // Works fine.

Serial.begin(250000);     // Or any speed above 250 000.
Serial.println("Test !"); // Doesn't work at all.

This answered question states that 2 Mbauds is possible, so I'm a bit lost.
The Arduino IDE console offers various speed from 300 to 2 000 000 bauds, so why don't speeds above 230 400 work ?

What type of Uno? Clone? Check what USB bridge is used on your board.

Cheap Chinese clone. The chip seems to be a CH340G.

CH340G does not support 250 Kbps. See page 5, https://www.insidegadgets.com/wp-content/uploads/2016/12/ch340g-datasheet.pdf

Thank you for the datasheet and this information. But according to the document, speeds like 460 800 bauds and 2 000 000 bauds should work, so why would this not be the case with my board ?

Add the line "while (!Serial); " after "Serial.begin()" or simply a delay. The USB handshake might take some time and the first character lost.

Please remember that the baudrate is not the USB transfer rate. It is between the MCU and the USB bridge. Also the max sustained baudrate is approx. 100-200 Kbps with the Arduino HardwareSerial implementation.

Thank you for your help and reminder. My print() are in a while loop, and it's not a problem if I miss a few characters at the beginning. What is the HarwareSerial implementation ? I see it's a custom version of Serial, but what is it for ?

The HardwareSerial class is an implementation of the Arduino Serial class that uses the MCU/AVR UART (hardware serial). The class (internals) are interrupt driven and uses ring-buffers to store incoming and outgoing characters.

CHG340 supports common baud rates: 50, 75, 100, 110, 134.5, 150, 300, 600, 900, 1200, 1800, 2400, 3600, 4800, 9600, 14400, 19200, 28800, 33600, 38400, 56000, 57600, 76800, 115200, 128000, 153600, 230400, 460800, 921600, 1500000, 2000000 baud.
250 000 baud isn't supported by that IC.
The Baud steps is either 200% or 150% of the previous value (There is exceptions).
Tested and working Baud rates.
I used putty as serial monitor since the built in monitor didn't have all baud rates preprogrammed.
SpeedTest.ino
// Serial port Baudrates:
// const int Speed = 115200;
// const int Speed = 128000;
// const int Speed = 153600;
// const int Speed = 230400;
// const int Speed = 460800;
// const int Speed = 921600;
// const int Speed = 1500000;
const int Speed = 2000000;

void setup() {
  // Initialize serial:
  Serial.begin(Speed);

  // Initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  Serial.print("Speed :  ");
  Serial.println(Speed);
}

This helped me, thanks ! Actually, I've found that my problem is due to serial latency, but I still managed to communicate at 1 Mbaud.

I have tested 3000000, which worked for me. See also https://www.eevblog.com/forum/microcontrollers/ch340-usb-uart-speed-tests/

the windows driver only goes to 128000

I have seen commenst that speeds abowe 115200 is "unstable" in both windows and linux

There may just be a workaround to allow this adapter to operate at 250000 baud (at least in the Raspberry Pi). The author of this article:  http://dmxpi.blogspot.com/2014/04/dmx-on-raspberry-pi-start-here.html has modified the linux driver and claims it works. I hope this helps.

Please edit your answer to include the method/steps employed in the link. If the link dies then your answer will not be as useful as it could be.

i agree with @Greenonline


text:
Alternative to UART/I2C LCD displays?
I'm building a MIDI synthesizer on Arduino Uno, and am considering user interface options.
I see on Adafruit and Sparkfun there are 16x2 LCD panels available that interface via I2C serial or by UART, but I think neither of those will work in my application:

The UART is clocked at 31250 baud to receive MIDI, and that's not a supported baud rate for these LCD devices;
I'm producing audio by driving an external DAC (MCP4725) over full-speed I2C; any transmission to another device would audibly jitter the DAC output;
SoftwareSerial would get around the UART clocking problem, but I believe it would stall the main loop while driving the output.

One option might be to roll my own software serial routine, carefully clocking it on the main loop, which (I believe) reliably runs at either 14.8KHz or 22.2KHz depending on the DAC protocol in use. I could set a SparkFun SerLCD into a slow data rate (2400 baud) and count passes through the main loop to time the data output.
Another option would be to use a secondary MCU -- I have a surplus Trinket M0 on hand -- and define a custom synchronous serial protocol between the two MCUs, and have the secondary relay commands to the LCD but that's getting into Rube Goldberg territory.
Any obvious options I'm overlooking?

Also consider using an Arduino Mega, which has 4 UARTs.

@LookAlterno: IIRC, it's a sort of synchronous, either 8-bits or 4-bits, parallel interface.

There are a few interrupt-based SoftwareSerial alternatives floating around that will not stall your loop.

The standard HD44780 LCD interface is defined as a "6800 CPU bus interface" with optional 4-bit mode. That is not "sort of synchronous" nor "not an interface really" but rigidly defined in operation. The I2C and UART LCDs just provide a third party interface (IO expander, small MCU, etc) to that 6800 CPU bus interface.

UART is considered "point-to-point", so as a rule of thumb you shouldn't attach more than two devices. Usually serial LCDs come with a I2C or SPI interface, or you can use any parallel LCD connecting the required 7 pins (4 data, 3 control). Or you can use a shift register to control it (there are plenty of schematics on the internet and I think all the libraries support these modes). In any case, high-speed I2C (the 3.4Mbps one)? Are you sure the arduino uno supports this? Did you already try it? If, as I think, the uno is capped to 400kbps, I suggest you to switch to an SPI ADC (a bit faster)

@frarugi87 I meant full-speed I2C (400k) for the DAC, not high-speed - will edit. I'm only using the input side of the UART currently for MIDI, so I figured the output side would be available. Parallel LCD seems like the best solution, but I'm running short of pins, so I may have to lose some indicator LEDs if I go that route.

@RussellBorogove ok, then if you use the I2C only to communicate with the DAC (and never release it - this means you will have to write your library, since you need to never send the stop byte and the address) you will be able to continuously feed the DAC with two bytes for each sample, which are roughly 19 bits. At 400kbps, the sample rate of the signal can be at most 21 kHz. Is it enough? In my opinion it is better to switch to a SPI DAC (e.g. from the same supplier the MCP4921, or lower resolution variants MCP4911 or 4901), which is much faster to control

Yep, the requirements for a grungy bass synth are different from those for a symphony ;) I was actually using the sample-at-a-time mode of the 4725, so getting ~14khz from it — and putting it directly through a fixed lowpass at ~4500. In any case I’m probably switching to PWM output.

One obvious option would be to get a display with SPI interface, since you have it available. Another option is to get a DAC running on SPI, and use the I2C for the display.
If you insist on using one of these 16x2 LCDs, there are SPI adapters for them as well. Example


text:
Arduino Ethernet Shield Response Process, Time, and Synchronization
I have a ethenet shield. I want to update my server page. Server page have to show current time. The code is given in this link. Code works but there is two problem
1- When i press the stop button in the browser, Arduino stops. After this i press refresh button and there is no response.
2- How can i synchronize the arduino time. From where? without setup another server. Is there any time stamp server that compatible with arduino?

Question 1.
Your code looks odd:
void checkForClient(){

  EthernetClient client = server.available();

  if (client) {
    boolean sentHeader = false;
    while (client.connected()) {
      if (client.available()) {
        if(!sentHeader){
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          sentHeader = true;
        }
        durumBildir(client,50,ID);
      }
    }
  }
  delay(1); // give the web browser time to receive the data

}

void durumBildir(EthernetClient client, int deger,String ID){
  client.print(ID);
  client.print("-");
  client.print(deger);
  client.print("-");
  if (timeStatus()!= timeNotSet) {
    digitalClockDisplay( client);
  }

  client.print("<br>");
}

You never read from client, so it will always be available (and thus you never leave your loop). I just tested it. Why are you sending the time out indefinitely? Even when you disconnect the poor Arduino is still sending the date and time out forever. No wonder you can't connect again.

I don't have an answer for question 1.
For question 2:
You can add a function to implement an NTP (network time protocol) client.  For example, see the UdpNtpClient article on arduino.cc.  In your setup() or loop() code call the function initially or perhaps hourly or daily to set system time via an NTP time server.  The server's IP address can be hardcoded or otherwise as you like.
For lists of public time servers, see www.ntp.org and pool.ntp.org.
Alternately, you could add a DS1302 or similar clock chip board to your hardware.


text:
Arduino Cross Correlation?
How can I write lightweight cross correlation code for arduino? I couldnt find any solution. The measurement system contains an ultrasonic sensor and a servo  that turns from 45 to 135 degree and measures distance from 4-300 cm. Than i collect data in an array which contains distances with respect to angle. System makes several measurement like this and program finds cross correlation between new and old arrays.
http://www.instructables.com/id/How-To-Make-an-Obstacle-Avoiding-Arduino-Robot/

Do you want to correlate two real-time signals or a real-time signal with a predefined pattern? How large (in number of samples) is the window over which you want to integrate?

signal collected and than cross corr will work. length of signal is 90.

Could not understand your sentence. Could you please update the question with information about the two signals you want to correlate? Are they known at compile time? Have they to be processed sample by sample during acquisition?

I wrote a sparse cross correlator that works with a digital signal sampled on timer values. It was running on a very small microcontroller. If you give us more information about what signal you are correlating I would be happy to post it here

There is an ultrasonic sensor.and a servo  that turns from 45 to 135 degree and measures distance from 4-300 cm. now i collect data in an array which contains distances with respect to angle.system makes several measurement like this and than program finds corelation between new and old arrays.

Given the time scale of the measurements, performance is not an issue.
And since you are not computing in real-time, as the samples are being
measured, you can apply the definition of cross-correlation as is, and
compute it in a double loop. The only difficulty is figuring out that
cross-correlation may not be the proper tool for the job... and finding
the right one! My assumption is that you want to estimate a rotation
angle between the two measurements.
The mathematical definition of cross-correlation assumes infinite
arrays. In practice, cross-correlation is often used to locate a short
pattern inside a long signal. In this case, the computation is done only
for shifts where the pattern completely overlaps the signal. Then the
length of the result is
length(result) = length(signal) − length(pattern) + 1

In your case, since your pattern is a previously measured signal, this
would give a single-sample result, which is useless.
You could instead compute the integral for all shifts where there is
any overlap between the pattern and the signal. This is equivalent to
zero-padding the signal. This has the drawback of biasing the result: if
your signal and pattern are both featureless (positive constants), you
will find a very nice peak at zero shift!
You can remove this bias by subtracting the average from both the signal
and the pattern, and correlating (signal − avg(signal)) with
(pattern − avg(pattern)). This still carries a bias for “big”
features. Imagine for example that, after removing the averages, you
have
pattern = [  0,   0, −20, +20,   0,   0];
signal  = [−50, +50,   0,   0, −20, +20];

You would expect your correlator to find a good match between the
[−20, +20] of the pattern and the [−20, +20] of the signal. The
correlation is, however, much better with the [−50, +50] of the signal.
You may try to alleviate this by computing a normalized
cross-correlation instead, but you will at best make both matches
equally good.
My suggestion is that you completely forget about correlations and
instead think in terms of “goodness of fit”. Correlations are good for
finding scaled and shifted copies of a pattern inside a signal. You are
looking for shifted only copies, with no scaling. Your question should
be: if you shift the pattern by some amount, how well does it fit the
signal? What amount of shift gives the better fit? The canonical answer
to all “goodness of fit” questions is to minimize the RMS difference
between the two: you compute the sum
S = Σ(signal − shifted(pattern))²

Then the RMS difference is
RMS(difference) = √(S/N)

where N is the number of samples involved in the sum. The most likely
shift is the one that minimizes this error. In practice, you do not need
the square root, you just minimize
RMS(difference)² = Σ(signal − shifted(pattern))² / N

You can implement this formula as-is, it's completely straightforward.
Just beware that N depends on the shift, as it's the length of the
overlap. And avoid going to very small overlaps (i.e. large shifts).
Now, if you expand the square inside the sum, you may find that, after
all, this is not so far from a cross-correlation... And BTW, all this
has nothing to do with Arduino.

I need both to delay and correlation informations. delay information will be used to estimate displacement and relation will be used to decide importance of estimated displacement (is it realy meaningfull or not). The system will work like ultrasonic radar based dead reckoning. Also I'm trying to implement this link

You have both informations: 1) the amount of shift that gives the better fit, 2) the RMS difference at this particular shift.


text:
minIMU 9 and Arduino reading Gyro angle
I'm using minIMU-9 https://www.pololu.com/product/1268 and I want to read pitch, roll and yaw angles. I applied this library https://github.com/pololu/minimu-9-ahrs-arduino but there is a slope when sensor is not moving or vibrating. How can i fix or compensate this. The y axis is angle in degree and x axis is time in seconds
Pitch

Roll

Yaw

Have you estimated the offset values vector and updated it in code?

yes i did. You can see values coming towards from 0

I suppose "at desktop readings" means you have your sensor resting on the desktop so you where looking for a constant output value over the time. Well, there are some mechanical limitations about gyroscope's accuracy, resolution and external factor like temperature that make noisy or non-sense readings.
What you are obtaining from this library is a calculated orientation that carries or accumulate an error over time. Basically there is not a perfect algorithm to calculate orientation as at MEM's scale electrons still moving due to temperature and other radiations.
Solution depends on your application scenario: if your sensor will be most the time quite, maybe just mathematical compensate with inverted slope (about 4-5 degrees per minute) and look for more rapid changes to determine movement. If your application will be on constant move maybe it is not required any compensation. Trade off must be considered if both scenarios will take place on your application. Anyway, reading measures on your actual application will give you more clue on how to handle this.
Below the L3GD20's mechanical characteristics

the sensor has internal temperature sensor so the gyro compansates temperature changes automaticaly.

even internal compensation is not perfect that's why datasheet has SoDr, OffDr and so on parameters.


text:
External ADC reading zero while input is zero
Using ADS1115 (or any other external ADC), how its possible to read zero instead of random floating values while no any signal at the ADC's input pin?
The ADS1115 is driven by an op-amp buffer as follows.

The op-amp's + input is sometimes connected to a pH sensor, sometimes left unconnected.

Signal is op-amp buffered pH sensor signal so its impedance is near by zero I think.

Ok. But what will going on when input is connected? I'm asking because I want to understand before trying.

You get the output impedance and the 10k in parallel, so if the output impedance is considerably lower than 10k then the 10k will have virtually no effect on the signal.

That's an interesting point - I assumed the poster was asking about when nothing was connected. @user30878,  could you clarify please? Are you asking how to get 0-readings when nothing is connected to the ADC, or are you saying you get fluctuating readings when you have the opamp connected but nothing connected to the op-amp inputs? (Or something else?)

Op-amp's output is always connected to ADC input but nothing connected to op-amp's input in my case. By fluctuate  I mean randomly floating values.

OK, then your problem is at the input to the op-amp. Please add a circuit diagram, including what's connected to the input of the op-amp, and then we can answer without guessing.

Simple op-amp configuration, non-inverting and unity gain mode (voltage follower).

Any input biasing? Please add a diagram.

Not any else component!  This is it http://www.electronics-tutorials.ws/opamp/opamp17.gif

The behaviour you are seeing is what happens when you have high-impedance inputs.  Basically, if you don't drive them, you get random values.
Unfortunately in your case, where the sensor you are using has no output current to speak of, I don't think there's anything you can do about this electronically.
You'll have to solve the problem in some other way if you really need to be able to disconnect the sensor.  A mechanical solution would be a connector which shorts when disconnected.  Switched headphone connectors do this, for example - when you pull out the jack, they make a connection so that the speakers can be switched on.

You mean 100 times larger resistor than sensor? It would be 100 mega Ohm then.

In fact I don't need to get zero. I just want to get rid off random values.

What is the ouput impedance of the pH sensor? I have no idea how they work...

It can be go to 1 tera ohm.

Yes. There is nothing added to this circuit. http://i395.photobucket.com/albums/pp34/teriyakithunder/pHprobe.jpg . Just the output goes to ADC input.


text:
Trying to use a 7 segment display to count 0/9 with a potentiometer
im trying to switch number on the display using a
    potentiometer, it is just counting from 0/9.
    All help is much appreciated!
int SegmentA = 6;
int SegmentB = 7;
int SegmentC = 8;
int SegmentD = 9;
int SegmentE = 10;
int SegmentF = 11;
int SegmentG = 12;

const int PP = A0;

void setup()
{
  pinMode (SegmentA, OUTPUT);
  pinMode (SegmentB, OUTPUT);
  pinMode (SegmentC, OUTPUT);
  pinMode (SegmentD, OUTPUT);
  pinMode (SegmentE, OUTPUT);
  pinMode (SegmentF, OUTPUT);
  pinMode (SegmentG, OUTPUT);

}

void loop() {

  int POD = analogRead(PP);
  int SM = map(POD, 0, 1023, 0 , 8);
  switch (SM) {

    case 0:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, HIGH);   //0
      digitalWrite (SegmentF, HIGH);
      digitalWrite (SegmentG, LOW);

      delay(1000);

    case 1:
      digitalWrite (SegmentA, LOW);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, LOW);
      digitalWrite (SegmentE, LOW);   //1
      digitalWrite (SegmentF, LOW);
      digitalWrite (SegmentG, LOW);

      delay(1000);

    case 2:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, LOW);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, HIGH);   //2
      digitalWrite (SegmentF, LOW);
      digitalWrite (SegmentG, HIGH);

      delay(1000);

    case 3:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, LOW);   //3
      digitalWrite (SegmentF, LOW);
      digitalWrite (SegmentG, HIGH);

      delay(1000);

    case 4:
      digitalWrite (SegmentA, LOW);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, LOW);
      digitalWrite (SegmentE, LOW);   //4
      digitalWrite (SegmentF, HIGH);
      digitalWrite (SegmentG, HIGH);

      delay(1000);

    case 5:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, LOW);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, LOW);   //5
      digitalWrite (SegmentF, HIGH);
      digitalWrite (SegmentG, HIGH);

      delay(1000);

    case 6:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, LOW);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, HIGH);   //6
      digitalWrite (SegmentF, HIGH);
      digitalWrite (SegmentG, HIGH);

      delay(1000);

    case 7:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, LOW);
      digitalWrite (SegmentE, LOW);   //7
      digitalWrite (SegmentF, LOW);
      digitalWrite (SegmentG, LOW);

      delay(1000);

    case 8:
      digitalWrite (SegmentA, HIGH);
      digitalWrite (SegmentB, HIGH);
      digitalWrite (SegmentC, HIGH);
      digitalWrite (SegmentD, HIGH);
      digitalWrite (SegmentE, HIGH);   //8
      digitalWrite (SegmentF, HIGH);
      digitalWrite (SegmentG, HIGH);

  }

}

I would shorten the delay (1000) to be much less - otherwise you turn the pot, nothing happens, you turn it some and finally something happens but now you've overshot what you wanted, and you overdo it the other way trying to get to where you wanted.  Try a delay of 50 to 100, have it be much more reactive to turning the knob.  You can then move on to using a rotary decoder with detents, one click for one number change.  Here's a poorly lit example with 2 digits and rotary encoder.  In this case, a shift register was used to drive each display (vs multiplexing).

https://www.youtube.com/watch?v=f51eSlcZt-g  The link.

You miss the break statement at the end of each case. e.g.:
  digitalWrite (SegmentF, LOW);
  digitalWrite (SegmentG, HIGH);

  delay(1000);

  break;

case 4:

This causes each case to perform, and continue with the next case. However, since there is a delay of 1 second, it looks like it is counting.
Actually, I would expect it counts from a certain value depending on the pot meter to 7, since there is no digit 9 implemented, and the delay for the 8 digit is missing too.
To further improve your code, you can add the delay not in every case but at the end, since I assume there always will be one digit selected.
Also you can make a function void showDigit with a parameter for each of the possible segment states and replace all (almost) duplicated code by that function call, or send the digit and use showDigit to set internally the states of each segment (by using a boolean array[nr_of_digits][nr_of_segments], somewhat like Nic Hartley proposes below.

@NicHartley Thanks ... I think a two dimensional array is than even better, but the use of an array is better in general.

@NicHartley since the Arduino has only 2 KB this might be useful, but indeed, only when needed. I always prefer readability over memory reduction.

@NicHartley I run out immediately with 2 KB (that's why I want to do my 'main' project with an STM which has 192 KB (but maybe I should have used a Raspberry).

Let us continue this discussion in chat.

You'll want a single delay (if any) at the bottom of the loop() function. You may not need it since it will keep displaying the current digit until you move the potentiometer. Exception: if the pot is near the edge between 2 digits, you could see some dithering.
Replace the delay-calls in the cases with break; statements. Otherwise whichever case you call will fall through into the case below it, and so on, displaying subsequent each digit in turn, which isn't what you wanted (and is what you are already seeing).
Change the map() call to map(POD, 0, 1024, 0 , 10). Otherwise there will be no '9' band on potentiometer and the '8' band will be only 1 value wide (out of 1023): exactly the value "1023". You'd like the '9' band to be about as wide as all of the others. It's even possible that a given potentiometer won't get close enough to zero resistance for you to get a 1023 reading.

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


text:
Restarting Arduino changes cursor position on OLED
I got an 16x2 OLED Display (DEP 16201-Y , compatible to the HD44780 controller) for my Arduino Uno and I got it to work in 4-bit Mode.
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

void setup()
{
//lcd.clear();
   lcd.begin(16, 2);
   lcd.clear();
   lcd.setCursor(0,1);
   lcd.print("Hello there");
   delay(1000);
}

void loop()
{
   lcd.setCursor(0,1);
   lcd.print("Hello World");

   lcd.setCursor(0,0);
   lcd.print("ABCDEFGHIJKLM");

   delay(1800);

   lcd.clear();

}

I'm using the LiquidCrystal library as it is written for this controller.
The code is uploaded to the Arduino and now I power it via a normal power supply with 9V.
Then it is pure luck at which position the Text appears. Most of the times at the programmed position but sometimes the hole text is shifted to the right or to the left.
In read in the .cpp file and it says, that the display won't be reseted when the Arduino is reset, so I assume the problem lays there, but I don't know how to fix it.
Thanks!

I've indented your code (difficult to read & follow without it). Added missing ';' after the delay(1000) in setup(). Was that a copy/paste error or a bug?

I have had a similar module which has displayed similar problems - randomly the lines would swap over on a whim. The best I could get was to control the power to the module to give it a power cycle when needed. I gave up on it in the end, it seems to be an inherent problem with these displays.

@JRobert just a copy/paste error. Code works fine :) Thanks!

Same cause and solution as: https://arduino.stackexchange.com/questions/43080/oled-display-crashes-when-connecting-usb


text:
Multiple transmitters and problem with ref
There are three Arduinos on a model. Each of them has a DS18B20 Dallas temperature sensor and an nRF24L01 antenna wireless communication. There is also an independent device consisting of an Arduino and an nRF24L01 antenna. Device acts as a receiver. Arduino and antenna play the role of transmitter. The code is:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>

int temp1;
int WindSpeed;
int temp2;
int temp3;
RF24 radio(7, 8);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL};
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(0, pipes[1]);
  radio.openReadingPipe(1, pipes[2]);
  radio.openReadingPipe(2, pipes[3]);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    radio.read(&temp1, sizeof(temp1));
     Serial.println("Temp1:");
     Serial.println(temp1);
     delay(50);
     radio.read(&WindSpeed, sizeof(WindSpeed));
     Serial.println(" WindSpeed Bf : ");
     Serial.println(WindSpeed);
     delay(50);
     radio.read(&temp2, sizeof(temp2));
     Serial.println("temp2:");
     Serial.println(temp2);
     delay(50);
     radio.read(&temp3, sizeof(temp3));
     Serial.println("temp3:");
     Serial.println(temp3);
     delay(50);
  } else {
    Serial.println("No radio Data avaliable");
  }
  delay(3000);
}

The problem is that the code sends some values but the correspondence isn't right in AnalogRead. How can I watch each pipe with the antenna of corresponding Arduino in order to have the right results, and each Arduino sends to the receiver through its own antenna the value of its sensor?
Thanks all for your time!

I wouldn't send those three sensor values in different packets. Just combine them in a single packet. As you are currently relying on the order of the packets, things will get messed up if a single packed isn't being received. Using a single packet will prevent his problem.  I'm not really understanding your question. I'm also missing the senders Arduino code.

@Gerben the data is coming from three distinct radio transmitters, and the question seems to be about using the radio's multiple pipes feature to keep the feeds distinct.

You appear to be using the multiple pipes of the nrf24L01 to keep your data feeds distinct, and to be asking how you can differentiate the pipes on receive.
It's not clear which exact RF24 library you are using, but if you look at the headers of a typical one you will find something like:
  /**
   * Test whether there are bytes available to be read
   *
   * Use this version to discover on which pipe the message
   * arrived.
   *
   * @param[out] pipe_num Which pipe has the payload available
   * @return True if there is a payload available, false if none is
   */
  bool available(uint8_t* pipe_num);

Additionally, you do not want to use any delays in receiving code, as that could cause you to miss transmissions - if you use delays for pacing, they should be on the transmit side.
It's not clear if you have 3 or 4 pipes (and in your setup you have forgotten that C/C++ array indexing starts at 0 not 1) but to read 3 of potentially 4, you could do something like:
#define INTERVAL_MS 10000
unsigned long lastMsg = 0;
int values[4];
char *pipeNames[] = {"Temp1:", " WindSpeed Bf : ", "temp2:", "temp3"};
void loop() {
   uint8_t pipe;
   if (radio.available(&pipe) {
     if (pipe < 3) {
        radio.read(&values[pipe], sizeof(int));
        Serial.println(pipeNames[pipe]);
        Serial.println(values[pipe]);
        lastMsg = millis();
     }
     else radio.flush_rx(); //unclear if this is needed to allow new data on a pipe that is of interest
   }
   /* warning - may mis-operate after ~50 days */
   if ((millis() - lastMsg) > INTERVAL_MS) {
      Serial.println("no data received in past 10 seconds");
      lastMsg = millis();
   }
}

Just two corrections: millis() is lowercase and from the available() prototype, you should pass in '&pipe' rather than 'pipe' so the function can modify it to the pipe that has available data. So, no need for the loop.

Thanks!   Tying "Millis" felt odd when I was doing it, but it is that way in the title of the reference page, but not for the actual function.

You want to send data from 3 (or 4?) different Arduino transmitters to one Arduino receiver and you want to be able to distinguish the packets sent by each transmitter as they are received. The most straightforward way is to create a struct for your data and attach a unique header and trailer that can be used to identify the sender.
typedef struct {
  uint8_t header = 0x01;
  int temp1;
  uint8_t trailer = 0x10;
} PACKET;

Something like this should be present in each transmitter but with unique header and trailer for each one. Then the receiver should have the header and trailer bytes for all the transmitters and, whenever it receives data, it checks the first received byte against the list of header bytes to know who sent the data before it continues. Finally, it checks the last byte to know if it's the correct trailer byte for the assumed sender and also as an additional (but perhaps unnecessary) layer of error detection to know if the received packet is a complete valid one.

This would work in the generic case, but the poster appears to be use the nrf24l01 "pipes" feature to keep their channels unique.  Since they have that out-of-band distinction, they don't need to implement an in-band one with identifiers in their data.

@ChrisStratton I agree. This is unnecessary, since the library already provides a convenient way to do it.

The actual capability comes from the radio hardware, the library merely exposes it.

@ChrisStratton True, but digging through the NRF24 docs to find this and then implement it would be a pain.


text:
Using ethernet, how do I navigate to a page on my local server
I want to access the following page on my local using my Arduino with ethernet shield"  192.168.1.2/zombie/arduino.php.  My arduino is conencted to a PC through a router. The system keeps timing out
I am using the following code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,3 };
char server[] = "192.168.1.2/zombie/arduino.php";

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  int res = client.connect(server, 80);

  Serial.println(res);

  if (res) {
    Serial.println("connected");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.println("data:");
    Serial.println(c);
  }else{
    Serial.println("NA");
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

"localhost" means the loopback interface (ie, 127.0.0.1), and so by definition cannot be accessed from any other system.  You have a local server (presumably on the same subnet as your Arduino), not a "localhost" one.

I discovered the answer after some testing.
The server var:
char server[] = "192.168.1.2/zombie/arduino.php";

should only contain the ip address.  So it should look like this:
byte server[] = { 192,168,1,2 };

The additional URL elements should be added using:
client.println("GET /zombie/arduino.php");

after a connection has been established
The final code should look like this:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,3 };
byte server[] = { 192,168,1,2 };

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  int res = client.connect(server, 80);

  Serial.println(res);

  if (res) {
    Serial.println("connected");
    client.println("GET /zombie/arduino.php");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.println("data:");
    Serial.println(c);
  }else{
    Serial.println("NA");
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}


text:
I2C begginer with I/O expander with mega328p C code
I've just started with the I2C protocol. I read about it in the datasheet, other documents, blogs and videos.
So, I started to develop my code and I think I did my first success, I succeeded to send start and check TWST for sending start signal.
I get started OK, but I can't proceed to send data. What I'm missing? I'm thinking I didn't send the correct address.
void I2C_init(void);
void I2C_start(void);
void I2C_stop(void);
void I2C_tx(uint8_t data);
void I2C_TWSR_Check(void);

void setup() {
  Serial.begin(9600);
  I2C_init();
  //  I2C_TWSR_Check();
  I2C_start();
  I2C_TWSR_Check();
  I2C_tx(0x40);           // sending the address
  I2C_TWSR_Check();       // waiting for response
}

void loop() {
  uint8_t i;
  // simple loop to blink an LED on the I/O expander pin
  for (i=0;i<5;i++) {
    I2C_tx(0xff);
    I2C_TWSR_Check();
    _delay_ms(500);
    I2C_tx(0x00);
    I2C_TWSR_Check();
    _delay_ms(500);
  }
}

void I2C_init(void) {
  //set SCL to 100kHz
  TWSR = 0x00;
  TWBR = 0x48;
  //enable TWI
  TWCR = (1<<TWEN);
}

void I2C_start(void) {
  TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
  while (!(TWCR & (1<<TWINT)));
}

void I2C_stop(void) {
  TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
}

void I2C_tx(uint8_t u8data) {
  TWDR = u8data;
  while (!(TWCR & (1<<TWINT)));
}

void I2C_TWSR_Check(void) {
  uint8_t Status;
  Status = TWSR & 0xF8;
  switch(Status) {
    case 0x08: // start OK
    Serial.println("Start is OK");
     break;
    case 0x10: // Re start
    Serial.println("Re start");
     break;
    case 0x18: // SLA+W OK ACK
    Serial.println("SLA+W OK ACK");
     break;
    case 0x20: // SLA+W no ACK
    Serial.println("SLA+W no ACK");
     break;
    case 0x28: // data OK ACK
    Serial.println("data OK ACK");
     break;
    case 0x30: // data OK no ACK
    Serial.println("data OK no ACK");
     break;
    case 0x38: // arbitration lost in SLA+W or data TX
    Serial.println("arbitration lost in SLA+W or data TX");
     break;
     default:
     Serial.println("Error");
    break;
  }
}

Can you tell us exactly what I/O expander device you are using? If you could provide a link to the documentation that would be great!

https://www.picclickimg.com/d/l400/pict/181805816595_/1pc-of-PCF8574-IO-Expansion-Board-I-O-Expander.jpg Thank you so much for reply,

I solved the problem :)

Can you post the solution as an answer and accept the answer then, it might help people that have a similar issue in the future.

Of course, but can I post it as an answer?

OK the answer is that I didn't send the correct address!
Because if the I2C starting command with the slave is successful, then you should get successful sending ACK according reading the value of transmission status from the status register TWSR and ANDing this value with 0xF8. Then by reading the datasheet you know the value of transmission status. I developed a function to determine the status of transmission with Arduino Serial library which is I2C_TWSR_Check();.
I did this code for Master transmitter and receiver only.
So the trick is that you have to fix the address according to the AVR's TW address command format, which is the first bit is for read/write command and the remaining 7-bits are for the address, so you have to shift the real address which I got by "I2C address scanner" I got from one of AVRfreaks members.
For example, if the address is 0x20, then after shifting it 1-bit to the left, the new address is 0x40 for write operation and 0x41 for read operation.
void I2C_init(void);
void I2C_start(uint8_t address);
void I2C_stop(void);
void I2C_tx(uint8_t data);
uint8_t I2C_rx(void);
void I2C_TWSR_Check(void);

uint8_t bitmask;

/////////// I2C modules addresses ////////////
// 8-bit I/O expander 0x20
#define IOEXP_WR  0x40    // I/O 8-bits expander address
#define IOEXP_RD  0x41

// LCD1602 adapter
#define LCD1602_WR  0x4E  // LCD1602 I2C adapter address
#define LCD1602_RD  0x4F

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  I2C_init();
}

void loop() {

  I2C_start(LCD1602_WR);
  I2C_TWSR_Check();
  I2C_tx(0xff);
  I2C_TWSR_Check();
  I2C_stop();
  _delay_ms(500);

  I2C_start(LCD1602_WR);
  I2C_tx(0x00);
  I2C_stop();
  _delay_ms(500);
}

void I2C_init(void)
{
  //set SCL to 100kHz
  TWSR = 0x00;
  TWBR = 0x48;
  //enable TWI
  TWCR = (1<<TWEN);
}

void I2C_start(uint8_t address)
{
  TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
  while (!(TWCR & (1<<TWINT)));
  //I2C_TWSR_Check();
  TWDR = address;
  TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
  while (!(TWCR & (1<<TWINT)));
  //I2C_TWSR_Check();
}

void I2C_stop(void)
{
  TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
}

void I2C_tx(uint8_t data)
{
  TWDR = data;
  TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
  while (!(TWCR & (1<<TWINT)));
  //I2C_TWSR_Check();
}

uint8_t I2C_rx(void)
{
  TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
  while (!(TWCR & (1<<TWINT)));
  return TWDR;
}

void I2C_TWSR_Check(void)
{
  uint8_t Status;
  Status = TWSR & 0xF8;
  switch(Status)
  {
    /////////////// MASTER TRANSMITTER //////////////
    case 0x08:
    Serial.println("Start is OK");
     break;
    case 0x10:
    Serial.println("Re start");
     break;
    case 0x18:
    Serial.println("SLA+W OK ACK");
     break;
    case 0x20:
    Serial.println("SLA+W no ACK");
     break;
    case 0x28:
    Serial.println("data TX OK ACK");
     break;
    case 0x30:
    Serial.println("data TX OK no ACK");
     break;
    case 0x38:        // arbitration lost in SLA+W or data TX
    Serial.println("arbitration lost in SLA+W or data TX");
     break;

    /////////////// MASTER RECEIVER //////////////
    case 0x40:
    Serial.println("SLA+R OK ACK");
     break;
    case 0x48:
    Serial.println("SLA+R OK NO ACK");
     break;
    case 0x50:
    Serial.println("data RX OK ACK");
     break;
    case 0x58:
    Serial.println("data RX OK NO ACK");
     break;

     default:
     Serial.println("Error");
    break;
  }
}

Question titles on SE sites should not be edited to indicate that a problem has been solved, rather the answer providing the solution should be marked accepted - even when as in this case it is your own.

I thought it's better to declare to the viewer that the problem for this topic is solved and so anyone who is browsing for a certain point on Google would see that it's solved.

The procedure for that on SE sites is accepting an answer, not editing the title.  So accept your own answer - only that will cause the system to consider it resolved and stop churning it back up as if it needs further attention.

"and stop churning it back up as if it needs further attention", what does this mean? Not so clear to me :) sorry.

Just click the hollow check mark beside your answer so we can be done with this.

authors: Вадим Грибачев

authors: Эмин Агагулиев


text:
P I D AND GY80 10 DOF
I am running the program for GY80 10 DOF , and runs fine . Date is printed on the serial monitor
How ever I have failed to use this program for my WalkerBot
(walker bot is a Robotic suit that I want to build for 4 years old my grand son He can not walk due to C P )
Unless the PID is not introduced in the program it will not be good for Balancing of the walker Both the program is as under , and my further questions are in comments
I need help Please
I tried to use the Code Control to insert the codes But it did not work , I may be excused for that Please
the codes
  #include <Wire.h>
  #include <GY80.h>

     GY80 sensor = GY80(); //create GY80 instance

  void setup()
  {
    // initialize serial communication at 115200 bits per second:
    Serial.begin(115200);
    sensor.begin();       //initialize sensors
  }

     // How to envelop this program with PID
     // where the gyro output is supposed to maintain the vertical position of the //bot , and the accelerometer will be doing countermeasure of tilts
// unless they both are on a feedback with PID this bot will not balance
//as the servomotors if do not respond in runtime the bot will fall
void loop()
{
    GY80_scaled val = sensor.read_scaled();       //get values from all sensors
    // print out values

    Serial.print("Mag:");                         //magnetometer values
    Serial.print(val.m_x,2);
    Serial.print(',');
    Serial.print(val.m_y,2);
// tried to get some output from here for using in PID but failed
if(val.m_y,2 >2 ||val.m_y,2<0){Serial.print("Output has been managed");}
but there was no output
    Serial.print(',');
    Serial.print(val.m_z,2);
    Serial.print(' ');
    Serial.print("Acc:");                         //accelerometer values
    Serial.print(val.a_x,3);
    Serial.print(',');
    Serial.print(val.a_y,3);
    Serial.print(',');
    Serial.print(val.a_z,3);
    Serial.print(' ');
    Serial.print("Gyro:");                        //gyroscope values
    Serial.print(val.g_x,1);
    Serial.print(',');
    Serial.print(val.g_y,1);
    Serial.print(',');
    Serial.print(val.g_z,1);
    Serial.print(' ');
    Serial.print("P:");                           //pressure values
    Serial.print(val.p,5);
    Serial.print(' ');
    Serial.print("T:");                           //temperature values
    Serial.println(val.t,1);

    delay(250);        // delay in between reads for stability
}

It is a mess Sorry I failed to organise It

I don't see a question in either the title or in the text.

why this program is  causing erratic movements? , making the test bench fall immediately , 2. Why the motors do not react to the tilt of the Gyro Board.

Code Gorilla Thank you for making the post neat , I felt very embarrassed when I failed to make it look elegant and had to post it like a grade 1 kindergarten student . I appreciate Thanks

I am sorry, but I may not have understood your post, but I think the problem is your code doesn't work and you don't know why.  I think the problem is with this line:
if(val.m_y,2 >2 ||val.m_y,2<0){

It is because it is not valid code, I suspect its a cut and paste error and should be
if(val.m_y > 2.0 || val.m_y < 0.0){

the ,2 you use in the print statements specifies the number of digits to print after the decimal point (I think).


text:
Video streaming by ESP32
I'm making an Arduino car and controlling it with a game-pad by bluetooth.  I want to have a live video from it by using ESP32 board and ov7670 camera or vc0706 camera. How can I do this ??

I don't know how to strat

Start with checking how feasible your requirements are (I guess Arduino and a camera is not feasible, same as esp32 for live video), but try and you will find out.

@MatsK - Are you sure its not feasible on an ESP32?  I can't find any examples, a but 240MHz dual core should be able to stream low res video I would have thought.

My bad, I missed that it was ESP32.

See the documents and information of arducam library it may help you.....
This lib uses to connect with OV5640 5MP Camera and in its examples you may got your answer...

There is only one sort of ESP32 type board supported by Arducam as far as I can see and it still seems to be limited to still images.


text:
Weird Arduino LED behaviour
I noticed something when I was trying something with leds;
  pinMode(13,HIGH); // giving +5V to pin 13.
  delay(1000);      // waiting for 1 sec.
  pinMode(13,HIGH); // giving +5V to pin 13 again.
  delay(1000);      // waiting for 1 sec again.

  //loops forever.

But I couldn't light the led. What is the reason behind this? Shouldn't it be lit forever?

Is that the whole program?

@Ignacio Vazquez-Abrams no,the pin is initilized before setup func. and this is in the loop func.

Maybe you should post the whole program then?

pinMode is not the function to use to set a level on a pin, it's used to setup the pin as input, input with pullup, or output. Use digitalWrite in your loop.

As already in the comments, you are using pinMode(...) where you should be using digitalWrite(...)
The code should look like
void setup() {
  pinMode(13, OUTPUT); // sets the pin to an OUTPUT, it can now source or sink current
}

void loop() {
  digitalWrite(13, HIGH); // sets the pin to +5V
  delay(1000); // waits 1 sec
  digitalWrite(13, HIGH);
  delay(1000);
}

When you use pinMode(13, LOW) you are actually writing pinMode(13, INPUT) as LOW and INPUT are two aliases for the same value (0, by the way).
When in INPUT mode the PIN doesn't source or sink any considerable current, so I can't say much more about why the LED is turning on unless you provide a schematics of your circuit (but I have idea you are doing something really wrong).
It might be useful to have a look at this simulation:

on the left the LED is connected directly to voltage source without control from Arduino
in the middle, the LED is controlled by Arduino on the high side: click on the letter to toggle the pin state
on the right the LED is controlled on the low side