I have a problem with my nano arduino and the nrf24l01 as receiver Hello I have a problem with my nano arduino and the nrf24l01 as receiver . I'm trying to upload my code to my board, but it say that my code have this mistake:

Receiver:45:10: error: void value not ignored as it ought to be

exit status 1
void value not ignored as it ought to be

the complet code is:

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

//Receiver Code (Hand)

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem

//define the servo name
Servo myServo1;
Servo myServo3;
Servo myServo4;
Servo myServo2;
Servo myServo5;

RF24 radio(9,10);     /*This object represents a modem connected to the Arduino.
                      Arguments 9 and 10 are a digital pin numbers to which signals
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int msg[5];

void setup(){

  //define the servo input pins
  myServo1.attach(15); //A1
  myServo2.attach(16); //A2
  myServo3.attach(17); //A3
  myServo4.attach(18); //A4
  myServo5.attach(19); //A5

  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);   //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }

void loop(){
  if(radio.available()){
    bool done = false;
    while (!done){
    done = radio.read(msg, sizeof(msg));

    myServo1.write(msg[2]); //A1
    myServo2.write(msg[4]); //A2
    myServo3.write(msg[3]); //A3
    myServo4.write(msg[1]); //A4
    myServo5.write(msg[0]); //A5
    }
  }
}

and the problen is here:

done = radio.read(msg, sizeof(msg));

I don't know hoy to make that comes out as a code. I'm sorry.
I'm trying to program a bionic hand but i have just started to work with arduino boards and their respective prongram. If someone can help me I would be very grateful. thanks

radio.read() does not return a value.  You can't assign "no value" to a boolean.

If radio.available() is true then radio.read() will succeed. There is no need to test if it worked or not.


Finding address of OLED using I2C communication and Arduino It is known that address of OLED SSD1306 is 3C. The frame format is as follows:

The figure implies that the binary pattern should be 01111000 for the first frame (considering write mode and the second last bit is a dont care).
So I was trying to send the first frame using Wire.h library. The following is a code
Wire.beginTransmission(0b01111001);
But i receive a nack (return value of 2)

However, If I send 00111100, i receive a ack(return value of 0). What is wrong in my interpretation?

You misinterpret how the Wire library is used. Though the first byte in the transmission is called the address byte, the actual address consists only of the 7 higher bits in that byte. The direction bit is not in the address.

So the Wire.beginTransmission() method wants the address as parameter, without the direction bit. That bit is set corresponding to the used function (0 for Wire.beginTransmission() and 1 for Wire.requestFrom()).

0b0111100 is the real address (when connnecting the address pin to ground)(note, that there are only 7 bits, since the address only has 7 bits). The write operation address byte will then be 0b01111000, though the library is hiding that way from you. You need to provide the 7 bit address to the function.

  the second last bit is a dont care

As mentioned above, that is not correct. This bit (the least significant bit of the address) is set by the address pin SA0. It seems, that you have it tied to ground, which sets the corresponding bit in the address to zero. If you would tie it to Vcc, it would be 1.


Calling functions from an array of pointers in a library causes 'undefined reference to' error I am trying to create a library, where I have an array of pointers to functions in it. This array is used by other functions in the library. This is the code of the header file:

class Lib {
  public:
    static void call();
    static void (*caller[])();
  private:
};

This is the code of the .cpp-file:

#include "Lib.h"

void (*caller[2])();

void Lib::call() {
  caller[0]();
}

The sketch executing this is

#include <Lib.h>

void setup() {
  Lib::call();
}

void loop() {}

When I try to compile this, I get the following error:

  undefined reference to `Lib::caller'
  collect2: error: ld returned 1 exit status
  Mehrere Bibliotheken wurden für "Lib.h" gefunden

Another weird thing is that the error about the multiple found libraries goes away if I take away the line

Lib::call();

However, if I put the same code directly into the sketch like so:

void (*caller[2])();

void call() {
  caller[0]();
}

void setup() {
  call();
}

void loop() {}

I get no error. What's the problem here?

void (*caller[2])();

should be:

void (*Lib::caller[2])();

Since you are defining storage space for a static member variable you have to tell the compiler what class it's a static member of.


Converting human readable date to a unix timestamp Can anyone provide a sample code that would convert a human readable date like 2019-10-27 22:10:35 to a unix timestamp like 1572214235?

I found many topics about it, but they eider refer to out of date libraries, or they seem to address more complex time functions, I find it hard to extract this functionality from them.

After parsing the time into numbers, you can use the standard C time library time.h. More specifically, use the mktime function to convert a struct tm into a time_t, and use difftime to get the seconds since the start of the Unix expoch:

#include <time.h>

void loop() {
    struct tm ltm = {0};
    ltm.tm_year = 2019 - 1900;
    ltm.tm_mon  = 11 - 1;
    ltm.tm_mday = 5;

    double epoch_seconds = difftime(mktime(&ltm), (time_t)0);
    Serial.print("Remember, remember, ");
    Serial.print(epoch_seconds);
}

Note that in struct tm, the year starts at 1900 and the month starts at 0.


Can anyone explain how to use MPL sensor with Arduino MEGA? I am trying to connect a MPL3115A2 Altitude/Pressure/Temp Sensor Breakout which I bought from Hobbytronics to my Arduino Mega. What I had in mind was (Breakout -> Arduino):

3.3V -> 3.3 V
GND -> GND
SDA -> A4
SCL -> A5

The information which I've found so far is very conflicting and I'm not sure whether or not I should be using pull-up or in-line resistors, and if so, what value?

The code which the product page links to also differs, with one stating that the Wire library is unsafe to use with a 3.3V rated sensor due to the internal pull-ups, but the other code uses the Wire library?

If anyone could advise me on how best to use this sensor without frying it, it would be much appreciated!

Product information
Code

Since the device is 3.3V and the Arduino is 5V, you will need a I2C level converter such as the TCA9517. Simply supply the Mega side with 5V and the device side with 3.3V and attach 4.7kohm pull-ups to 5V on the Mega side, and it will convert both SDA and SCL for you. You won't need pull-ups on the device side since it includes pull-ups on the board.

For I1 and I2 (push-pull outputs) you can use either normal level converters or you can use a SN74LVC2G07 along with the pull-ups found on the Mega inputs.


Is it possible to use Serial window for debug statements while using the hardware serial port for GPS module? I am using the hardware serial ports of Atmega 328 to connect to a GPS module . A GSM SIM900 module is connected via Software serial . Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports? Both my module and the Serial window is set to 9600 bps baud rate .
Also I want to read the GSM responses from the Software serial and print the same in the Serial window for debugging. Is this possible?

Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports?

Yes, that works.  If you connect the Arduino TX pin 1 to the GPS RX, then everything you print to Serial goes to both the Serial Monitor window and the GPS device.

This works, because:

It's ok if you see the GPS configuration commands (if any) on the Serial Monitor window.  Your debug prints will appear after them.
The GPS device ignores anything that doesn't start with a '$' character; it ignores all your debug prints.


Simulink with arduino : data acquisition I'm working on data acquisition from a sensor attached to the Arduino : MPU6050 using a model in Ssimulink. I have installed the hardware support in Simulink but I don't know how to start building the model. The model must read the data from the Arduino by deploying it into the Arduino.

My connection Arduino <=> MPU6050 is :

Arduino    MPU 9150
3.3V       VCC
GND        GND
A5         SCL
A4         SDA
DIGITAL 2  INT
GND        AD0

update : i have use a s-function but I get the following error:
_The call to realtime_make_rtw_hook, during the after_make hook generated the following error: Could not download the model to the target hardware. Verify the connection between the computer and target hardware.

The build process will terminate as a result.

Caused by: Could not download the model to the target hardware. Verify the connection between the computer and target hardware._

But the target is definitely connected, and downloading others module (like led blinking ) with simulink is working fine. I've also tested this on a different PC with Windows 8 (64bits) with the same result. Can anyone give me a hint please?

I just made my GY-521(MPU6050) work with Simulink using s-function.
I wish this would be helpful for you.

I am using an Arduino MEGA 2650 board. The sensor data is read in in real time.
Note that currently only Arduino MEGA 2650, Arduino MEGA 2650 ADK, and Arduino DUE support the real time windows target.
If you are using other types of board, this answer may not applied.

Your hardware connection looks correct. But if you have some troubles you can refer to mine for checking:

5v VCC
GND GND
SCL SCL(check the register map of your board)
SDA SDA(check the register map of your board)

Above four connections are adequate if you just read raw sensor data.
INT is needed if you are going to read fused data. But I did not try that.

Next you may write a small program in Arduino IDE to ensure everything works.
You can refer to the Arduino MPU6050 examples.
The code written here will be used to construct your Simulink s-function later.

Now you can start to build your Simulink block using s-function builder.
If you did not do this before, here is a good tutorial:

https://m.youtube.com/watch?v=_OLctOFjjYQ

In our case, you need to copy Wire.h, twi.h and their .c counterparts in your current working directory where your s-function resides.

And do not forget to rename generated .c file to .cpp, and add external "C" declaration. All of these are illustrated in above video tutorial.

After all of above are done, you turn your simulation mode to external, and run.
You can view your sensor data in scope if everything goes right.

Source code and configuration used in my function:
I include all headers in the Libraries panel of S-Function Builder,

#ifndef MATLAB_MEX_FILE
#define ARDUINO 100
#include <Arduino.h>
#include <Wire.h>
#include <Wire.cpp>
#include <twi.h>
#include <twi.c>
#define MPU 0x68
#endif

Wire.* and twi.* files are copied from Arduino IDE's directory. I put these files along with my S-Function block file.

The address of I2C is 0x68 here.

Next, the code for sensor outputs are placed in Outputs panel. And do not forget to add ports in Data Properties panel.

#ifndef MATLAB_MEX_FILE
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true);

int raw = Wire.read() << 8;
raw = raw | Wire.read();
ax[0] = (float)raw / 8192.0f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
ay[0] = (float)raw / 8192.0f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
az[0] = (float)raw / 8192.0f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
temp[0] = (float)raw / 340.0f + 36.53f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
gx[0] = (float)raw / 131.0f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
gy[0] = (float)raw / 131.0f;

raw = Wire.read() << 8;
raw = raw | Wire.read();
gz[0] = (float)raw / 131.0f;
#endif

Finally, initialization and configuration are done in Discrete Update panel.

#ifndef MATLAB_MEX_FILE
if (xD[0] != 1) {
    Wire.begin();

    /* Do not sleep */
    Wire.beginTransmission(MPU);
    Wire.write(0x6B);
    Wire.write(0);
    Wire.endTransmission(true);

    /* Gyroscope full scale range: 250 degs/s */
    Wire.beginTransmission(MPU);
    Wire.write(0x1B);
    Wire.write(0);
    Wire.endTransmission(true);

    /* Accelerometer full scale range: 4g */
    Wire.beginTransmission(MPU);
    Wire.write(0x1C);
    Wire.write(8);
    Wire.endTransmission(true);

    xD[0] = 1;
}
#endif

Please refer to your board's datasheet for specific address and LSB scales. I am using GY-521 here.


How to get the sizeof array of structs I'm trying to make a use of a relay module,
I want a clear way to configure and control my relay module
I've defined the struct and filled it with some info about id, pin number, title, and relay state
I can't loop with for in the array of controls, because I can't get the sizeof the array right
typedef struct{
  int id;
  int pin;
  String title;
  bool state;
}  SwitchControl;

SwitchControl controls[2] = {
  {1, 22, "Switch 01", 1},
  {2, 23, "Switch 02", 0},
};

for(int i=0; i<sizeof(controls) - 1; i++){
}

thanks

To make it generic, you simply divide the sizeof the array by the sizeof the type:
for(int i=0; i<sizeof(controls)/sizeof(SwitchControl); i++){
}

Then you can later change the items if the array, or the structure and the code will be the same.


Why do I need to use latin-1 instead of utf-8 when using python with arduino? When reading and writing with a python serial port connection to arduino, if I don't use latin-1 ('ISO-8859-1'), the results are not as expected. Like if I have
int outP = 5;
//...
int outV = Serial.read();
analogWrite(outP, outV);

While with python I have
serial_port.write(chr(255).encode())

I read 3.78 V from the pin, whereas if I use
serial_port.write(chr(255).encode(encoding = 'latin-1'))

I get 5.04 V. I have read latin-1 and utf-8 don't always match, but is there something about arduino that requires using latin-1? Of course, these return different values when testing each encoding, using 255 gives b'\xc3\xbf' (from 'Ã¿') with utf-8 or b'\xff' from ('ÿ') with latin-1, but why does arduino work with latin-1?
FYI other options that work are
v = 255

serial_port.write(v.to_bytes(1, byteorder = 'big'))

serial_port.write(bytes[v])

but is there something about arduino that requires using latin-1?

No, not really.
What it comes down to is that Serial.read() reads bytes, irrespective of whatever encoding they may be being used with.  ISO-8859 only encodes character code points in the 0-255 range, so when you choose a 0-255 code point and send it as ISO-8859, it gets sent as 1 byte, which is how you're code has been written to receive it.
A 255 code point as utf-8 would require multiple bytes to encode and so would result in multiple Serial.read() calls for a given value.
If you open a python3 REPL and put chr(255).encode() or more explicitly chr(255).encode('utf-8') you will see it results in b'\xc3\xbf'.  So on the Arduino side you will see this as two separate Serial.read() results, 0xC3 and 0xBF.
When you're just taking in strings and UTF-8 and splatting them out via Serial.println(), the Arduino is blissfully unaware of that they're UTF-8 and not ISO-8859.  Really you could use any encoding you wanted, the the caveat being that if you're using c-strings to store them, the encoding would need to be one that doens't allow for a single null byte to be in the middle of the string.

You may want to look into using struct.pack rather than cobbling together python bytestrings with sequences of chr() and .encode(whatever). struct.pack will also result in a bytestring, but it's more purpose built for doing this.
You can import struct and then struct.pack('B', 255) will result in b'\xff same as chr(255).encode('iso8859-1'), but at least expresses intent.  'B' here signifies an unsigned char range, you'll find the format specifiers in the documentation. You'll get a greater benefit when you begin using multiple fields where struct.pack will be a lot less unwieldy than the chr and encode and string concatenation.


How can I make my custom board use the programmer selected in "Tools->Programmer" when the Upload button is pushed? I've created a custom board that can be programmed using any one of several programmers defined in programmers.txt. I would like the user to be able to choose which programmer to use via the "Tools->Programmer" menu options.

I tried using {protocol} and {upload.protocol} in platform.txt to pass the programmer to the upload tool, but neither seem to be defined when the Upload button is used to initiate the upload (they are defined if Upload using programmer is selected from the menu).

Make sure you do not have a protocol listed in the boards.txt file. If the uploader sees protocol is null then it will fall back to using the same code that "Upload using programmer" does.

Relevant code in SerialUploader.java:

    if (usingProgrammer || prefs.get("upload.protocol") == null) {
      return uploadUsingProgrammer(buildPath, className);
    }


Reading data from ThingSpeak via Arduino Uno+ESP8266 I am integrating thingspeak and arduino plus Esp8266 mean making a simple project which contain my android app to update the thingspeak channel and then want to read the data of that channel via arduino uno. the android parts works fine but at the arduino side i got stuck and unable to read the channel data via esp8266(attached to my arduino uno).
Here is my code.any help would be appreciated.
it shows in serial monitor connecting to thingspeak.com and show nothing next.

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif

char ssid[] = "M T G";            // your network SSID (name)
char pass[] = "androidGUII";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "arduino.cc";

// Initialize the Ethernet client object
WiFiEspClient client;
static const char* host = "api.thingspeak.com";
static const char* apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
void setup()
{
  // initialize serial for debugging
  Serial.begin(115200);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }
  // you're connected now, so print out the data
  Serial.println("You're connected to the network");
  printWifiStatus();
  Serial.println();
}

void loop()
{
      const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
    }
  client.println("GET /channels/xxxxxxx/feeds.json?api_key=xxxxxxxxxx&results=2 HTTP/1.1");
  while (client.available() == 0);  // wait till something comes in; you may want to add a timeout here
  Serial.println(client.read());
  client.stop();  // close socket
  delay(10000);
}
void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

HTTP GET request needs to end with an empty line and HTTP 1.1 requires a Host header.

Add an empty line and eiher change the HTTP version to 1.0

client.print("GET /channels/421932/feeds.json?api_key=");
client.print(apiKey);
client.println("&results=2 HTTP/1.0");
client.println(); // empty line

or add the Host header

client.print("GET /channels/421932/feeds.json?api_key=");
client.print(apiKey);
client.println("&results=2 HTTP/1.1");
client.print("Host:");
client.println(host);
client.println(); // empty line


Running loop for a specific time period I currently have a loop that runs without a time condition:

unsigned long previousMillis = 0;        // will store last time LED was updated

int WET=4;//wet line
int DRY=5;//dry line
int Inhale=1000;//msec
int Exhale=1000;//msec
//int Noflow=3000;//msec

void setup() {
  // put your setup code here, to run once:
  pinMode (WET, OUTPUT);
  pinMode (DRY, OUTPUT);
}

void loop() {
  //inhale
  digitalWrite(WET,LOW);
  digitalWrite(DRY,HIGH);
  delay (Inhale);
  //exhale
  digitalWrite(WET,HIGH);
  digitalWrite(DRY,LOW);
  delay (Exhale);
  //No flow
  //digitalWrite(WET,HIGH);
  //digitalWrite(DRY,HIGH);
  //delay (Noflow);
}

Then i have tried to code a "timer" for each cycle,but i got error:"
exit status 1
Error compiling for board Arduino/Genuino Uno."

Code with timer:

unsigned long previousMillis = 0;        // will store last time LED was updated

int WET = 4; //wet line
int DRY = 5; //dry line
//int Inhale=1000;//msec
//int Exhale=1000;//msec
//int Noflow=1000;//msec
int BPM = 60;
int IE = (((60 * 1000) / BPM) / 2);

void setup() {
  // put your setup code here, to run once:
  pinMode (WET, OUTPUT);
  pinMode (DRY, OUTPUT);
}

void loop() {
  for (int i = 0; i = 20;)
    int BPM = BPM + 10;
#include <elapsedMillis.h>

  elapsedMillis timeElapsed;
  unsigned int interval = 60000; //one minute in ms

  while (timeElapsed < interval) {

    //inhale
    digitalWrite(WET, LOW);
    digitalWrite(DRY, HIGH);
    delay (IE);
    //exhale
    digitalWrite(WET, HIGH);
    digitalWrite(DRY, LOW);
    delay (IE);
    //No flow
    //digitalWrite(WET,HIGH);
    //digitalWrite(DRY,HIGH);
    //delay (2000);
  }
}

Target ouput: to run every cycle of the loop for 1 min.

Any one familiar with this error?
Many thanks for your help

Your code has a number of problems:

Don't put #include statements for header files in the middle of your code. They belong at the top, before any other code. (What is the header file elapsedMillis.h?)

Another thing: Your for loop is a mess. It should read something like: for (int i = 0; i < 20; i++) (That would cause the for loop to run 20 times, with the value of i ranging from 0 to 19.) However, what do you want to happen in your for loop? Without braces after that code, the ONLY line that will execute 20 times is the int BPM = BPM + 10; line (which doesn't make any sense.)

You really shouldn't use time-based while loops inside your main loop function. That defeats the purpose of using timers instead of delay statements. And you should get rid of your calls to delay() and use millis() to manage all your timing. Do a search on "Arduino blink no delay" and study the examples for information on how to restructure your code.


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, 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.


Arduino Yun, pass int data true REST Would it be possible to instead of passing a state via a REST browser:

digital/13/1

to set an int value? For example, if in the sketch if I would name an int: 2, could I set this to 48 via REST?

If so, how?

Check out the TemperatureWebPanel example: you'll see that you can make your own REST APIs and pass any values your sketch can handle.


Why can't I see the serial plot with the following code for arduino? const int GSR=A0;
int threshold=0;
int sensorValue;

void setup(){
  long sum=0;
  Serial.begin(9600);
  delay(1000);

  for(int i=0;i<500;i++)
  {
  sensorValue=analogRead(GSR);
  sum += sensorValue;
  delay(5);
  }
  threshold = sum/500;
   Serial.print("threshold =");
   Serial.println(threshold);
  }

void loop(){
  int temp;
  sensorValue=analogRead(GSR);
  Serial.print("sensorValue=");
  Serial.println(sensorValue);
  temp = threshold - sensorValue;
  }

The serial plotter requires just numbers and nothing else.

It can't understand the data in the format:

sensorValue=49

It just expects:

49

Remove the line

Serial.print("sensorValue=");

and it will start working.


Debugging a RadioShack Arduino motor/sensor shield I bought a cheap "Make" kit at RadioShack, which includes some sort of proprietary Arduino Uno compatible motor/sensor shield. Naturally, the documentation is pretty bad. The documentation and Arduino code for the kit is here:

https://github.com/RadioShackCorp/2770168-MakeItRobotics-Starter-Kit

It includes a circuit schematic (2770168-CorePCB_schematic.pdf), but I'm still having trouble mapping the pins to the Arduino's pins. Can anyone help me make sense of this?

What I've made out so far is the shield's screw terminals appear to be connected to quadruple h-bridges. However, there are several other pin headers that I can't quite make out. I think it also directly exposes 4 of the Uno's ADC pins and 4 DIO pins. There are four pins for dual IR line sensors, but there's a lot of circuitry between these and any Arduino pins. Almost everything feeds into a DC6688F2SCN chip, but I can't find a datasheet anywhere, so I have no idea what it does.

The manual says jumpers on J16 need to be removed in order to connect to the Uno over USB, so it looks like I can't use the shield with the board and debug via USB at the same time. Is this board worth investigating or should I trash it?

There is a bit of info on the DC6688F2SCN here: Chip Selection Guide, but Chris is 100%. Without the firmware, all you can do is look at the source code for the Arduino side.

If you look closely at the top of the board, you can see that one side of J16 goes to pins 2 & 3 and the other to 0 & 1. On the schematic, there are some other components hooked in there as well. The serial is definitely going using 0 & 1. I'm not sure why they have them wired to 2 & 3. It's probably a good idea not to put anything on any of these four pins.

That's pretty good though. Compare it to the SainSmart L293D shield, which is significantly cheaper but eats up eight digital pins when driving four motors. Also, the L293Ds can only put out 600 mA per channel while the Bs can do a full Amp.

The documentation isn't very good and the supporting code also has some issues; but, overall, this is a pretty decent package. It comes with the erector set pieces as well. You also get three IR sensor channels.


How do I use 3 Hc-sr04 ultrasonic sensors to control 3 vibration dc motor? This code we are using only one motor and one hc-sr04 ultrasonic sensor, the code is shown below:

#define trigPin 7
#define echoPin 6
#define motorPin 5

void setup()
{
  Serial.begin(9600);// to use the serial monitor
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorPin, OUTPUT);
}

void loop()
{
  int duration,distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2)/29.1;
  Serial.print(distance);//to print the distance on the serial monitor
  Serial.println("cm");

  // to make the motor vibrate depending on the distance
  // if the ultrasonic sensor is too far from the obstacle it will vibrate slowly
  // if the ultrasonic sensor is very close to the obstacle it will vibrate very fast

    if(distance <= 60 && distance >= 45)
    {
      // to make the motor vibrate
    digitalWrite(motorPin, HIGH); // making the motor on

    delay(200);
    digitalWrite(motorPin, LOW);// making the motor off
    delay(200);
    }

    else if(distance < 45 && distance >= 30)
    {
    digitalWrite(motorPin, HIGH);
    delay(100);
    digitalWrite(motorPin, LOW);
    delay(100);
   }
    else if(distance < 30){

    digitalWrite(motorPin, HIGH);
    delay(50);
    digitalWrite(motorPin, LOW);
    delay(50);
  }
  else
  {
    digitalWrite(motorPin, LOW);
  }
}

We want you to tell us your comment about the code.

And we want to add two more motors and two ultrasonic sensors, one of them in the left and the other in the right.

We want you to help us in the code, because we don't know how we can change it for two other motors.

There's a few things you need to consider when making multiple things happen at the same time.

Firstly is timing. You can't make two things happen concurrently with different timings if you have delay() in there, since nothing else can happen while delay() is executing.  So you have to get rid of all delay() calls and replace them with examining the difference between successive calls to millis().

For instance, imagine you're in the kitchen and you want to boil and egg and make a cup of tea at the same time.  You fill the kettle and turn it on.  You put a pan of water on the stove with an egg in it to boil.

Now you could sit and stare at the egg until it's boiled enough for you to eat, but what happens to the kettle while you're doing that?  It's boiled, turned itself off, and started to go cold.

So instead you put the egg in the pan and look at the clock.  Then you think "in 5 minutes I will take the egg out of the boiling water".  You might set an alarm for 5 minutes time if you have one, or you may keep glancing at the clock periodically to see if the 5 minutes have past yet.  Meanwhile the kettle has boiled and you've made your cup of tea.

Then the 5 minutes have passed.  You know that because you remembered what time you put the egg on to boil and you know what the time is now, so you can subtract one from the other to find that 5 minutes have passed.

Now let's make it a little more complex.  Imagine you want two eggs - one soft boiled and one hard boiled.  The hard boiled one may want 8 minutes, the soft boiled one 5 minutes.

So you put one egg on to boil and remember the time.  Roughly three minutes later you put the other egg in and also remember that time.

Once enough time has passed that the first egg has been in 8 minutes you take it out.

Once enough time has passed that the second egg has been in 5 minutes you take it out.

You have had to remember two start times which you then compare separately to decide what to do with each egg when.

To translate that to your program - you have to remember a start time for each action for your motors, along with the state of the motors - and when the right time has elapsed you change the state of the motor (motor on -> motor off - egg in pan -> egg on plate) and remember the time at which you changed the state so you can know when to change the state again.

That's exactly what the BlinkWithoutDelay example does to make an LED change state (on -> off -> on) at certain times by remembering when it last changed state so you know when to change the state next.


I²C between ATTiny85 (8MHz) and Arduino Uno I keep receiving the following error in myATTiny85-Slave code below:

sketch_mar12a.ino: In function 'void setup()':
sketch_mar12a:19: error: 'class USI_TWI_S' has no member named 'onRequest'

I have downloaded TinyWireS and TinyWireS.h clearly has a public function onRequest. I opened the .ZIP file (downloaded from https://github.com/rambo/TinyWire) and drag-dropped TinyWireS folder into the Arduino libraries folder. This is how I install ALL libraries.
I am using Arduino 1.0.6
What am I doing wrong?
ATTiny85-Slave Code:
#include "TinyWireS.h"                  // wrapper class for I2C slave routines
#define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)

byte t=10;

void setup()
{
   TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
   TinyWireS.onRequest(requestEvent);
}

void loop()
{
}

void requestEvent()
{
   TinyWireS.send(t);
}

Arduino Uno-Master Code:
 #include <Wire.h>
 #define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)

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

 void loop()
 {
      byte num;

     // read 1 byte, from address 0x26
     Wire.requestFrom(I2C_SLAVE_ADDR, 1);

     while(Wire.available()) {
          num = Wire.read();
     }

     Serial.print("num = ");
     Serial.println(num,DEC);
 }

I was able to compile your code "ATTiny85-Slave Code" without problems.

You can try to extract the contents of the ZIP archive (i.e. the library) directly to the directory where your sketch is stored. #include "TinyWireS.h" should then pick up that version.

You should also switch on verbose output for the compilation to have a look at the directory in which the code is compiled. Here you would find (at least in my older Arduino IDE version) copies of the included files. (/tmp/build... on Linux systems.) You can then make sure the proper version of the files is used.

You can also search your drives for other copies of TinyWireS.h.


How long does it take for a servo to change rotation? I have an Arduino Uno and a Micro Servo 9g A0090 servo.

Given that Servo.read() simply returns the last value written to the servo I guess there is no way to query a servo's actual position.

If I can't query the servo, how do I know that the servo rotated to the position of my last write() call?

Rotating from 0 to 180 will take longer than rotating from 0 to 10. How do people normally handle this scenario? Perhaps I just time how long it takes to go from 0 to 180 and then always call delay() afterward to give the servo time to complete its rotation?

Normal servos don't provide any feedback. Their speed depends on the servo's specs and the load.

You could measure the time it takes to rotate a certain angle and use that to calculate the time, then add some safety margin. But if the load isn't constant, the times will be off.
You could change the position slowly, but that still doesn't guarantee that the servo will do what you told it to.

If you want to know servos's position, you need a servo that outputs it. There are servos that expose the signal from their internal potentiometer.

Adafruit sells them and has a useful guide about them.

You can also modify a normal servo yourself, by attaching a feedback wire to the potentiometer's wiper pin.


ATtiny84A support with "Attiny" board manager installed to Arduino IDE Referring to page http://highlowtech.org/?p=1695, is it possible to program ATtiny84A as well, or just the chip version ATtiny84 (without "A")? Does anybody know?

According to the PDF ATTiny24/44/84 to ATTiny24A/44A/84A Migration AppNote it should be pretty easy as there are only some differences in electrical specifications. No changes in registers or so.

The signature bytes are the same too, so it should be posible even without adding another boards.


bi-directional nrf24 communication The central arduino

The 1st node

The 2nd node

I want the central to send to the first node the rgb code like a string on the loop

  "rgb: 255000255"

but when it detects something to PIR to send a string to central.
In addition every some seconds the 2nd node to send a string to the central the temperature.

As i mentioned in my previous questions i have some problems when it comes to the bi-directional comunication. I have tried a lot of code. Can someone show me how to achieve what i want to do if not with code, with steps. Please help me!!

You cannot (easily) have all nodes on the network with the same address.

There are ways of doing it but they aren't easy.  They basically involve creating a "broadcast" facility in your network, and that has certain caveats involved with it.

The nRF24L01 modules have an "auto-ACK" mode to give reliable communications.  This only works with 1:1 addressing and cannot work with broadcast.  If you want to (as most people do) use the auto-ACK facility then you have to have each node with its own unique address.  After all, if you're sending the ACK to a station, and there are multiple stations with that address, which one will ACK?

So you have to think about if what you are trying to achieve is really the right way of going about it.  It sounds like you want to just program another node with the same code as an existing node without making any changes to that code and "just have it work".  That's a very advanced topic and one that even I would spend quite some time implementing it.  Yes, you can do unreliable communications (i.e., no auto-ACK) then you could have all the remote stations with the same address, but I would certainly keep the master as a unique address.  Better would be for each node to start up with a pre-defined address which it then uses to ask the master for a unique address (a-la DHCP) and the master then keeps a list of what is connected on what address.  From then on it can use reliable communications to send and receive data to each node as it needs to.

A system I wrote for the chipKIT boards gives each node two addresses - its own unique address which you have to provide manually, and a more global "broadcast" address.  They are each on different pipes within the nRF24L01.  To communicate with an individual node you send to its unique address.  To broadcast to all nodes you send to the broadcast address.  If you're sending to the unique address you can then turn on auto-ACK. If you're sending to the broadcast address you don't turn on auto-ACK.

Note that using auto-ACK is a whole topic in itself and requires careful design planning to get it to work properly.

Also you have to think about what happens when you send a broadcast packet out and it's received by other nodes - how do they handle that data? Sending temperature data out globally, it will be received by the RGB receiver, which may try and interpret it, causing problems.  You need to come up with a way of identifying just what it is you're sending out and only having the right nodes responding to the right data.  That means coming up with a strict packet format.  Luckily the nRF24L01 chips communicate in fixed packet sizes (incidentally, all nodes on the network will have to be set to use the same packet size or it just won't work) up to 32 bytes, so implementing a packet structure over that is easy enough.  Just sending strings of data is both hard to interpret and incredibly inefficient.  You should be sending the data as actual data values in variables as part of the packet structure.


WS2812 - First are white and then they turn red/yellow/orange near the end I'm trying to power about 150 WS2812 LEDs from my ESP8266 NodeMCU board (running NeoPixel Arduino code). The first few LEDs are white, but about half way down, the LEDs turn yellow, then they turn orange, and at the end they're basically red.

Could this be caused because of the power draw? The strip itself is currently drawing about 900 mAh, and I am powering the ESP8266 with a 1.5A 5v supply. The LEDs are running off 3.3v directly from the ESP8266.

Also, after like 2 minutes, the LEDs turn off completely. The board never disconnects from my WiFi. They just turn off. I can turn them on again right after.

See Powering NeoPixels.

  Each individual NeoPixel draws up to 60 milliamps at maximum brightness white (red + green + blue).

  ...

  To estimate power supply needs, multiply the number of pixels by 20, then divide the result by 1,000 for the “rule of thumb” power supply rating in Amps. Or use 60 (instead of 20) if you want to guarantee an absolute margin of safety for all situations. For example:

So you need at least 3 amps or even 9 amps for absolute safety.

  The LEDs are running off 3.3v directly from the ESP8266.

I doubt it is designed for that. The internal traces won't be designed to handle maybe 5 amps.

To avoid colour degradation through the strip you could use multiple power supplies (to avoid the voltage dropping due to the resistance over the strip). You would connect the grounds (and connect the data wires of course) but break the +5V line in the middle and insert another power supply.

However one (fairly powerful) supply directly connected to the NeoPixels might do the trick. That is, not through the ESP8266.

Also see NeoPixels Revealed: How to (not need to) generate precisely timed signals.

On that page:

  Q: In the video, when the entire strip is lit full white, it looks like the far end has a orange tint to it. Is this an artifact of the camera or something?

  A: Wow, you are very perceptive! Yes, the string did start to get orange at the end at full power. I actually didn’t just run out of apartment when making this long string – I also ran out of power supplies. I had 3 supplies, each 10amps. This is almost enough, but not when every single LED is full brightness white. When that happens, the voltage at the very end of the strip starts to get too low and the LEDs start looking pallid. Why orange? Because blue LEDs need the highest voltage drop to light so when the voltage sags they are the first to go followed by the greens – leaving yellows to oranges and ultimately red.

(He had 1000 pixels). So this guy used 3 separate 10 amp power supplies!


Reading button presses with the 74HC4067E multiplexer My project is progressing quite well, but I am having some issues reading button presses through my MUX.

The Goal

Cycle through twelve buttons and twelve LEDs. When a button is pressed, light up the corresponding LED. I have one MUX for the LEDs which is working great thanks to the stack exchange community. My button MUX is the issue.

The Symptom

I have one button hooked up to the MUX. When it is not pressed, nothing lights up - that's right. But when it is pressed, every LED lights up as it is cycled through. It is as if pressing this button for one of the MUX pins is sending a HIGH signal to all of the MUX pins.

The Pictures

^^ You can see the big honking button in the bottom right. It is connected to 5V and then the MUX pin.

^^ I have two multiplexers. The one on the left is for the LEDs and the one on the right is for the buttons (of which I currently [ha!] have only one).

The Code

// set vars for all the pins
int led_input = 0;
int led_ctrl_1 = 1;
int led_ctrl_2 = 2;
int led_ctrl_3 = 3;
int led_ctrl_4 = 4;

int btn_input = 5;
int btn_ctrl_1 = 6;
int btn_ctrl_2 = 7;
int btn_ctrl_3 = 8;
int btn_ctrl_4 = 9;

// how many MUX pins?
int players = 12;

// function to take player number and convert to control pins
void ledWrite(int led, boolean val){

    if(!val){

        digitalWrite(led_input, LOW);

    }else{

        if((led - 8) >= 0){
            led = led - 8;
            digitalWrite(led_ctrl_4, HIGH);
        }else{
            digitalWrite(led_ctrl_4, LOW);
        }

        if((led - 4) >= 0){
            led = led - 4;
            digitalWrite(led_ctrl_3, HIGH);
        }else{
            digitalWrite(led_ctrl_3, LOW);
        }

        if((led - 2) >= 0){
            led = led - 2;
            digitalWrite(led_ctrl_2, HIGH);
        }else{
            digitalWrite(led_ctrl_2, LOW);
        }

        if((led - 1) >= 0){
            led = led - 1;
            digitalWrite(led_ctrl_1, HIGH);
        }else{
            digitalWrite(led_ctrl_1, LOW);
        }

        digitalWrite(led_input, HIGH);
    }
}

// function to take player number and convert to control pins
int btnRead(int btn){

    if((btn - 8) >= 0){
        btn = btn - 8;
        digitalWrite(btn_ctrl_4, HIGH);
    }else{
        digitalWrite(btn_ctrl_4, LOW);
    }

    if((btn - 4) >= 0){
        btn = btn - 4;
        digitalWrite(btn_ctrl_3, HIGH);
    }else{
        digitalWrite(btn_ctrl_3, LOW);
    }

    if((btn - 2) >= 0){
        btn = btn - 2;
        digitalWrite(btn_ctrl_2, HIGH);
    }else{
        digitalWrite(btn_ctrl_2, LOW);
    }

    if((btn - 1) >= 0){
        btn = btn - 1;
        digitalWrite(btn_ctrl_1, HIGH);
    }else{
        digitalWrite(btn_ctrl_1, LOW);
    }

    return digitalRead(btn_input);
}

void setup(){

    pinMode(led_input, OUTPUT);
    pinMode(led_ctrl_1, OUTPUT);
    pinMode(led_ctrl_2, OUTPUT);
    pinMode(led_ctrl_3, OUTPUT);
    pinMode(led_ctrl_4, OUTPUT);
    pinMode(btn_input, INPUT);
    pinMode(btn_ctrl_1, OUTPUT);
    pinMode(btn_ctrl_2, OUTPUT);
    pinMode(btn_ctrl_3, OUTPUT);
    pinMode(btn_ctrl_4, OUTPUT);
}

void loop(){

    for(int x = 1; x <= players; x++){

        if(btnRead(x) == HIGH){

            ledWrite(x, true);
            delay(100);
            ledWrite(x, false);
        }
    }
}

I know this is a lot to trudge through, and I honestly appreciate any help you are willing to offer. Thanks in advance!

All your unused MUX input pins for the button MUX are floating. You will need to tie all of the unused inputs (those that do not have a physical button attached) to ground. Floating inputs are undefined and cause undefined output.

Also, when your attached button is not pressed, its input will also be floating. You can avoid this by connecting the input pin on the MUX to ground using a resistor. That way, when the button is not pressed the input will be low (through the resistor), and when the button is pressed it will be high (through the button connection).


AVRDUDE Error (Arduino Leonardo) I, like many others, have encountered the avrdude error. However, I am not sure how to go about fixing mine after looking at numerous forums, etc.

avrdude: verification error, first mismatch at byte 0x0002
     0x74 != 0xe6
avrdude: verification error; content mismatch

I am simply trying to upload a simple sketch, but right when it seems it is about to finish, I get this error and the uploading loading bar simply never finishes...

Thanks for the help!

I had lots of issues when I first started.  these are all things I tried and at least one of them stopped this problem occurring, but I haven't a clue which.

Close the IDE (if you are using it and open it again)
Disconnect your board, wait 10 seconds and reconnect it.
Check you settings, are you using the correct board, etc.
Use a different cable.
Update your drivers.
Update your IDE/Toolset.
Use a different physical port on your PC.
Load the Blink example, if that doesn't work you serious have issues.
Reboot your PC.
If you can, try a different PC.


Arduino IDE / Teensy 3 on Ipad Does anyone know a good IDE for Ipad to write Arduino code and compile it for teensy 3 ?

Answers with different alternatives would be appreciated

I don't know of any way to compile it on an iPad, but Textastic should do the trick for writing the code if you set the syntax highlighting to C++.


Can I cut the pin holes off of my Arduino board? I'm making a project, but my arduino pro micro is just slightly too big to fit in it's case.

What would happen if I cut off the pin holes that I don't need? Would it still work? Or would it be ruined?

I guess that one could cut (or hone down) parts of the PCB. Obviosly this process devoids the warranty and there is the risk of damaging either the board or some components on it (i.e. by holding or clamping it during the process).

I would not expect any other wiring besides those connecting the pins to run in this part of the PCB. The reference layout (see board layout and using Eagle (free version)) - if the clones follow that layout - confirms that there are no other traces there. So it is mostly important to not cut any other traces and remove any chippings after the cutting to avoid short circuits.

If in doubt buy two or three boards ;) to try and repeat the process.


Burn hex with optiLoader Can optiLoader be used to burn custom hex?

For example, there's hex representation stored in optiLoader.ino in image_328, if that value is replaced with content of my pre-compiled hex, should that work right out of the box or some additional tweaking is needed?

EDIT

Discussion about the same topic on arduino forum as well.

Yes, it should work provided that your desired target image is stored in the same form, with correct metadata, and that it is small enough to fit in the programmer device.

The storage format of the payload-to-program could be made more optimal by a factor of almost two; however, for the original purpose of injecting compact Arduino-style bootloaders that is scarcely needed, and would have made preparing payloads more complicated.


Do I need the Motor Shield to drive servo motors? I was perusing Arduino's list of official shields and noticed the Motor Shield that can be used to drive up to 2 servo motors.

Being brand new to Arduino/robotics, I am wondering: do I really need this shield to drive a set of servos?

What does this shield really offer in the way of driving motors?
What is lost by not using this shield?
What if I my project has more than 2 motors?!?

The Motor Shield is for driving bare motors, not servos. Servos already include drive electronics and only require a PWM signal in order to control them, whereas the Motor Shield provides the drive electronics for bare motors.


Should L, TX, RX led light on while connected with laptop Dear Sir,
               I need to know that should led light named as L, TX, RX should be on when we connect it with laptop?
Because when I connect it with laptop led light turns on for 1 or 2 second then turns off. That's why I am asking you this question.
                 Hoping for a favourable answer.
Your's faithful,
Nir Patel.

On Arduino Uno (and most basic Arduinos), the 'L' LED is operated by whatever code is on the Arduino. RX and TX flicker whenever the Arduino is sending data to the PC (TX) or is receiving data from the PC (RX).

If you have never re-programmed your Arduino, it is running whatever code was in it when it was shipped to you. It sounds like your Arduino has a bootloader but no code yet. The bootloader listens for the PC to try upload a new program. While it is listening, it blinks the L LED.

If the PC tries to upload, you will see the RX and TX lights flicker as the two communicate, until the upload is finished. Then whatever program was uploaded will run, and it will control the LEDs.

If the PC doesn't try to upload a new program within a few seconds (how long depends on which bootloader version is in the Arduino), the bootloader will start whatever program is already in the Arduino. Again, that program will then control the LEDs.


delay() vs delayMicroseconds() I just started using Arduino and so far I've used both delay() and delayMicroseconds(). I was wondering what the difference between these two is, because it seems to me that they're the same.

From the documentation:

  delay()

  Description

  Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)

So... milliseconds vs. microseconds.


Debouncing, or problem with my code? I'm using a simple microswitch on pin 2, to activate an external interrupt.

void pause()
{
  Serial.print("\n\nPause\n\n");
  delay(1000);
}

void setup()
{
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(0, pause, RISING);
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  Serial.print("\nGoing");
  delay(100);
}

When I tap the micro switch, some reason, my serial monitor output looks like this:

Just to clarify, there is no delay between any of

Is this just some serious debouncing, causing my Arduino to find lots of rising instances? or is there some kind of problem in my code?

I have a page about using switches but since I don't want to give a link-only answer I'll summarize here.

Detect switch changes

What is needed is to detect a transition. That is, either:

It was closed and is now open.

Or:

It was open and is now closed.

To do that you need to "remember" the previous state of the switch and detect a change, like this:

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    oldSwitchState =  switchState;  // remember for next time
    if (switchState == LOW)
       {
       Serial.println ("Switch closed.");
       }  // end if switchState is LOW
    else
       {
       Serial.println ("Switch opened.");
       }  // end if switchState is HIGH
    }  // end of state change

  // other code here ...

  }  // end of loop

This code looks for changes, and only displays something when the switch changes.

By the way, you should be doing neither delay nor Serial.print inside an interrupt, as both of the rely upon interrupts being active, and interrupts are not active inside an ISR.

Debouncing

A simple technique is just to build in a short delay, for example 10 milliseconds (ms). For example:

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    oldSwitchState =  switchState;  // remember for next time
    delay (debounceTime);   // debounce
    if (switchState == LOW)
       {
       Serial.println ("Switch closed.");
       }  // end if switchState is LOW
    else
       {
       Serial.println ("Switch opened.");
       }  // end if switchState is HIGH
    }  // end of state change

  // other code here ...

  }  // end of loop

In the above code the delay is inside loop (where it is OK to use it) and causes a short pause to allow the switch to stop bouncing.

Debouncing without delay

The above code is fine in simple applications, and if you test it, you should find that the message "Switch closed." and "Switch opened." should only occur once per switch press. But, there's a problem. If you hang around the Arduino forums for a little while you will probably see people telling you "don't use delay". There are various reasons for this, not the least is which that using delay stops your code from doing anything else useful (like testing sensors, controlling motors, flashing LEDs, etc.).

The code below does not use delay, but rather checks for the time that has elapsed after you hit the switch, and sees if the "debounceTime" (in this case 10 ms) has elapsed. If not, it ignores the transition.

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds
unsigned long switchPressTime;  // when the switch last changed state

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    // debounce
    if (millis () - switchPressTime >= debounceTime)
       {
       switchPressTime = millis ();  // when we closed the switch
       oldSwitchState =  switchState;  // remember for next time
       if (switchState == LOW)
          {
          Serial.println ("Switch closed.");
          }  // end if switchState is LOW
       else
          {
          Serial.println ("Switch opened.");
          }  // end if switchState is HIGH

       }  // end if debounce time up

    }  // end of state change

  // other code here ...

  }  // end of loop

More information on the Arduino site: http://arduino.cc/en/Tutorial/Debounce

  It is essential for me to use an interrupt, because I need to be able to pause my entire program, at the push of a button, then resume it when the button is pushed again. I heard from other people that I cannot use any type of delay in the interrupt, is this true?

You don't really pause a program with delay, it is now just doing something else (waiting for a timer to reach a certain time). Timers depend on interrupts to update counters as the hardware timer will overflow (roll over) very rapidly.

I suggest a redesign. In your main loop, for example, you could detect the switch press, and then not do anything until it is pressed again. For example, where I had "other code here" in my example:

static bool switchWasPressed;

if (switchWasPressed)
  {
  // do nothing
  }
else
  {
  // do what you want to do continuously
  }

Now, in the code which detects switch presses you toggle switchWasPressed. So instead of:

Serial.println ("Switch closed.");

You put:

switchWasPressed = !switchWasPressed;  // toggle switch press state


Arduino Pro Micro Analog Pinouts I have the Arduino Pro Micro and I would like to use all the analog pins that I can on it.

It currently looks like it has a total of 9 Analog pins that can be used.

A0, A1, A2, A3, A6, A7, A8, A9 and A10.

However, I am unsure how to call these pins since all of those are also digital pins.

Would A0-A3 be defined as:

#define analog1 A0;
#define analog2 A1;
#define analog3 A2;
#define analog4 A3;

While the other pins would be this?:

#define analog5 4;
#define analog6 6;
#define analog7 8;
#define analog8 9;
#define analog9 10;

Then just call:

analogRead(analog1);
analogRead(analog2);
.....
analogRead(analog8);
analogRead(analog10);

Would that be the correct way of defining the 9 analog pins?

Assuming you have the Pro Micro core, they are called A0, A1, A2, A3, A6, A7, A8, A9 and A10. There is no need to "special case" the others, since the pins are known as both.


Using Multiple Serial Ports with arduino nano I am using a arduino nano to control a adafruit ultimate gps and a xbee wireless controller. However I recently ran into a problem using both at the same time (before I was using each separately until now) and read that I cannot listen to 2 software serials at the same time with a arduino. The biggest problem I see is that since I can only listen to one at a time, if I open a port, will cached data from the xbee and/or gps instantly start transferring in? Or or it more luck based that I will catch it as it comes? How should I go about coding around this? Should I just close and reopen the ports as needed(assuming there is no luck factor involved)? Any help is greatly appreciated. I will explain more if necessary.

You can use SoftwareSerial library in order to instantiate a second (soft) serial port.

By looking at the example, it seems that you can use any two digital pins to use SoftwareSerial library and instantiate a second serial port along with the hardware serial port.


Strange Arduino Serial Behavior I have a quirky question today.
I have an Arduino MEGA 2560 with a very simple setup. It's connected to my pc over usb, and has one device connected on its onboard TX/RX2 port group. Whenever I open the COM port on my pc I see a short spike in voltage on the TX2 pin. An analogous behavior happens on even the simplest sketches so I don't think it's the library I'm using to talk to this device.
With the sketch below instead of a short spike in voltage, the TX2 line stays high and when the pc's COM port is opened that TX2 line drops to 0v for maybe a half second.
Not super relevant info about device
It's a Noritake GU140X32F-7000 display. The mfg website doesn't list it's model directly but the
info on the 'B' variant, and it's supplied AVR code, work just fine.

MFG Website for this model>> https://noritake-vfd.com/gu140x32f-7000b.aspx
Code Library>> https://www.noritake-elec.com/codeLibrary.php#gu7000

Relevant bare-minimum code to see this effect on an oscilloscope connected
GRD <-> AVR Ground, POS <-> Pin16(TX2)
void setup() {
  Serial.begin(115200); // Connection to computer
  Serial2.begin(38400); // Connection to TX2 pin 16
  Serial2.write('akjlahsdkjahsdkjlhasdkjhaskldjhaksjhd');
}

uint8_t serialByte = 0;
void loop() {
  if (Serial.available() > 0) {
    serialByte = Serial.read();
  }
}

What happens, which I don't want happening, is after I've had the Arduino draw to the Noritake screen, and I open or reopen the COM port from my pc to the Arduino, the screen blanks itself. Doesn't matter if I use PUTTY, python's serial library with
ser = serial.Serial('COM4', 115200, R timeout=0,parity=serial.PARITY_NONE, rtscts=1)
or Serial Port Monitor's trial version from https://www.com-port-monitoring.com/ via the send dialog - it happens either way.
Especially weird is I don't see data going over this COM port in the Serial Monitor software when the COM port is opened and yet my oscilloscope (fairly crappy DSO138) catches a spike in voltage happen the moment this serial line is opened from my pc. When I use the Noritake library the TX line is normally low when there's no data, whereas the Arduino built in Serial2 line is normally high until there's data. Then when I connect it goes low for about a half second. The code Noritake uses to communicate over this serial line is a bit odd, not actually using the Serial or Stream built in classes, instead opting to write data manually to this port and only including these two external libraries.
#include <avr/pgmspace.h>
#include <util/delay_basic.h>

What causes Serial2 to go low when my PC opens the COM port to Serial on my Arduino? What can I do to prevent it from writing to Serial2?

As to why this happens: connecting to the Arduino with the built in USB port would wipe the display because the Arduino would reset and re-initiate the display initialization routine. The spike in current was actually the initialization signal. In the bare minimum sketch the signal going high, low, then back high was again due to the Arduino resetting.
The solution I'm going with is just changing how I connect to my Arduino with python by adding dsrdtr = 1 to my serial declaration. I tested this and my Arduino no longer resets, and uploading sketches is not impacted.
# Python 3.7.5
import serial
ser = serial.Serial('COM4', 115200, timeout=0, parity=serial.PARITY_NONE,
                   rtscts=1, dsrdtr = 1)


Program attiny13 with Arduino uno 1.6 I am looking for the boards.txt, platform.txt and core files needed for the programming of the ATtiny13 with the Arduino Uno. Those I find on the internet probably only works with Arduino 1.0 and not with 1.6.

You can use the library for IDE 1.6 https://github.com/damellis/attiny/


Arduino to AtTiny change of pin interrupt behaviour? I have a project which, to save on battery, is put to sleep until an interrupt pin is rising from LOW to HIGH.
This works well on Arduino Nano, however the translation doesn't on the ATTiny.
#include <avr/sleep.h>
void setup(){
    pinMode(2,INPUT);
    noInterrupts();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    attachInterrupt(INT0,wakeUp,RISING);
    //Yadada
    Interrupts();
}
void wakeUp(){
   //Something Something
   sleep_mode();
}

Both on the Arduino Nano and the AtTiny, the interrupt Pin 0 is equivalent to Pin 2.

The Arduino is set to ISP
I have run the Bootloader (with internal clock as 8MHz if that makes a difference)
The program loads on the AtTiny45.

Yet, the interrupt pin does not interrupt.
Does the INT0 act differently on a ATTiny than on the Arduino, and if so, how can I wake up my AtTiny?

After going through a lot of documentation, it seemed best and more efficient to attach the interrupt without functions.
EIMSK  |=  (1<< INT0);//Attaches the interrupt
MCUCR  |=  (1<< SM1)  //Power-down mode
         | (1<<ISC01) //The rising edge of INT0
         | (1<<ISC00);// generates an interrupt request


Arduino keypad matrix example? ( teensyduino ) I'm a beginner using Arduino with a Teensy 3.2 board and programming it as a usb keyboard. I have two 4 button membrane switches. Their button contacts are on pins 1-8, and the 9th pin holds a soldered together wire of both membrane switches' "ground" line or whatever it's true name is; the line that completes the circuit.

Basically when you press the buttons they are supposed to simply type "a, b, c..." respectively. I've been told I need to use a matrix for this.

I'm looking for an example of how to code a keyboard matrix that effectively supports a one row/9 column line (or vice versa?) I've been unable to find that solution online.

All I have so far is this code which, when the button on the second pin is pressed, sends tons of "AAAAAAAAAAAAAAAA" keystrokes.

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send an ASCII 'A',
    Keyboard.write(65);
  }
}

Would anyone be able to help?

By your description, you don't have a matrix.  You have them wired as just 8 straight switches.

A matrix would be if you had the 4 switch pins of one keypad wired to the same switch pins of the other keypad, and the two common connections from the keypads wired to two separate IO pins.

At the moment your code is responding whenever a button is in the low state. Instead it needs to respond only when the button transitions from the high state to the low state.  To do that you need to know what state all the buttons were in the previous pass through loop to compare them to what they are in this pass through loop - and if any have changed then they have either been pressed or released.

You should also implement debouncing to that you don't get false presses.

If you don't want to learn how to do all that yourself I have a handy library that will do it all for you:

https://github.com/MajenkoLibraries/DebouncedInput

If you want to convert your setup to an actual matrix to save on IO pins you want to read the Arduino Keypad tutorial:

http://playground.arduino.cc/Main/KeypadTutorial


Is the Serial buffer going from Arduino to PC and from PC to Arduino different? I'm both sending and receiving strings to Arduino from my Python program on the PC and the opposite. I don't check by code if one is finished before doing the other. Are they seprate buffers, or is it just pure luck my program has been running fine until now and each program has been reading the right string ?

There shall be separate buffers for Tx and Rx (in Arduino Serial library). The actual buffer size may vary, but shall be around 8-16 bytes and there is also hardware buffer in MCU. Please try to increase serial baudrate, if possible.

UPD: In HardwareSerial.h:

#if (RAMEND < 1000)
#define SERIAL_TX_BUFFER_SIZE 16
#else
#define SERIAL_TX_BUFFER_SIZE 64
#endif

....

unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];

It seems for Atmega328 the buffers are 16 bytes each

UPD: As Nick pointed, for Atmega328:

#define RAMEND       0x8FF     /* Last On-Chip SRAM Location */

So the buffers are 64 byte each.


Will Intel Atom Processor laptops support cloned a Arduino with CH340 driver? I am planning to buy a low cost and low weight laptop with an Atom Processor.

I only have cloned Arduinos - will the Arduino drivers and IDE work on laptops which come with Atom Processors?

The processor in your laptop is irrelevant. It is the operating system you should be thinking about, not the processor.

If the operating system has drivers for the CH340 chip, and Windows does, as you already know since you are using it already, then you already know that the answer is a big fat yes.

The only time you need to worry about if the processor will support something is when you are switching to a completely different archetecture such as ARM.


xBox receiver code output is scrambled I'm running the following code:

#include <XBOXRECV.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
XBOXRECV Xbox(&Usb);

void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nXbox Wireless Receiver Library Started"));

}

void loop() {
  Usb.Task();
  if (Xbox.XboxReceiverConnected) {
    if (Xbox.getAnalogHat(LeftHatY) == 0) {
      Serial.print(Xbox.getAnalogHat(LeftHatY));
    }
   Serial.print("TEST");
  }
}

After running the example that the library includes and a spin off I wrote for test purposes I keep getting random output, this is just some of it:

  9�]==�=�~=���y��:.�:�:����9�=��������:�:�\=���^=�?�}�:^���:�|]=9�\=��������:�ܗ��.\�~=���

Seems like wrong baud-rate. Change baud-rate in the Arduino IDE serial monitor.


Temperature sensor bugs My project is based on a moving fan using DHT11 sensors. I have used 2 void loops and the IDE is showing an error

  "exit status 1
  redefinition of 'void loop()'"

One doubt: Can we use 2 void loops in the code? Please see and identify the errors.

2nd doubt: dht DHT; shows error

  "exit status 1
  'dht' does not name a type" for my version of Arduino 1.8.1

#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>

 // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define dht_dpin 12
dht DHT;
#define pwm 9

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

void loop() {
  // put your main code here, to run repeatedly:
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(" Fan Speed");
  lcd.setCursor(0,1);
  lcd.print(" Controlling");
  delay(2000);
  analogWrite(pwm, 255);
  lcd.clear();
  lcd.print("Circuit Digest ");
  delay(2000);
}

void loop() {
  DHT.read11(dht_dpin);
  int temp=DHT.temperature;
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.print(temp);   // Printing temperature on LCD
  lcd.print("oC");
  lcd.setCursor(0,1);
  if(temp <26 ) {
    analogWrite(9,0);
    lcd.print("Fan OFF");
    delay(100);
  } else if(temp==26) {
    analogWrite(pwm, 51);
    lcd.print("Fan Speed: 20%");
    delay(100);
  } else if(temp==27) {
    analogWrite(pwm, 102);
    lcd.print("Fan Speed: 40%");
    delay(100);
  } else if(temp==28) {
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%");
    delay(100);
  } else if(temp==29) {
    analogWrite(pwm, 204);
    lcd.print("Fan Speed: 80%");
    delay(100);
  } else if(temp>29) {
    analogWrite(pwm, 255);
    lcd.print("Fan Speed: 100%");
    delay(100);
  }
  delay(3000);
}
}

Here, below is updated version of your code.

Before running this code, you have to download DHT library. Just click on Click Here and you find good explanation & library of DHT11 Sensor. Becuase this library I usually preferred for my code. So, please download it and then run my code.

Click Here

And two void() loop never used. Put your all logic in one void() loop.

Note: This is not tested code. So if you face any problem then update me.

#include <dht.h>                // DHT library
#include<LiquidCrystal.h>       // LCD library

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

dht DHT;

#define DHT11_PIN 12

#define pwm 9

float temp;

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

  pinMode(pwm, OUTPUT); //Pin as OUTPUT
}

void loop()
{

 int chk = DHT.read11(DHT11_PIN);
 temp = DHT.temperature;
 Serial.print("Temperature = ");
 Serial.print("\t");
 Serial.print(temp);
 delay(1000);

 lcd.begin(16, 2);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Fan Speed");
 lcd.setCursor(0, 1);
 lcd.print("Controlling");
 delay(2000);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Circuit Digest");
 delay(2000);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Temperature:");
 lcd.setCursor(10, 0);
 lcd.print(temp);

 lcd.setCursor(0, 1);

 if(temp < 26 )
 {
    analogWrite(pwm, 0);
    lcd.print("Fan OFF");
    delay(100);
 }
 else if(temp == 26)
 {
    analogWrite(pwm, 51);
    lcd.print("Fan Speed: 20%");
    delay(100);
 }
 else if(temp == 27)
 {
    analogWrite(pwm, 102);
    lcd.print("Fan Speed: 40%");
    delay(100);
 }
 else if(temp == 28)
 {
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%");
    delay(100);
 }
 else if(temp == 29)
 {
    analogWrite(pwm, 204);
    lcd.print("Fan Speed: 80%");
    delay(100);
 }
 else if(temp > 29)
 {
    analogWrite(pwm, 255);
    lcd.print("Fan Speed: 100%");
    delay(100);
  }
}


Serial Connection to Phone Line I was hoping to create a cheap security system by connecting an Arduino to the phone line output of a base station.

Since the base station should call a phone number if the alarm is tripped I wouldn't have to do much hardware hacking so long as I can read/parse the output from the base station.

My question is can I read serial output from a phone line like this?

Phone lines run off of the RS-232 telecommunications protocol which can run off -25v to 25v, which would completely destroy your Arduino. Luckily there is an IC made to help you with that. You can use the MAX3232 IC to convert RS-232 to TTL 5v or 3.3v (Same chip can do either). Look at providers like Digikey for just the chip or you can get a breakout from providers like SparkFun.

TL;DR Yes, but you need a special IC to not fry your Arduino.


Where is the documentation for writing an Arduino core? I'm interested in writing an "Arduino core" (i. e. porting Arduino to a new MCU and new board(s)).  I'm having trouble finding much documentation on how to do so.  Am I missing something?
This page says "anyone may develop a core for their own boards following the rules and requirements we have issued."  So, where are those "rules and requirements?"
I found something called the "Platform Specification", which sounded promising, but it only documents the config files; it does not say anything about the code that needs to be written to support a new platform.
I found ArduinoCore-API, which says it is the "hardware independent layer of Arduino core."  But it doesn't mention anything about how to write the hardware-dependent part of the core.
I'd be grateful if anyone could point me to the Arduino core documentation.  It's not turning up in my web searches.  Thanks!
Clarifications:

Yes, I can look at existing cores as examples, but I'd rather have the documentation, as well.  Especially since existing cores may be of varying quality, or may not be up to the latest standard.  Documentation is always a good thing.
The reason I want to write a core is because... I want to use an MCU which is not currently supported!  (Specifically, I want to add support for the GD32F350, but really that shouldn't be relevant to answering "Where is the documentation?")

There are two major parts to writing an Arduino core: the hardware independent portions and the hardware dependent.
The hardware independent portions are pretty much done for you in the ArduinoCore-API. However I wouldn't just use that verbatim but use it as a starting point and adapt it to your needs. This is because it actually has a couple of unresolved issues and not everything may 100% fit your needs. We don't use it for the chipKIT core because:

It has an unresolved issue around the naming of the String.h file which conflicts with the libc's string.h on case insensitive filesystems
Our USB stack is vastly different to how the Arduino "Pluggable USB" works
We have extra facilities in a number of standard objects to make use of more efficient use of more advanced hardware

Once you have the hardware independent portion sorted you need to write, from scratch, the hardware dependent portion.  The basic list of functions you need to implement are listed in the Arduino reference. How you write them cannot be documented, since that depends on the hardware. And you may well need to (or want to) write considerably more functions that just those. For example on chipKIT as well as the standard analogWrite() function we also have functions to change the PWM frequency and resolution - things that aren't part of the "standard", but are incredibly useful.
A good starting point is to examine the Arduino.h file of an existing core (the AVR core is a good baseline) which will list most of the functions and their parameter/return types. That gives you what the functions expect to receive and what they should emit, but how those functions are written is completely down to you.
And then of course you have to implement the boards variants etc to make the whole things work...
Also, be warned that writing (and maintaining) a core is a long and involved process and will consume the rest of your life.


How to program an offbrand arduino uno? So I recently bought this off brand arduino uno from betemcu.cn.
it says its r3 compatible.

Can I program this thing with the arduino coder or do I need to use something else? whenever I try uploading the code it says "problem uploading to board"

what settings or program should I use to code this?

The issue is probably that you need a driver for the onboard CH340G USB-to-serial bridge.

The Baite Electronics Arduino clones are generally of good quality and work well.
There are some differences between them and Arduino-brand Arduinos. Two notable ones are a different voltage regulator and (probably the issue here) a different USB-to-serial bridge IC.  The Arduino brand products use an FTDI IC and Baite uses, in this case, the CH340 USB bridge IC.

The product is described on this webpage and you will see that they say

  UNO MEGA328P CH340G for Arduino Compatible

The CH340G relates to the USB interface IC.
Until about a year ago the USB driver in windows worked with most common USB ICs as well as with FTDI ICs.  However, FTDI changed their system so that the Windows driver will now only work with FTDI brand ICs. So it is now necessary to load a driver into the PC (whether Windows, Linux or other O/S) to suit the CH340.

If you email them Baite will provide a link to the CH340 driver, but they do not usually provide it on their website (reason unknown to me.)

Or, you can obtain a driver from numerous websites.
A web search on eg:  driver ch340 baite arduino
turns up many pages.   How good or how safe any of these is is TBD.

This page claims to provide a Windows 7 CH340G driver and install instructions

This YouTube video describes how to install a driver and provides a link to this page which lists a number of drivers.

This page discusses the issue


How to convert bool array to byte? I have following problem:
I'm reading 8 bit signal from one Arduino pin and store all informatin in bool array. Now I want to convert this array to single byte in decimal. How to do this?

I've tried this:

bool ID[8] = {0, 0, 0, 0, 0, 0, 1, 1};
int recivedID = int(ID);

and

bool ID[8] = {0, 0, 0, 0, 0, 0, 1, 1};
int recivedID = ID.toInt();

non works.

byte BoolArrayToByte(bool boolArray[8])
{
  byte result = 0;

  for(int i = 0; i < 8; i++)
  {
    if(boolArray[i])
    {
      result = result | (1 << i);
    }
  }

  return result;
}


Can we use Arduino mini in eagle to create new custom modal I want to learn pcb design in Eagle/Fritzing. So i was thinking of using existing amazing Arduino mini/nano in eagle and create a custom pcb which has all arduino capability and plus some components like 7 segment/Bluetooth radio etc.

Can we do that? Is is allowed or arduino design is not open to be modified?

From https://www.arduino.cc/en/Main/FAQ#toc8:

I want to design my own board, what should I do?
The reference designs for the Arduino boards are available from their specific product pages. They're licensed under a Creative Commons Attribution Share-Alike license, so you are free to use and adapt them for your own needs without asking permission or paying a fee.

You can find the board design files on the Documentation tab of each product page.
Arduino Mini product page:
https://store.arduino.cc/arduino-mini-05
Arduino Nano product page:
https://store.arduino.cc/arduino-nano


Error compiling for board Arduino Uno SIM7000 I'm using  botletics / SIM7000-LTE-Shield with Arduino Uno, I selected all examples but all end up with the same Error
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::postData(const char*, uint16_t, const char*, const char*, const char*)':
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp:2045:3: error: expected ';' before 'readline'
readline(10000);
^~~~~~~~
exit status 1
Error compiling for board Arduino Uno.

I cloned botletics comparatively gigantic repo.  They've modified the Adafruit library without changing the name.
The problem appears to be that you are working out of the current master branch.  Switch to the latest tag, 1.1.0, and the SMS_Response example will compile just fine.  I didn't try all of the others.
Direct link to the zip file for the 1.1.0 tag.


Reduce 5v Trinket Pro to 3.3v? Apparently these nRF24L01+ modules need 3.3v, but I've only got 5v Trinket Pros that I'm using.

How can I reduce the voltage to the RF transmitter?

Would a voltage regulator work? Specifically looking at this: http://addicore.com/product-p/165.htm

The NRF24L01+ has inputs that are 5V tolerant! So you only need to provide 3.3V on the Vcc pin of the module, which you can do by putting a voltage regulator between it, and the 5V of the Trinket. So there isn't really any need to convert the Trinket to 3.3V.

PS Remember to add some capacitors to the output of the voltage regulator, as the NRF needs a pretty stable 3.3V. Noise in the power lines can cause instability in the operation of the device.


I can't turn on the motor by Arduino IoT Cloud I'm trying to turn ON/OFF a DC motor from Arduino Iot Cloud. I have to turn it ON/OFF physically and through the cloud, physically it works well but from the cloud it does nothing. I'm using an Arduino MKR WiFi 1010, a L298N Dual full bridge,9V DC motor and a push buttom. Mi circuit is like this
My code is this
#include "thingProperties.h"
#include <FTDebouncer.h>

#define MOTOR_PIN 2
#define BUTTON_PIN 5

FTDebouncer buttons;

void setup() {
  pinMode(MOTOR_PIN, OUTPUT);
  buttons.addPin(BUTTON_PIN, LOW);
  buttons.init();

  setDebugMessageLevel(2);
  Serial.begin(9600);
  delay(1500);
  // Defined in thingProperties.h
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}

void loop() {
  buttons.update();
  ArduinoCloud.update();
  onMotorChange();
}

void onPinActivated(int pinNr) {
  // do something according to the _pinNR that is triggered. For instance:
  Serial.println(pinNr);
  toggle = !toggle;
}

void onPinDeactivated(int pinNr) {
  // do something according to the _pinNR that is triggered. For instance:
  Serial.println(pinNr);
}
void onMotorChange() {
  digitalWrite(MOTOR_PIN, toggle || motor);
  Serial.print("The motor is ");
  if (toggle) {
    Serial.println("ON");
  }
}

I tried with a LED and it worked very well, but with the motor doesn't.
This is the code that Arduino creates when I add things to the board, the part of

thingProperties.h

// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

// x-ed id
const char THING_ID[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_PASS;    // Network password (use for WPA, or
use as
key for WEP)

void onMotorChange();

bool toggle;
bool motor;

void initProperties(){

ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(toggle, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(motor, READWRITE, ON_CHANGE, onMotorChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Thanks for the help and suggestions. How should I connect the motor or what do I have to change in the code?

The following code is an example. As I don't know the Arduino Cloud Thing configuration, and I don't have access to the cloud and the Hardware, the
programm is just a guess making some commented assumptions.
There are many assuptions I made, and I can not rely on the schematics you showed me. Eventually you have to redesign the circuit/hardware setup. A L298N is a so called H-Bridge. That needs at least two control pins in1 and in2 connected to arduino outputs to define the direction of the motor. You only connected one of them to an output of the arduino. And one of them to the button and an input of the arduino. (If that part of the schematics is correct.)
If you press the button in1 gets HIGH but the in2 may also get HIGH because your program switches the motor pin to HIGH. That turns the motor off. If one pin is HIGH the other must be LOW to drive the motor. Some L298N modules also need a PWM signal at the enA pin. That sets the speed of the motor with the duty cycle of the PWA signal. Most modules have a pullup at enA and enB so per default the motors are configured for full speed.
#include "thingProperties.h"
#include <FTDebouncer.h>

#define MOTOR_PIN 2
#define BUTTON_PIN 5

FTDebouncer buttons;

void setup()
{
  pinMode(MOTOR_PIN, OUTPUT);

  // !!! PPK: Handler methods added
  buttons.addPin(BUTTON_PIN, LOW, onPinActivated, onPinDeactivated);

  buttons.init();

  setDebugMessageLevel(2);
  Serial.begin(9600);
  delay(1500);
  // Defined in thingProperties.h
  initProperties();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}

void loop()
{
  buttons.update();
  ArduinoCloud.update();
}

void onPinActivated(int pinNr)
{
  if ( pinNr == BUTTON_PIN )
  {
     toggle = !toggle;
     // this assumes that the toggle triggers a change for
     // the motor variable in arduino cloud. If not,
     // the motor variable will not be changed and my code does not work.
     // uncommenting the following line may help, in that case
     // motor = toggle;
  }
}

void onPinDeactivated(int pinNr)
{
  // Intentionally left empty, we only react to the rising edge.
}

void onMotorChange()
{
  digitalWrite( MOTOR_PIN, motor );
  Serial.print("The motor is ");
  if ( motor )
  {
    Serial.println("ON");
  }
  else
  {
    Serial.println("OFF");
  }
}


Convert Bitstring to Textstring I have an Arduino Uno which is going to receive a long binary string.  I know that this string will correspond to English when decoded.  How can I convert the incoming binary string to text, so that I can read it in the Serial Monitor?

Bonus Points: This string will almost definitely have random noise digits.  How would I noise-proof the string, or how could I have the code detect and ignore noise?

UPDATE: It might help if I mention my end goal.  So I have this contained clean space that is locked up to avoid contamination.  It is quite small, and used for growing silicon crystals.  I want to be able to take a greyscale image every hour, and transmit it to a receiver on the other end of the room, through a window.  The window is two half inch panes of glass with an inch of space between them.  I have on hand 2x Arduino Uno, 1x Arduino Beetle, and 1x Raspberry Pi.  The whole text string thing is just for testing purposes so that I can understand what I'm doing.  From what I've read on the subject previously, I need to take the image, convert it to Hex, convert that to binary, transmit it, receive it, convert back to Hex, convert back to an image.  I have 0 experience with Arduino or Raspberry, have a limited idea of how to execute this, and appreciate all the help I can get!

Perhaps you have asked the wrong question. Because there is a library for those cheap 433MHz modules: RadioHead.
Use the RH_ASK mode, and try the 'ask' examples

You might see VirtualWire used a lot with those 433MHz modules. That is the same as RadioHead. The RadioHead is newer and has a few bugs fixed, but it uses also more memory.

The RadioHead library uses a far more superior protocol than anything else, that makes the range better than with other libraries. It also has a (simple) CRC checksum in the protocol. That means that when you receive something, you can be (almost 100%) sure that the data is correct.

Other protocols require that a message is transmitted 10 times, to be sure that it will be received. With the RadioHead library, sending a message just once is good enough.

Those cheap 433MHz modules have a disadvantage: they can only be turned on and off (ASK modulation) en you need a library for the protocol. That means that if the Arduino is doing more things that uses interrupts or code that disables interrupts, then the protocol is disturbed and it will not work very well.
The RF transceiver modules have a chip on the module itself that takes care of the protocol, that is so much better. Sparkfun has a Wireless Buying Guide and Adafruit uses the RFM69 a lot.

Those cheap modules require an antenna, or else the range could be less than the size of the table they are on. Solder a 16cm piece of wire to the antenna pin. Any piece of wire of any length is better than no antenna.


How is LED powered when PIN 2 is disconnected? Using the Arduino tutorial "Button", I have noticed that if I totally disconnect Pin2 from the circuit, the LED comes on dimly.

I am trying to understand HOW this happens.  Is it simply due to being a floating ground?

The pinMode(buttonPin, INPUT); line tells the board to set the buttonPin in high impedance mode.

When you disconnect the wire the state of that pin becomes unknown; usually it oscillates.
Since it is oscillating, the LED turns on and off randomly: you see it "dimly light".

The usual solution is to use a pull-up or pull-down. I suggest you to wire your buttons towards the ground, declare the pins as pinMode(buttonPin, INPUT_PULLUP); and invert the logic (i.e. buttonState = !digitalRead(buttonPin);). This way it will never oscillate again.


Help to get Arduino UNO with 4 SoftwareSerial transmit only ports I just started with my Arduino UNO so please pardon my ignorance with SoftwareSerial but I need help. My goal is to make a system of 4 SoftwareSerial ports. Port1 will receive a burst of 5-10 characters and I will then transmit on eventually Port2,3 & 4. Maybe all or just 1 depending on an operator setting. I made the simplest system to try it where I receive on port1 and display on Serial Monitor. All works well until I do a begin to the second port which is commented out in the listing. When it is not commented out it looks like Port1 receives nothing, no display Port1 never says "available" therefore nothing. Any ideas would be most appreciated.

#include <SoftwareSerial.h>
SoftwareSerial RotorPort1 (8, 9); //RX, TX
SoftwareSerial RotorPort2 (10, 11);

int RotorPortSpeed = 9600;

void setup() {
  Serial.begin(9600);
 RotorPort1.begin(RotorPortSpeed);
  //  RotorPort2.begin(RotorPortSpeed);
  delay(200);
 }

void loop() {
 if (RotorPort1.available()) {
    byte incomingByte = RotorPort1.read();
    Serial.print ("data= ");
    Serial.print(incomingByte);
    Serial.print("  ");
    Serial.print(char (incomingByte));
    Serial.println();
    delay (300);

  }
}

As Chris Stratton suggests, multiple instances of SoftwareSerial may cause issues, particularly with pin-change interrupts.

I adapted SoftwareSerial a while back to have a "send only" version. This can be downloaded from here - 6 KB.

One normal SoftwareSerial and 3 instances of the "send only" may possibly help. I haven't tested it.

Chris's suggestion to modify SoftwareSerial to allow pin number changes on-the-fly may be even better. SoftwareSerial can only write to one pin at a time as it blocks, and thus having 4 instances of it doesn't really achieve anything.

Another possible approach would be to use a multiplexer chip. I have a page about that. You could have a single SoftwareSerial instance, and then use the multiplexer to forward its data to one of (up to 8) pins.

You would need pull-up resistors to keep the other pins high (idle) when not in use at a particular moment.


How to increase the serial port's data throughput I have an array of numbers that will be subtracted from the ADC readings
of a 50 Hz sine wave. Using Serial.begin(57600);, I can only
output 25 samples per sine wave cycle, or about 1,250 samples per
second. my questions are:

how fast the increent of array number moves with y++ in my int sinus[]? because when i see on serial monitor with 52700 baudrate it can only show about 25 numbers per cycle (50Hz)
how to increase the speed the increment of y++ in my array?

int sinus[] = {
    70, 72, 83, 92, 108, 132, 157, 182, 207, 230, 243, 255, 255,
    255, 250, 238, 217, 193, 169, 143, 118, 98, 88, 77, 72, 80
};
int dataSensor;
int hasil[26];
int datasensor2;
int dataBaru;
int x;
int y;
int intPin = 2;
int output;
int output2;
int toggle;
int toggle2;
int z;

void setup() {
    TCCR1A = 0b00000010;
    TCCR1B = 0b00011100;
    TCCR0A = 0;  //disable millis, delay and mciros
    TCCR0B = 0;
    ICR1 = 3200;

    Serial.begin(57600);

    pinMode(A1, INPUT);
    pinMode(A0, INPUT);
    pinMode(A2, INPUT);
    pinMode(intPin, INPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);

    attachInterrupt(0, genJeah, RISING);
}

void genJeah() {  //intrupsi rising
    y = 5;
}

void loop() {
    dataSensor = analogRead(A0);
    toggle     = digitalRead(A1);
    toggle2    = digitalRead(A2);
    dataBaru = map(dataSensor, 0, 1023, 0, 255);

    for (x = 0; x < 25; x++) {
        hasil[x] = sinus[x];
    }
    // for (x=0; x<100; x++){

    output = sinus[y] - dataBaru;
    Serial.println(output);
    y++;
    if (y > hasil[26]) {
        y = 0;
    }
}

If you are looking for throughput then stop sending the ASCII conversion of numbers and just send the numbers.
In other words, use Serial.write() rather than Serial.print(): you can send ~25k integers per second with a 52k baudrate.

As you are actually remapping the ADC output to a single byte, that means you can easily achieve a 48k/s throughput with this simple change.

If you are also looking for low latency please consider the USB connection is actually packet based, not stream based, which means you will receive the data in chunks, no matter how frequently you write. You can speed it up a bit flushing the channel, at the cost of throughput.


Coding and libraries for Maxtronix Ultrasonic sensors I need to access distance data using a LV-EZ0 Maxtronix ultrasonic sensor: MB1000
LV-MaxSonar®-EZ0™High Performance Ultrasonic Rangefinder

Can anyone suggest what particular arduino libraries or code would be most useful?

I noticed this new ping library, NewPing

Would this work for my purposes with this particular sensor?

Likely work in pulse mode (library you mentioned) and sure work in RS232 serial mode (spec. in data sheet page 2, top, read data number as text).

How many sensors do you need and how fast update rate? Serial mode is easier if you application need small number of sensor at 'nominal' update rate (Arduino has limited number of hardware serial port, although softserial library may help).

Essentially, in pulse mode, the RX and PW pin is similar to Trig and Echo pin on many widely available sensor (several models number, basically following similar principle). Need care about the high and low relationship as may differ from the default value in library.

Taken from the data sheet of LV-MaxSonar®-EZ0

  R X – If held low, the EZ0™ will stop ranging. Bring high for 20uS or
  more to command a range reading.

  P W – This pin outputs a pulse width representation of range

Specifically you may want to first try the simple (old) ping: Ping Ultrasonic Range Finder

Changes needed:

Your sensor data sheet requires 20 μs trigger pulse while the above is 2 μs;
The library read a high pulse. Your sensor data sheet 'send pulse' which likely imply a HIGH pulse, may not need change;
The library use one pin for both in and out. your is one pin in (in for sensor, out for Arduino) for trigger and one put out for measurement.

Also, another library. Note the author states that many sensor from the factory differs (may need small change in code): Distance Detection
with MaxSonar ultrasonic rangefinder.


Arduino Nano 3.0 dimensions without the pins I think the title of this question is quite clear. I am looking for the exact dimensions of the Arduino Nano 3.0, with the electronic components and the USB mini port on the IC (the Atmega328 one), without the external pins.

Mini-USB-B is around 4mm tall.

Most PCBs are around 1.6mm.

The FT232RL on the bottom is 2mm (max) according to the datasheet. (voltage regulator is 1.8mm). (I'm sure about this tantalum capacitors)

So that's something around 7.6mm total height