text:
nRF24L01+ Arduino mpu6050
How do I ever understand what the Arduino IDE means when they advise you of any errors?  The reason I ask is because I got several errors that don't make sense to me as I see what the error means and what line the issue is but I don't see anything wrong with the code. It's written how it should be, the reason I say this is because before I ended the code I was compiling/verifying my code every time I write a new line just to make sure if I got new errors. It's easy to check as it was more than likely the very last line of code I just wrote, rather than write a book then do a spell check you know?
I have included the part of the code where I get errors and the errors themselves. Hopefully someone can point out to me what is it that Arduino sees that I don't and in the same token I'll learn how to counter measure those errors.
1.  //imu's
2.  #include "Wire.h" // i dont think this will be needed on this mcu's "slaves"
3.  #include "I2Cdev.h" // i dont think this will be needed on this mcu's "slaves"
4.  #include "MPU6050.h" // i dont think this will be needed on this mcu's "slaves"
5.
6.  //motors
7.  #include "Servo.h" // select which motor this slave mcu has and comment out the other
8.  #include "Stepper.h" // select which motor this slave mcu has and comment out the other
9.
10. //wireless
11. #include "nRF24L01.h"
12. #include "RF24.h"
13. #include "SPI.h" // i dont think this will be needed on this mcu's "slaves"
14.
15. #define RF_CS 12
16. #define RF_CSN 13
17. RF24 radio(RF_CS, RF_CSN);//RF24 radio(9, 10);
18. const int pinCE = 9;
19. const int pinCSN = 10;
20.
21. byte bArray[] = {0000, 1000, 0100, 1100, 0010, 1010, 0110, 1110}; // this are the Ch 0/7 address from Mux
22. const uint64_t LA = 0xF0F0F0F0D2LL;//mcu1 address of Slave
23. const uint64_t RA = 0xF0F0F0F0C3LL;//mcu2 address of Slave
24. const uint64_t LL = 0xF0F0F0F0B4LL;//mcu3 address of Slave
25. const uint64_t RL = 0xF0F0F0F0A5LL;//mcu4 address of Slave
26. const uint64_t LW = 0xF0F0F0F0E6LL;//mcu5 address of Slave
27. const uint64_t RW = 0xF0F0F0F0F7LL;//mcu6 address of Slave
28. const uint64_t UT = 0xF0F0F0F0F8LL;//mcu7 address of Slave
29. const uint64_t BT = 0xF0F0F0F0F9LL;//mcu8 address of Slave
30.
31. /* MUX CH address To simplify things, 1 is HIGH, 0 is LOW
32.                                                                     0000 – 0
33.                                                                     1000 – 1
34.                   A multiplexer of this sort really just            0100 – 2
35.                   acts as a 16 to one 1 switch. The 4 digital       1100 – 3
36.                   pins are used to set HIGH or LOW, in a binary     0010 – 4
37.                   fashion (0-15) to determine what pin “SIG” is      1010 – 5
38.                   connected to. So bringing all 4 pins LOW would    0110 – 6
39.                   switch the CD74HC4067 to channel 0 (so SIG and    1110 – 7
40.                   C0 would be connected), bringing them all HIGH    0001 – 8
41.                   would switch it to 15 (so SIG and C15 would be    1001 – 9
42.                   connected)                                        0101 – 10
43.                                                                     1101 – 11
44.                                                                     0011 – 12
45.                                                                     1011 – 13
46.                                                                     0111 – 14
47.                                                                     1111 – 15 */
48.
49. int recivers[8][4] = {
50.   { 0xF0F0F0F0D2LL, { 0, 0, 0, 0 }, //0000 – 0 SDATA line from MPU to Multiplexer ch0
51.     { 0xF0F0F0F0C3LL, { 1, 0, 0, 0 }, //1000 – 1 SDATA line from MPU to Multiplexer ch1
52.       { 0xF0F0F0F0B4LL, { 0, 1, 0, 0,}, //0100 – 2 SDATA line from MPU to Multiplexer ch2
53.         { 0xF0F0F0F0A5LL, { 1, 1, 0, 0 }, //1100 – 3 SDATA line from MPU to Multiplexer ch3
54.           { 0xF0F0F0F0D6LL, { 0, 0, 1, 0 }, //0010 – 4 SDATA line from MPU to Multiplexer ch4
55.             { 0xF0F0F0F0E7LL, { 1, 0, 1, 0 }, //1010 – 5 SDATA line from MPU to Multiplexer ch5
56.               { 0xF0F0F0F0F8LL, { 0, 1, 1, 0 }, //0110 – 6 SDATA line from MPU to Multiplexer ch6
57.                 { 0xF0F0F0F0F9LL, { , 1, 1, 1, 0 } //1110 – 7 SDATA line from MPU to Multiplexer ch7
58.                 }
59.               }
60.             }
61.           }
62.         }
63.       }
64.     }
65.   }
66. }
67.
68. MPU6050 mpu;
69. int16_t ax, ay, az;
70. int16_t gx, gy, gz;
71.
72. long long  val[6];//6 DOF MPU 6050 thats where this val{6} come from
73. long val;
74. long prevVal;
75.
76. byte bArray[] = ( 0, 180 );
77.
78. //Mux control pins on the Arduino Digital pins
79. int s0 = 8;
80. int s1 = 7;
81. int s2 = 6;
82. int s3 = 5;
83.
84. //Mux in "SIG" pin
85. int SIG_pin = 0;
86. //int val = readMux(7);
87.
88. void setup()
89. {
90.   pinMode(s0, OUTPUT);
91.   pinMode(s1, OUTPUT);
92.   pinMode(s2, OUTPUT);
93.   pinMode(s3, OUTPUT);
94.
95.   digitalWrite(s0, LOW);
96.   digitalWrite(s1, LOW);
97.   digitalWrite(s2, LOW);
98.   digitalWrite(s3, LOW);
99.
100.      Wire.begin();
101.
102.      for (int i = 0; i < 10; i++) //10 mpu's
103.      {
104.        mpu.initialize();
105.      }
106.
107.      radio.begin();
108.      radio.payload = 6;
109.      radio.setAutoAck(false);
110.      radio.setDataRate(RF24_2MBPS);
111.      radio.openWritingPipe();
112.    }
113.
114.    void loop()
115.    {
116.      for (int i = 0; i < 16; i ++)//Loop through and read all 16 values
117.      {
118.        int readMux(int channel)
119.
120.        int controlPin[] = {s0, s1, s2, s3};
121.
122.        int muxChannel[8][4] = {
123.          {0, 0, 0, 0}, //channel 0
124.          {1, 0, 0, 0}, //channel 1
125.          {0, 1, 0, 0}, //channel 2
126.          {1, 1, 0, 0}, //channel 3
127.          {0, 0, 1, 0}, //channel 4
128.          {1, 0, 1, 0}, //channel 5
129.          {0, 1, 1, 0}, //channel 6
130.          {1, 1, 1, 0}, //channel 7
131.          {0, 0, 0, 1}, //channel 8
132.          {1, 0, 0, 1}, //channel 9
133.          //  {0, 1, 0, 1}, //channel 10
134.          //  {1, 1, 0, 1}, //channel 11
135.          //  {0, 0, 1, 1}, //channel 12
136.          //  {1, 0, 1, 1}, //channel 13
137.          //  {0, 1, 1, 1}, //channel 14
138.          //  {1, 1, 1, 1}  //channel 15
139.        }
140.      }
141.      //loop through the 4 sig
142.      for (int i = 0; i < 4; i ++)
143.      {
144.        digitalWrite(controlPin[i], muxChannel[channel][i]);
145.      }
146.
147.      //read the value at the SIG pin
148.      int val = analogRead(SIG_pin);
149.
150.      //return the value
151.      return val;
152.
153.      for (int i = 0; i < 6 i++)
154.      {
155.        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
156.        val[0] = map(ax, -17000, 17000, 0, 180);
157.        val[1] = map(ay, -17000, 17000, 0, 180);
158.        val[2] = map(az, -17000, 17000, 0, 180);
159.        val[3] = map(gz, -17000, 17000, 0, 180);
160.        val[4] = map(gy, -17000, 17000, 0, 180);
161.        val[5] = map(gx, -17000, 17000, 0, 180);
162.
163.        radio.openWritingPipe(recievers[i].address);
164.        radio.write(val);
165.      }
166.
167.      delay(50);

    Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Nano, ATmega328"

    sketch_may19a:57: error: expected primary-expression before ',' token
    sketch_may19a:66: error: braces around scalar initializer for type 'int'
    sketch_may19a:68: error: expected ',' or ';' before 'MPU6050'
    sketch_may19a:73: error: conflicting declaration 'long int val'
    sketch_may19a:72: error: 'val' has a previous declaration as 'long long int                val [6]'
    sketch_may19a:76: error: redefinition of 'byte bArray []'
    sketch_may19a:21: error: 'byte bArray [8]' previously defined here
    sketch_may19a.ino: In function 'void setup()':
    sketch_may19a:104: error: 'mpu' was not declared in this scope
    sketch_may19a:108: error: 'class RF24' has no member named 'payload'
    sketch_may19a:111: error: no matching function for call to         'RF24::openWritingPipe()'
    sketch_may19a.ino:111:25: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note: void     RF24::openWritingPipe(uint64_t)
    void openWritingPipe(uint64_t address);
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:324:8: note:   candidate         expects 1 argument, 0 provided
    sketch_may19a.ino: In function 'void loop()':
    sketch_may19a:120: error: expected initializer before 'int'
    sketch_may19a:139: error: too many initializers for 'int [8][4]'
    sketch_may19a:140: error: expected ',' or ';' before '}' token
    sketch_may19a:144: error: 'controlPin' was not declared in this scope
    sketch_may19a:144: error: 'muxChannel' was not declared in this scope
    sketch_may19a:144: error: 'channel' was not declared in this scope
    sketch_may19a:151: error: return-statement with a value, in function     returning     'void' [-fpermissive]
    sketch_may19a:153: error: expected ';' before 'i'
    sketch_may19a:155: error: 'mpu' was not declared in this scope
    sketch_may19a:156: error: invalid types 'int[int]' for array subscript
    sketch_may19a:157: error: invalid types 'int[int]' for array subscript
    sketch_may19a:158: error: invalid types 'int[int]' for array subscript
    sketch_may19a:159: error: invalid types 'int[int]' for array subscript
    sketch_may19a:160: error: invalid types 'int[int]' for array subscript
    sketch_may19a:161: error: invalid types 'int[int]' for array subscript
    sketch_may19a:163: error: 'recievers' was not declared in this scope
    sketch_may19a:164: error: no matching function for call to 'RF24::write(int&)'
    sketch_may19a.ino:164:20: note: candidate is:
    In file included from sketch_may19a.ino:12:0:
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note: bool     RF24::write(const void*, uint8_t)
   bool write( const void* buf, uint8_t len );
    ^
    C:\Program Files (x86)\Arduino\libraries\RF24/RF24.h:281:8: note:candidate     expects 2 arguments, 1 provided
    expected primary-expression before ',' token

Please post the entire code (with the #include lines at the top).

Can you add line numbers to the code? As without them it is hard to determine which lines the errors refer to. Can you indent the code to make it more readable? Where are mpu and radio declared?

Also, as Spiked3 points out in his answer, the remapped values (of ax, az, gz, gy and gx) assigned to val are discarded, as you successively reassign val with new mapped values, without using the previous value. So only the remapped value of ay is tested. Is this intentional? Should the (val != prevVal) test not be repeated after each remapping?

Regardless, as you are a new user, welcome to SE Arduino, Frank..! :-) Please consider reading the tour page.

Replacing your original question with gibberish, once people have taken considerable trouble to answer it, is irritating. It is disrespectful of the effort they have put into their answers. -1 vote for doing this.

" considerable trouble to answer it"? i did not get no valuable answer if anything i waited my time even asking , so is ok it mutual we all waited our time XD......and btw not everyone wants their answer to be shared " I wanted the answer" if the community did not come up with the question i dont want to share my research

You do know that you assign 6 different values to val, before you use the last one?
And assigning 4 interrupts? I have to question how well you understand what you are doing.
Google pastebin for a method of posting all of your code before asking for help. And be sure to include what you have already tried and how it failed. People are much more likely to help, as opposed to do it for you.
update:  As pointed out using pastebin is not a good long term solution, just a quick fix.
You are doing quite a few newb things in your code. There is nothing wrong with that we were all newbs at some point.
First, you are driving 21 servos?  Assuming you board has 21 PWM pins, do you realize they could be drawing up a half amp or more each?  If at 1/2 that it would still be around 5 amps, that is probably 100 times more than the Arduino can handle.  So I hope you have made provisions to power them externally.
The first real error is on line 130. You define a stepper motor called GzUT, then you pass it to a function expecting a pin number. This is not correct, and I also suspect the 'stepper' library would already set up the pins and there is no need for you to do that. Even beyond that, you declare the GzUT as part of a structure, but you never create a variable that is made of that structure.
This is indicative you are not an experienced programmer, and an embedded program is not the place to learn how to program.
You are trying to do too much at first.  Go slower.  Get 1 servo (or stepper) to work. then add the others once you understand how to do that. Refer to samples from the stepper library web site. (http://www.arduino.cc/en/Tutorial/MotorKnob)
The MPU-6050 is also a somewhat more advanced sensor. It look like you plan on multiplexing them? With an I2C multiplexer?  Have you thought out the addressing? Do you have any idea of timing requirements of 21 servos and multiple i2c data streams and if the processor is even capable of meeting those requirements?  My experience with an Arduino UNO is it barely can keep up with 1 mpu-6050. I doubt if you can add more than one servo.
The Arduinos in general are awesome prototype platforms. They are great for learning embedded programming. But they are not so good for just learning to program in general, especially when you are trying to do a lot of work, of which 21 servos certainly qualifies as.  Again, my recommendation would be slow down, do one small thing at a time, or if this is a real project, contract it out to someone with experience.
Update: I didn't mean to offend. It is just unclear from your question and your code how much experience you have or do not have. That being said, I am not able to figure out which of the rlf2401 libraries you are trying to use. There 5 of them mentioned on this Arduino page http://playground.arduino.cc/InterfacingWithHardware/Nrf24L01. So follow up with which one you used and I will take a look.


text:
Using Parallax VPN1513 GPS Smart Module with External Antenna and Ruggeduino
I am using a Ruggeduino for a project involving an autonomous vehicle, and I need GPS capability in it. I am using the "VPN1513 GPS Smart Module with External Antenna" from Parallax (https://www.parallax.com/product/28510), and the TinyGPS Library (http://arduiniana.org/libraries/tinygps/). I have it supplied with 5v, grounded, and with the SIG and EN wires going to ports 0 and 1 on the Ruggeduino. Everything that I have done so far has resulted in this example program from the library returning "****", which means it is getting invalid data. Does anyone know what I'm doing wrong? Thank's for the help in advance.
Here's the program:

#include <SoftwareSerial.h>
#include <TinyGPS.h>

TinyGPS gps;
SoftwareSerial nss(1, 0);

static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

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

  Serial.print("Testing TinyGPS library v. ");
  Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = ");
  Serial.println(sizeof(TinyGPS));
  Serial.println();
  Serial.println("Sats HDOP Latitude Longitude Fix  Date       Time       Date Alt     Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)    (deg)     Age                        Age  (m)     --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("--------------------------------------------------------------------------------------------------------------------------------------");
}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();

  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }

  gpsdump(gps);
}

static void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);

  print_date(gps);

  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0)
    sz[len-1] = ' ';
  Serial.print(sz);
  feedgps();
}

static void print_float(float val, float invalid, int len, int prec)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
    if (len > 0)
      sz[len-1] = ' ';
    for (int i=7; i<len; ++i)
      sz[i] = ' ';
    Serial.print(sz);
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("*******    *******    ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d   ",
    month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  feedgps();
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  feedgps();
}

static bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

source: Stack Exchange

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

sort: votes


text:
Use Adafruit 16-Channel 12-bit PWM/Servo Shield to switch relays
I'm wondering if using the Adafruit 16-Channel 12-bit PWM/Servo Shield is it possible to switch relays, such as use that shield as a multiplexer and use digital output without PWM.
Is it possible? example code?

That's silly. Find something with GPIOs.

sorry can you expand a little bit your comment?

Thank you for your interest and the time that to allow to answer to our questions. I have the same problem and i want a sample code to control relay by 16 channel pwm i2c.
can you help me please?
How can i use this code in the answer in the top : pwm.setPWMFreq(1000);//put this in setup()
...
// enable relay at channel 15
pwm.setPWM(15, 1, 0);
...
// disable relay at channel 15
pwm.setPWM(15, 1, 1); thanks

That will work. Just make sure you are not using Servo part of the library, but only the PWM part, and set the duty cycle to 100%. The relay should still work, even if the duty cycle is slightly lower, as the magnetic field takes a bit of time to collapse. Just make sure you don't forget to add a (flyback) diode to the relay.
Looking at the datasheet I think you need to use the following code
pwm.setPWMFreq(1000);//put this in setup()
...
// enable relay at channel 15
pwm.setPWM(15, 1, 0);
...
// disable relay at channel 15
pwm.setPWM(15, 1, 1);

Sorry I haven't specified before, I need both: PWM and digital output. In this way you are "removing" the pwm, right?

No. The only thing I changed is the PWM frequency (to the highest possible value).

@nkint Why would you want to control a relay with PWM? At best, PWM would be fast enough to not affect your relay. At worst it might make it buzz. Or are you saying you need some lines to control relays and others to drive PWM outputs?

Using the adafruit PWM servo shield seems like overkill, you are paying for a lot facilities (PWM) that you won't be using. If you want to use the shield to reduce the number of pins used on your arduino board,  consider a pair of shift out registers (74HC595 for example). The relays need a logic 1 or a logic 0 to change state. You send a bit pattern to the shiftout register that sets the output pins of the shift register to 1 or 0. I found this page helpful.

Sorry I had no specified before, I need both: PWM and digital output. Hanks anyway.

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


text:
Arduino: Breadboards and PCBs
I just watched this excellent video tutorial that shows a simple Arduino program that toggles an LED via a pushbutton. Very cool!
In the video, the author is using a breadboard for prototyping his circuit. What's the next "step up" from this? In other words, say I get my breadboard circuit working perfectly, is it now time to create a PCB? If my understanding of circuitry is correct, this is not a trivial process. I would need a CAD program to design my circuit, and it would likely be very expensive to get the design actually fabricated. At least too expensive for simple hobby purposes. Is there a middle ground between breadboard and PCB?

But there are free EDA packages out there as well as affordable (but not truly cheap unless you're going for hundreds of boards) PCB fab services.

You can build your project on stripboard (aka Veroboard, which is a particular brand). The wiki page at http://en.wikipedia.org/wiki/Stripboard covers most of the salient points - it is essentially a generic PCB. You can cut tracks, either with a knife, or a specialized tool, and you can solder your parts on to the tracks.
They come in various configurations - my personal preference is just straight strips - and you can cut them to size with a hacksaw.
If your project is non-trivial, you might still like to spend some time working out a decent layout. There are free, and not quite free, products to help you - I use Kicad, which is free & opensource, there are many others.
I have also used stripboard to group a few components together - for example, 2 7-segment displays and two SIPO chips to run them - this can then be a "component" for future bread-board projects.

Eagle CAD is one of the most popular E-CAD programs, and is reasonably priced free for personal use. When Libraries, tutorials and examples are made available it is most often in Eagle CAD format.

Once you ready your design and layout (in Eagle) you can get boards made for $30ish (https://oshpark.com/)
You will have to obtain parts and solder yourself for assembly, but your time is free, right?  I have done a few. I was a software only person until I started in November 2014 (http://www.spiked3.com/?p=5981)

If you are only making one or two the following works well:

Download Kicad (Free) and design your board.
Print out the layout on special film, and transfer to a blank PCB using a domestic iron.An example: http://www.maplin.co.uk/p/press-and-peel-film-pcb-transfer-system-ab15r
Etch the board in ammonium persulphate or ferric chloride solution.
Drill the holes. You will need some 0.8 and 1.0mm drills and a Dremel drill press or similar.
Mount your components and solder away.

The above works well for single-sided boards. Double sided are possible, but will take some practice.
There is a learning curve getting to grips with Kicad, but if you are serious about electroncs, the time invested is well worthwhile. I got from being a Kicad novice to producing a specialist Arduino shield in a weekend. I had the advantage of having used similar tools in the past, and the disadvantage of being 67 years old (with eyesight to suit)
All the required parts should be available from agood electronics parts suppier (For example Jaycay here in New Zealand)

Is there a middle ground between breadboard and PCB?

A prototype PCB with breadboardlike layout is a fast way to turn a breadboard design into a permanent build. So it may be in the range of valid answers to your question.
(-: The link below is just an example, there are lots of other names, designs and sellers and I am in no way releated to any of those... :-)
https://www.tindie.com/products/Schmart/400-tiepoint-schmartboard-breadproto-board-bundle/

or perma-proto

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


text:
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 shield will drive a pair of DC motors (the common small ones in models), or one stepper motor (the precision motors you find in dead printers, etc), and can also connect onwards to other stuff, which happens to include servos. I certainly wouldn't get one to run a servo...
If you want more than two motors, there are other motor shields, or you could make a custom board to suit.
There isn't enough power from Arduino outputs to drive a motor (in general) so some sort of driver is needed - for a simple DC motor, a simple transistor would do, you need bridges for steppers, or ESC's for RC-model type high-power motors. Servo's have their own drivers built-in, so can just plug-in to Arduino.
If you just want to control a couple of motors or a single stepper, the shield is quick & easy, which is where it is placed in the market.

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.

Thanks @Ignacio Vazquez-Abrams (+1) - so it sounds like servos are more of an "all in one" choice, which has me wondering: when to use a servo vs a bare motor? I'm sure servos are more expensive (if they already come with the drive electronics, etc.), but are their specific use cases where one is preferred over the other (servo vs. bare motor), regardless of cost? Thanks again!

if you're talking about RC servos, they are closed loop systems. With the control signal you're asking the servo to move the shaft to a SPECIFIC ANGLE and HOLD IT.

You don't need this shield to drive servo motors, they have their own controller, you need just a 5V power line, GND and digital output pin to generate a PWM and that's it. Usually Arduino has enough power to drive servo motors.
This shield you are talking about is used for DC (direct current) and stepper motor. These motors need power gain and the shield provides it and often has a chip called L298N (which implements H-bridge) with MOSFETs to properly feed the motor.
What does this shield really offer in the way of driving motors?
A proper circuit and components so you plug your motor and connect into your board leaving you just the programming task to control motor's position and speed.
What is lost by not using this shield?
Actually, you use this kind of component just for practice purposes. It is already built and you just use it. However, it's a good learning process building the H-bridge yourself and understanding how it works and why it is necessary (if you have time, this is a good task).
What if I my project has more than 2 motors?!?
Well, just decide how many H-bridges you need. This shield has the capacity for 2 DC motors or 1 stepper motor. In case they are servo motor, you just use this lib. It is possible to have plenty of servos working together and all you need are good battery and enough digital pins. They share timers of microcontroller, that's why it works for many motors.

The statement “servo motors... have their own controller, you need just a 5V power line, GND and digital output pin to generate a PWM” is a little off.  In general, servo motors have an encoder and use a separate servo controller to read the encoder and adjust PWM output to reach a setpoint.  RC servos are a special subcase of servo motors.

good point, @jwpat7, some modern servo motors come with sophisticated control techniques such as PID which improves the stability and precision. That's the "controller" I was talking about.


text:
How to tell what components are compatible with Arduino Due?
I am interested in using the Arduino Due in an upcoming project, however I am worried that the other shields/components that I need will not be compatible with it, because, according to that link:

The Due is compatible with all Arduino shields that work at 3.3V and are compliant with the 1.0 Arduino pinout.

The components I need to use are:

NightShade Electronics energyShield
Solar Panel
Servo Motors

Essentially a solar panel will power the energyShield (rechargeable battery), which in turn will power multiple servo motors.
I cannot tell if the energyShield uses the 1.0 pinout or not. I am also worried that since the the solar power generates 6V it will overload the energyShield which is rated at 3.3V. At the same time, I am worried that the servo motors, which seem to require 4.8V, will not be capable of being powered by the energyShield which outputs 3.3V. Thoughts?
Bonus Points if someone can explain to me what the "1.0 Pinout" is, and whether it is the latest/most modern pinout available for Arduinos.

As far as I understood this energyShiled accepts any input between 5-24V and output 5 - 3.3V. This specs are compatible with arduino Due. And with the solar panel.
You can always power servos from seperate source or from the same battery but with seperate direct line.


text:
how can I change the setting for number of upload retries in the IDE?
I run into this problem when I mess something up, and it's pretty annoying to wait for 10 not in sync timeouts before I can try some different method.
...
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x85

How can I set the number of "attempts" to say 2 instead of 10? Or how can I safely interrupt the upload process in the IDE?

The code is not in the arduino ide but in the tool chain (.exe) that it runs.
Normally it is a program called avrdude.exe that is running so you would need to rebuild the avrdude.exe tool which is not practical.
The easiest way, but rather crude, is to pull the usb cable. If the port disappears avrdude should stop immediately.

what's the harder proper way?


text:
How to see log from Arduino IDE?
Where can I see outputs from such instruction in an ino file ?
Serial.println("my message");

Click the magnifier icon in the top right corner of the window.

The Serial.print statements show up on whatever terminal program is opened and connected. Their can be only one open at a time, but it could the Arduino IDE built in monitor (ctl-shft-m) or an external terminal program, eg putty, or some other program you wrote that opened the com/serial port the Arduino is on.
Remember though - only 1 can be open at a time. If you use an external program you MUST close the com port before attempting to download a new version of your sketch.  If you use the built in monitor/terminal it will automatically do this for you.

Thanks. In fact I think my logs are not visible because the uploading process never ends. I use an arduino BLE nano; any idea on how to fix the problem ?

Nope. Sorry never tried anything like that. Are you saying you are uploading your sketch via BLE and it never finishes? Im not familiar with those products, but they look interesting.

No I 'm not uploading via BLE, just using the upload button on Arduino IDE, but it never ends

This helped, but I also needed to initialize the serial library in the setup method - Serial.begin(9600); - described here before logs showed up in the IDE monitor: http://forum.arduino.cc/index.php?topic=25326.0

It took me ages to realize that instead of remembering Ctrl-Shft-M you can just click on the little magnifying glass in the upper right of the IDE interface. Wait until after your script uploads though, it won't do anything while compiling or uploading your script.

Call Serial.begin(9600) in your setup() function:
void setup() {
  Serial.begin(9600);
}

Call Serial.print('example') or Serial.println('example') in your loop() function (or one of your own functions that your loop() function calls:
void loop() {
  Serial.print('example');
  Serial.print('example');
  // Output of the two calls above: exampleexample
  Serial.println('example');
  Serial.println('example');
  // Output of the two calls above:
  // example
  // example
}

Go to Tools > Serial Monitor to see the output.
References:

https://www.arduino.cc/reference/en/language/functions/communication/serial/print/
https://www.arduino.cc/reference/en/language/functions/communication/serial/println/

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


text:
what ftdi windows driver for arduino nano
at http://www.ftdichip.com/FTDrivers.htm they seem to divide chips into two categories,  FT4222H vs. D2XX driver.
What's the correct for a arduino nano?

The Official Arduino Nano has an FTDI FT232RL.
You want to use the Virtual Com Port(VCP) Driver so the FTDI device appears as a COM port under windows.
See the getting started guide for details.

The nano board purchased was obviously not an official. Peter at http://www.amazon.co.uk/SODIAL-ATmega328-P-20AU-Module-Board-Blue-Black/dp/B00QPUEFNW/ref=sr_1_1?ie=UTF8&qid=1430991247&sr=8-1&keywords=arduino+nano
helps out with driver to the ftdi-chip clone:
http://www.wch.cn/downloads.php?name=pro&proid=65
All working.


text:
arduino suddenly shows “avrdude: ser_open(): can't open device ”\\.\COM3" after last upload
I am using arduino uno to make a sound detector. I uploaded a program, found error in the code that it returns unintended numbers unreasonably big. I also think I used wrong code for the module, but it was connected in the way that can work properly with the proper code.
The code I uploaded was:
const int ledPin =13;
const int middleValue = 512;
const int numberOfSamples =128;

int sample;
long signal;
long averageReading;

long runningAverage = 0;
const int averagedOver = 16;

const int threshold=400;

void setup(){
    pinMode(ledPin, OUTPUT)
    Serial.begin(9600)
}

void loop(){
    long sumOfSquares = 0;
    for (int i=0; i<numberOfSamples; i++){
        sample = analogRead(0);
        signal = (sample - middleValue);
        signal *= signal;
        sumOfSquares += signal;
    }
    averageReading = sumOfSquares/numberOfSamples;
    runningAverage=(((averagedOver -1 )*runningAverage)+averageReading)/averagedOver;

    if(runningAverage>threshold){
        digitalWrite(ledPin, HIGH);
    }else{
        digitalWrite(ledPin, LOW);
    }
    Serial.println(runningAverage);
}

When the arduino suddenly stopped sending serial numbers, I pressed reset button and uploaded the default code:
void setup() {
}

void loop() {
}

but now it shows that it cannot connect to COM3 (arduino) and cant find the device, When I can see arduino uno successfully connected to PC using device manager (windows 8.1). The led light of arduino also turns on when I connect it to power source or usb.
it shows "port not found" when I click to see the serial output
Did I just fry Arduino? How should I fix this?
Also, i checked the led pin 13 blinking three times when i plug in the usb. I just cant upload anything

I ran into such a problem when I was accessing my Arduino board from two different windows applications like Arduino IDE and eclipse. or Eclipse and some serial monitor windows application. Make sure you close any application that programs or communicates with the Arduino board, and make sure you configure the COM you are using in Arduino IDE and try again.
Also try disconnecting any wire that is connected to RX and TX pins when you are programming the Arduino.

You might have your serial monitor open at COM3 somewhere which is why AVRdude is failing to open the port again. Make sure the serial monitor is closed.
if you are opening serial ports on Python or your own developed applications, you have to explicitly close the port on exiting the program, otherwise, the port remains open and you come across such errors.

my arduino revived the next day.... don't know why but it works!


text:
Implementing Quasi-Perpetual Battery on Arduino
I am interested in seeing how much "uptime" I can achieve with my Arduino device/project. I am brand new to electronics/robotics, and so I wanted to bounce my idea off of this community first and see if I am overlooking anything obvious/major, or if my overall approach is incorrect.
The idea is simple:
Provide my Arduino device with 2+ "rechargeable power sources" (described next) and then provide a mechanism to route power to any viable (non-dead) power source at any time. While one power source is being used to power the Arduino device, the other "idling" power sources are recharging. The intention is to allow the device to keep switching between power sources endlessly, in perpetuity, achieving 100% uptime (perfect "high availability").
As for each "rechargeable power source" I am thinking an energyShield (rechargeable Li-polymer) backed by a solar panel.
I did some preliminary research and was told that if I were to wire these power sources in series with diodes, then the circuit would always by default draw power from the source with the highest voltage. As soon as another source has higher voltage, the circuit begins drawing power from that one, and the "old source" begins recharging.
I'm a noob but not a fool, and I know there is no such thing as perpetual energy (hence the title "quasi-perpetual"), and I'm sure factors like sunlight/weather conditions/etc. would affect the efficacy of the solar panels, etc. But I guess my first concern is: am I doin' it right? Are there any caveats/pitfalls or considerations I'm overlooking here?
Assuming I'm more or less correct in my approach, the other concern is how to actually implement power sources and diodes in a series, and how to actually rig that all up and connect it to the Arduino board. Again, I'm a total electronics newbie, so I'm just having a tough time visualizing the precise solution there.
And as for determining the actual number of power sources (energyShield + solar panel combo) my device would need, I was just planning on starting with 2, and running the device at max power and monitoring their recharge rates. The more sources I add, the longer the device will operate. Obviously, at some point I'll either reach a point where its uptime is sufficient for my needs, or I'll run out of money. :-)

I think you mean "parallel", not "series".

You're overthinking it. Use one or more solar panels, a harvesting IC with sufficient storage, and the bare MCU and peripherals. Use enough panels and storage to run the MCU and peripherals 24/7, and to also charge the storage during the day.

As always, thanks @Ignacio Vazquez-Abrams (+1) you are my hero. But as always, I am compelled to ask followups! (1) What's a good way to tell how much storage my harvesting IC would need? (2) Any chance you can confirm that this one is an example of an IC that is compatible with an Arduino Due? And finally (3) Are there any solar panels you know of (from Ada Fruit or wherever) that would easily connect to this IC? Thanks again!

Measure how much power it uses over a day and add 25% margin. 2. Does it match the input specs of the Due? 3. Nope.

@smeeb, your comment links to your own TI basket so doesn't show what chip you meant to mention.

"I did some preliminary research and was told that if I were to wire these power sources in series with diodes, then the circuit would always by default draw power from the source with the highest voltage."
That is not correct - you need the two sources in parallel with a diode each. Then the higher voltage will become the current source.
When the sources are charging, the charge source may become the current source if that voltage is higher than the other stored charge source.

Sorry, didn't realize how old the question was.


text:
Undefined functions send() and receive() on TwoWire/SPI
I have downloaded a sketch that uses SPI.  The sketch includes the Wire library but at compilation time, I am getting errors that TwoWire doesn't have methods called send() and receive()?

This is caused by the sketch you downloaded being old.  In prior releases, the methods called send() and receive() were used to send and receive SPI data.  These were renamed to be write() and read().  If you change your code where there are references to Wire.send() and change to Wire.write() and also change Wire.receive() to Wire.read(), you should find that your applications compile and run correctly.


text:
How do i properly read an analog pin on attiny85?
Anyone ever run into a problem with your attiny not reading  your analog pins correctly? (-1023 or 1023 or 0 value) How did you resolve the issue?
Here's what my code looks like now :
4th revision of code as of 5/6/2015 8pm:
int NTC = A1; // thermistor
int switchPin = PB1; // push button
int LED = PB0;  // led

// button latch
byte ButtonState;
byte lastState = LOW;
byte count = 0;

 //brightness level of each different mode
int low = 50;
int med = 140;
int high = 255;
int dim = 0;

int ADCcount = 0;

void setup()
{

 pinMode(switchPin, OUTPUT);
 pinMode(LED, OUTPUT);

  }

 void loop()
 {

  ADCcount = analogRead(NTC);

delay(100);

  ButtonState = digitalRead(switchPin);

  if(ButtonState && ButtonState != lastState)  // button latch, no debounce      needed.
   {
      if(count < 4) // This will check to see if the count is within a range of  0 - 255
                 // anything over that, it will reset count back to 0. Of course
      count += 1;  // same as count = count + 5;
      else
      count == 0;
        }

    lastState = ButtonState;

   if (count == 0)
  {analogWrite(LED,0);}
    else if (count == 1) { if(ADCcount < 500) {analogWrite(LED,high);}
      else{ if(ADCcount > 525){analogWrite(LED,low);}
       }
          }
      else if (count == 2 ){analogWrite(LED,med);}
      else if (count == 3) {analogWrite(LED,low);}
      if(count >=4) {count = 0;}
      delay(50);
 }

simulate this circuit – Schematic created using CircuitLab

Show some effort and indent your code properly. Use four spaces in front of every line of code. I'd do it myself, but I'm on a phone right now.

350000 is a very big value for microsecond delay. The generated code might overflow and not actually wait or get stuck in an infinite loop. Use millisecond delay instead.

@FRob I switched the delay from microseconds to milliseconds but unfortunately it did not solve the issue..

Did you try to run it in debug mode with frequent stops to see the execution flow? I just do not see an infinite loop in your script. What happens after void loop() is executed?

@Naz Um... it loops (the function executes again). The arduino environment hides the standard main() function, declaring but not defining the setup() and loop() functions you see there, instead.

Ah.. ok. Is the error time dependent? Does everything work fine first 30 minutes? I see that the problem could be caused because when the microcontroller is working on some other program lines and you press the button, so it does not react to it. It means you must press it right before the new loop of the loop() function starts. This is very difficult to do. Instead, I would recommend to introduce interrupt subroutine that will react on the pin change value (the interrupt can react on rising edge, falling edge, or both). This way, you can strictly control this input signal.

@Naz No sometimes it will lock up after five minutes, other times longer than 30 minutes. I've never heard of an interrupt sub routine, from the little ive googled it could be the way to go. know of any good examples?

I do not follow one thing - this microcontroller has no DAC. How to do perform analogWrite?

@Naz It sets up a hardware timer, using a output compare unit to generate a PWM waveform, with the function argument controlling the duty cycle (by affecting OCRxx). Thats why "analogWrite" is only available on certain pins.

@jms Oh, PWM sounds good.

Whats the frequency of your PWM? What kind of LED is this (datasheet)? Why isn't there a series reistor with the LED?

@Golaž I do not know what the frequency of the pwm is.
led doesnt need a series resistor, to the extent of my knowledge.
http://www.cree.com/~/media/Files/Cree/LED%20Components%20and%20Modules/XLamp/Data%20and%20Binning/XLampCXA1512.pdf

Yes, you are right. However, no offence, but your code is utterly uggly... You're doing the same calculations in all of the switch cases, why not just make a function and call it? I am not sure what compiler you're using, but if you're declaring a variable inside a switch case one normally has to use curly braces case x: {... break;}. This way you'll be able to get rid of those global variables. Please clean it up a bit.

Also, you're doing quite some heavy calculations on a 8-bit uC, you're using division,log and floating point variables. On your uC there is no hardware divider neither there is a hardware floating point support. You might be missing out all those button presses due to these complex calculations. I would rethink your design... Can you linearize it?

@Golaž  no offense taken im sure the code looks fugly, im working with three months of knowledge. This is my first major coding project im using the arduino compiler. I like your function & Linearization idea ill try and clean the code up however im gonna need to do more research on how to linearize the calculations.

First try to clean the code up a bit and then edit your question. There might be a clear indication of whats wrong, but its hard to analyze it now as it is.

@Golaž I put all the same calculations in the switch cases because of the if statement.( at the very end of the case said if steinhart > 30 analog write led etc. etc.) when i made the function for temperature and a function for the switch case i could no longer write an if statement to read the temperature then write the led output. How would you go around this?

Your code is better now. However, I dont have enough time today to take a closer look, will check it tommorow.

How is the thermistor wired? The pin assignments in your code do not fit your schematic. 2) The switch pin should be configured as INPUT. 3) What should happen when count = 1 and 500 ≤ ADCcount ≤ 525? 4) Why use two delays in loop() instead of a single 150 ms delay? 5) The test for count >= 4 at the end of loop() is useless. 6) A switch/case on count would make the code more readable. 7) Constants should be declared const.

The improper bush-button event handling is likely to cause the problem. One way to properly react to the external environment signals could be constant polling or using interrupts. With constant polling, all the time is spent on the checking the status of the button. With interrupts, the program is executed as it should, and only if interrupt happens - the execution jumps to the interrupt subroutine, executes it, and goes back to the main code where it left off.
In your case, you can use pin 7, for example, for push button signal. It can have a function of INT0. Read Section 9. Interrupts of the datasheet - it is straight forward.
I do not completely understand what your program should do, but I will try to convey the general approach of using subroutines:
volatile bool pressed = false;
int main(void)
   {
   MCUCR |= (1<<ISC01 |1<<ISC00);       // set INT0 to interrupt on rising edge of pin7
   sei();                               // enable global interrupts

   while(1){
      if (pressed) then do something; //You can disable interrupts here so your code is not interrupted by cli();
      pressed = false; // reset the state
      else do something else;
   // you can re-enable your interrupts here by sei();
   }
}

// only happens when the change on pin 7 is from LOW to HI
ISR(INT0_vect){
pressed = true; // update the pressed status
}

If you want to use pin6 for push button, you should enable the PCINT1 instead of INT0 and change the ISR to handle the PCINT1 interrupt. In this case, pin 6 will react on voltage toggle (from HI to LOW, or the other way) and you can not discriminate rizing/falling edges. In that way, you must read pin6 within the instruction subroutine to know if it is hi or low.
EDIT:
I would suggest to stop the calculations in the Temp() function after the
  average = SERIESRESISTOR / average;

line due to the fact that you have only three operating modes for the LED. Thus you can, back calculate the average value that makes your steinhart value to be, for example >30. This way, all other values greather/smaller than that value will also fall under the same condition depending on whether average/steinhart are directly/inversely proportional.
When you determine the three ranges of raw average values you can use them directly in the Mode() function. Eventually, you can optimize you code even further, by performing monotonic read instead of burst reads. If you keep a buffer, you do only one addition of the most recent sample and subtracting the oldest sample. For this you will need two pointers and one memory for to store sum, but you will not need to do nSamples additions:
read (newSample);
sum += newSample;
sum -= oldestSample;
average = sum/numSamples;
update pointers to the memory for oldest sample and for the feature sample;

350ms should be ample time for the button to settle. Currently, he constantly polls, but when pressing the button for a short amount of time, it should work as is. Of course, pressing and holding it will cycle through all "modes" (counter) without ever giving a reading.

@Naz would I place this code under the void loop ?also should i include the int main?

@FRob is there a way for when the button is held down it doesnt cycle through all the modes?

I use Atmel Studio and this is how standard mix of C and assembly is written. I do know what should be written in Arduino environment.

@Naz I downloaded atmel studio yesterday learning how to program with atmel is next on my list.

@Naz You have a couple of mistakes in your code. pressed should be outside of main and defined as volatile. Secondly, delay shouldn't be in an ISR put that into main.

@Golaž You are right: Pressed is moved, the delay is removed. I tried to convey the concept idea instead of proper programming code. But for the sake of correctness, please, feel free to edit my answer.

@Naz I tried to implement your interrupt for the push button but i must have done it wrong because now the push button doesnt work at all.

@Naz Ill use my second arduino to run the thermistor sketch and monitor the raw resistor values to cut down on the temp code but how to do i create a pointer for memory and update that pointer?


text:
Arduino YUN real time control
I have a very specific problem, exactly with real time control. For example I try to write an application where I can edit min or max temperature that after reaching it , I will receive SMS with message. I'm wondering how to edit variables "on-the-fly" because, as I know Arduino IDE use it own libraries not this from C/C++, and I don't know how to get to SD card in Arduino too. Can someone help ?
Thanks

the SD card is at /mnt/sd/ . you should consider reading the yun tutorials here before going further, the ability to send and receive data is at the heart of the yun design.


text:
Can the Arduino Due be used as a serial to USB converter?
The Arduino due exclusively runs on 3.3V, so I am wondering if this can be used as a USB to serial converter just like the Arduino Uno could, or do you need to do level shifting?? Will I ruin the board if I just hook up RX and TX to a 5v device?

Yes it will work as a USB to serial device, however the serial will be at 3.3V not 5V. It'll still be serial though.
For it to send data to a 5V device, depending on the device, it might work.  3.3V is often around the "high" threshold for an input pin on a 5V device, but check the datasheet for the 5V device to be sure.
For receiving data the 5V will be above the 3.3V supply voltage of the main SAM3X chip, so should be avoided. As with most Atmel datasheets, actually finding the information you want is almost impossible, and I haven't found if there is a maximum "over voltage input current" or not, so to be on the safe side a full level shifting voltage divider should be used on the RX pin.

According to the datasheet 'Absolute Maximum Ratings' on page 1378 (where you'd look for things like these...) Voltage on Input Pins with Respect to Ground (except VBUS)...............-0.3V to +4.0V. No idea what you mean with "over voltage input current" but I'm not surprised it isn't in the datasheet.

Well, I said s***w it, and went ahead and tried it. Everything actually worked just fine! I was able to communicate with a serial device with putty and send and receive commands. I probably am going over recommended voltage, but I have not fried my Arduino (checked Rx and Tx with 3.3v device afterwards), so I guess it's fine.

The "over voltage input current" is basically the current rating of the ESD diodes on the input pin. I fyou know that you can get away with just a series resistor on the RX pin to protect it. I would advocate at least having a series resistor if you are reticent to make a voltage divider. 1K would most likely give enough protection.


text:
What is the function of the XBee / USB switch on an XBee shield?
I recently bought an XBee shield (this). The shield has a switch that seems to switch between USB/XBee. However, there is no USB port. What exactly is the switch supposed to do?

it looks like the switch connects / disconnects the XBee to the hardware serial port. And must be disconnected to program the board.

In case someone does ask the same question in the future, this is the explanation for the USB/XBee switch functionality on the XBee Pro Shield V3
The switch serves to connect/disconnect the XBee Pro shield v3 to the Hardware TX->1 & RX<-0 Lines of the Arduino. Moving the switch to the USB side, allows you to disconnect the XBee Pro shield v3 from the hardware serial lines and upload code to your Arduino. If the switch is on the XBee side, this allows your XBee Pro shield v3 to use the TX->1 and RX<-0 lines of the Arduino and if you want to upload code to your Arduino, you would have to remove the shield otherwise it would result in an error trying to upload code.

Better to check connection with tester. I think it switches connection to bluetooth module directly to your PC (with usb serial converter which is on arduino board)  or with arduino microcontroller.

I imagine that the switch has the same functionality as the "serial select" switch on the official Arduino Wireless Shield for XBee modules. Therefore the explanations on the switch settings given there (http://www.arduino.cc/en/Main/ArduinoWirelessShield) probably apply also to your board.

That link doesn't work anymore... "Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline." (from https://stackoverflow.com/help/how-to-answer)

The Xbee shield has aswitch labled Xbee/USB. This determines how the Xbee's serial communication connects to the serial communication between the microcontroller (ATmega8 or ATmega168 or Atmega328) and FTDI USB-toserial chip on the Arduino board.
In the Xbee position the Xbee module is connected to the RX pin of the microcontroller; and DIN is connected to TX. Note that the RX and TX pins of the microcontroller are still connected to the TX and RX pins (respectively) of the FTDI
chip - data sent from the microcontroller will be transmitted to the computer via USB as well as being sent wirelessly by the Xbee module. The microcontroller, however, will only be able to receive data from the Xbee module, not over USB from the computer.
In the USB position, the DOUT pin the Xbee module is connected to the RX pin of the FTDI chip, and DIN on the Xbee module is connected to the TX pin of the FTDI chip. This means that the Xbee module can communicate directly with the computer -
however, IMPORTANT this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the Xbee module.
THANKS TO RS-COMPONENTS FOR THE DETAILS!!!!!


text:
Arduino at 20 MHz?
I wonder why Arduino doesn't run at 20 MHz, the frequency the AVR is specified for. Now, running at 16 MHz, we're wasting 20% performance for nothing.
I don't think there are any implications when you replace the 16 MHz resonator with a 20 MHz type, with probably the sole exception for the baudrate in the bootloader. Or is there?
Does anybody know why the Arduino designers chose 16 MHz?

Don't forget to set the fuses when you do this

@portforwardpodcast no need to change the fuses. They are already set to "Full-swing external oscillator".

There's no hardware reason (as far as I'm aware) that you couldn't run a suitable Arduino at 20 MHz. You'd run into minor timing inaccuracies in software though, as the standard Arduino configuration apparently works best if the clock speed is either 8 or 16MHz.
I suspect this is largely for historical reasons. Early Arduino boards were based on chips which only went up to 16 MHz, such as the ATmega8. Using the same configuration for all chips just keeps everything a bit simpler and more consistent.
There is more information here about the timing issues: http://forum.arduino.cc/index.php?topic=158223.0#msg_1186708

Thanks for your answer. Can you elaborate on "exact power of 2"? The 1 second period over which clock pulses are counted doesn't mean anything to a microcontroller, it only knows clock ticks. Overmore, 16 MHz isn't an exact power of 2, that would have to be 16.777216 MHz.

@JorisGroosman Sorry I didn't explain that properly. It's about the way the Arduino core calculates microseconds from clock ticks. This forum topic gives a much better explanation than I could.

You can, and I do.
It's not technically an Arduino anymore, I guess. I made my own board, replacing a resonator on a board will require some fine soldering, but it is definitely possible.
There are some gotchas: Anything time-related (e.g. millis() ) will be run faster than is should - 25% more millis() per second. Also, the bootloader expects 16mhz, so you won't be able to reprogram it at this speed. I purchased a USBASP programmer - it hooks into the 2x3 pin grid on one side of the board, and lets you reprogram it without the bootloader (this is how the bootloader is put on in the first place!). You will need at least 4.5 volts at 20mhz to avoid problems, compared to 3.78 volts for 16mhz - this means batteries will drain somewhat quicker (3x1.5v batteries will run down pretty quick), and if you have any motors or other draw on the batteries, 3 1.5v batteries will probably not work even if they are fresh.
Alternatively, going in the exact opposite direction, the lower the clock speed, the less voltage is required - for some projects, you might not need the clock speed - you can go down to 1.8v running at 4mhz.


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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
Uploading... forever
This is my code:
const int trigPin = 4;
const int echoPin = 2;
const int trigPin2 = 6;
int incomingByte;
int val, val2;
const int echoPin2 = 7;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  pinMode(trigPin2, OUTPUT);
  digitalWrite(trigPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);

  pinMode(echoPin, INPUT);
  pinMode(echoPin2, INPUT);

  val = digitalRead(echoPin);
  val2 = digitalRead(echoPin2);

  if (val && val2 == HIGH) {
    Serial.println("Elephant on tracks");
  }

  if (Serial.available() > 0) {  // if the data came
    incomingByte = Serial.read();
  }
  // read byte
  if(incomingByte == '0') {
     digitalWrite(trigPin, LOW);
     digitalWrite(trigPin2, LOW);
     Serial.println("The system is OFF.");  // print message
  }
}

Anyhow, I click upload, and as the title of this question says, have to wait forever.
Not only this code, nothing gets uploaded. It was working just fine a week ago.
I run a Windows 7 64-bit system, and have an Arduino Uno R3.
Does anyone have any suggestions?

So you can't upload the sketch to Arduino? No error messages at all? Try to enable the verbose options in settings and paste the result here

Are you uploading to the right serial port? Do you have anything else attached to the Arduino?

Thanks for the suggestions. It finally worked. It was because of my HC-06 Bluetooth module. I don't know if the mistake was mine or if it is a fault with the module.

From your code, I assume that the bluetooth module is connected to pins 0 & 1 on the arduino. These pins are to be kept free/floating/not connected to anything if you need to upload code to your board.
Use software serial in such cases reduces the headache

Comment by SR1 turned into an answer:
Thanks for the suggestions. It finally worked. It was because of my HC-06 Bluetooth module. I don't know if the mistake was mine or if it is a fault with the module.

(Done to reduce "unanswered questions" on this site).


text:
arduino ethernet shield
I bought a ethernet shield for my Arduino Uno. I plug it my Arduino and PC with ethernet cable. There is all led is working on ethernet shield. But when i try to examples about ethernet which is in Arduino IDE as "DHCPChatServer" example.
I hope to see;
"Trying to get an IP address using DHCP"
"My IP address: 192.168.1.177"
But I just see "Trying to get an IP address using DHCP"
Any problem with my ethernet shield?

Are you running a DHCP server on the PC you connect the Arduino to? If not, it cannot obtain an IP. You may want to use a static IP instead.

I tried static IP but it didn't work.

@user3748265 What static IP address did you try? Only certain ranges are valid for local networks.

I check out ip address with ipconfig and i set up my ethernet with this ip address. IP address is 192.168.2.101 subnet mask:255.255.255.0 gateway:192.168.2.1

When you connect your arduino directly to the PC using the ethernet cable, neither of them have any information about the network.
Most ethernet devices attach to switches, routers, and gateways, and one or more of these devices host network services such as DHCP, DNS, or provide a way to obtain those services.
Without DHCP, for instance, neither your PC nor the Arduino know what IP adress to use, what their netmask is, and whether there's a gateway to other IP addresses.
You have a few options:

Follow the Automatic Private IP Addressing specification, which windows computers default to when no DHCP server is present or available. Set the IP address of the Arduino to 169.254.x.y where x and y are randomly chosen numbers between 0 and 255, and set th netmask to 255.255.0.0.  The windows computer should have done the same if no static IP address was set - use ipconfig on the windows command prompt to find its IP address.  Your computer and arduino should be able to talk to each other.
Set up a router. It doesn't need to connect to the internet, it just needs to connect to both the PC and the Arduino.  It'll implement a DHCP server and make sure, at minimum, that the two devices can talk to each other and the router.
Set static IP addresses on both devices.  Set up the PC with something like 192.168.42.1 with a netmask of 255.255.0.0 and the Arduino with 192.168.42.2 and the same netmask.  Now they should be able to talk to each other.
Connect both to an existing network.  The network should already have a router with DHCP on it, so it'll take care of everything, and as a bonus you may be able to get internet access as well, which could help with testing since you can use the ethernet shield to communicate with google and other known working services, rather than trying to set up a server on the PC.

I changed my Arduino Uno with Arduino Mega and problem is solved.Thank you


text:
Reading/writing to Arduino GPIO pins from raw C code
I'm interested in writing a C program without the Arduino IDE and related libraries and am trying to figure out how I can access the GPIO pins for read and write.
My assumption is that the GPIO pins are - at the hardware layer - just memory addresses, and so if I know what their address is I can send/receive data to and from them.

For writing to the digital pins, do I just send an int with a value of 0 or 1 to the pin's address? If so, what might that code look like? Can I then assume I could poll that address for a value, which would be either 0 or 1?
Can I assume the same for analog pins, but instead of binary values, I'd get an integral value between 0 and 1023?

And if I'm way off here, and pins are not accessed via memory addresses, then how?
Again, the solution I'm looking for wouldn't involve Arduino software, just the Arduino hardware (an AVR or ARM MCU). Bonus points for C pseudo-code examples! Thanks in advance!

I know the AVR stuff is easy, but I couldn't tell you how the ARM stuff works; I have an ARM board but I haven't had a chance to look at it.

Thanks @IgnacioVazquez-Abrams (+1) - I only mentioned ARM because that is what the Arduino Due is using, and I am interested in the Due for its beefier computing power. In any event, am I on track or way off in dodo bird land? Any chance I could see a few lines of C code for reading/writing pins (digital or analog)? Thanks again!

For the AVR-based Arduinos, a good reading: Port Registers.

Thanks @EdgarBonet (+1) - good find! Any ideas what the Arduino Due (ARM) might be using? Thanks again!

Also @EdgarBonet, I'm just realizing now, in that article it appears that the  DDRD register (controls data direction for pins 0 - 7) is a variable defined in the Arduino language. Since I am looking to bypass Arduino libs, what what the variable's value be in C?

No, DDRD does not come from the Arduino "language", it's defined by avr-libc. Just #include <avr/io.h> and you get all the I/O registers you see in the MCU datasheet.

In theses cases you are right, using register address is the way to read/write data from/to digital pins.
In the case you use analog input, the process is similar but you have to follow some procedures before getting the value of the data.
GPIO REGISTERS
For AVR micro-controllers these registers are:
DDRn – Data Direction Register
PORTn – Port Output data Register
PINn – Port Input Register
n- Indicates the port name i.e. A, B, C & D
If you have arduino board and want to use these pins, look for mapping pictures about arduino and avr pins.
The following is an example from the Arduino website.
DDRD is the direction register for Port D (Arduino digital pins 0-7). The bits in this register control whether the pins in PORTD are configured as inputs or outputs so, for example:
DDRD = B11111110; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
DDRD = DDRD | B11111100; // this is safer as it sets pins 2 to 7 as outputs
                         // without changing the value of pins 0 & 1, which are RX & TX

See the bitwise operators reference pages and The Bitmath Tutorial in the Playground
PORTD is the register for the state of the outputs. For example;
PORTD = B10101000; // sets digital pins 7,5,3 HIGH

You will only see 5 volts on these pins however if the pins have been set as outputs either by using the DDRD register directly or by using the  pinMode() function.
For analog read
You just need to include the headers and start using the registers. They hold the equivalent hexadecimal values for your microcontroller. And the procedure is described in the datasheet. All you have to do is to translate it to code.
// this code scans ADC1 for an analog signal upon request, using 8Mhz processor clock

#include <avr/io.h>
#include <stdint.h>       // needed for uint8_t

int ADCsingleREAD(uint8_t adctouse)
{
    int ADCval;

    ADMUX = adctouse;        // use #1 ADC
    ADMUX |= (1 << REFS0);   // use AVcc as the reference
    ADMUX &= ~(1 << ADLAR);  // clear for 10 bit resolution

    // 128 prescale for 8Mhz
    ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

    ADCSRA |= (1 << ADEN);    // Enable the ADC
    ADCSRA |= (1 << ADSC);    // Start the ADC conversion

    while(ADCSRA & (1 << ADSC)); // waits for the ADC to finish

    ADCval = ADCL;
    ADCval = (ADCH << 8) + ADCval; // ADCH is read so ADC can be updated again

    return ADCval;
}

int main(void)
{
    int ADCvalue;

    while (1)
    {
        ADCvalue = ADCsingleREAD(1);
        // ADCvalue now contains an 10bit ADC read
    }
}

For more information about analog read, see this.

Thank you so much @bpinhosilva (+1) - however, I'm not 100% sure you understand my exact question. Take DDRD for instance. In your code example above you have: DDRD = B11111110. You state that this sets Arduino pins 1 - 7 as OUTPUT. But DDRD is a variable... but what library is it define inside of? In other words, what #include statement do I need to add to my source code to gain access to DDRD? If the answer is one of the Arduino libraries, then this doesn't help me! I need non-Arduino access to the AVR/ARM pins! Thanks again!

I just noticed your 2nd code sample above includes avr/io.h - if you can confirm that DDRD (and other similar port/register vars) are defined in this file, I think I'm all set!

You use #include <avr/io.h>. This is a standard library for avr units. Inside that you find definitions for these registers. Other point is that I am assuming you use Arduino but want to develop with a different IDE. So you need to find the equivalent avr pin to your board's labels. That's why the code says Arduino pinx and so on.

These names are not variables, they are mnemonics for addresses so you can easily remember them. You are welcome!

Thanks again @bpinhosilva (+1 again) - last followup question: I am wondering what the equivalent is for ARM registers. I found this EE.SE question but no one has answered it. Any idea what I would use for an ARM MCU? Thanks again!

I have never used ARM before, but I think it is similar. Just take a look at the datasheet and then you will see the gpio pins. And probably there is a lib similar to avr/io for your usage.


text:
Wifi REST API GET call - how to concatenate and pass URL parameters?
I'm not too familiar with the Arduino C++ language, but I would like to get this native code to work.
In curl this works:

curl "http://access.alchemyapi.com/calls/text/TextGetTextSentiment?text=i+feel+great&outputMode=json&apikey=my-apikey"^C

So I am trying to use a WiFi client for the same request but it seems the passing and parsing of the URL parameters is causing a problem.
sprintf(request,"/calls/text/TextGetTextSentiment?apikey=%s&text=%s&outputMode=%s","31adba6dfc3a879b88762f50efc9f892bd573207", "i+feel+great", "json");
Serial.println(request);

When I print the request, everything after the & gets truncated.
  char serverName[] = "access.alchemyapi.com";
  if(client.connect(serverName,port) == 1)
  {
    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }

This works (HTTP status 200, though with missing parameters error from the API service) if I only pass in 1 parameter.

How is "request" defined?

Concatenating the string data in memory before sending it shouldn't be necessary. Instead, you should just be able to use client.print() (or equivalent) to output each part of the request in sequence. For example:
client.print("GET ");
client.print(page);
client.print(" HTTP/1.1\r\n");

client.print("Host: ");
client.print(serverName);
client.print("\r\n");

// etc.

That should let you output any combination of HTTP headers you need.


text:
How can I stop someone from hacking in to my Arduino via Bluetooth?
I am using an HC-05 bluetooth Module. How can I stop someone from pairing with my device by brute forcing the key? Failing that, and if someone does pair with my device, is there a way to authenticate the user? I was thinking of salted hash with a shared secret key. Is there anything better?

Are you thinking that a device could repeatedly try and pair with you by submitting different keys over and over?   I'm not sure about the spec of bluetooth nor maximum allowable key size ... but I'm guessing that you can set a key to be at least 8 bytes in length ... which makes a brute force attack on your device no more or less likely than a brute force attack on any other password protected environment.

Why is your device always accepting pair requests?

@Kolban HC-05 does not take any more than 4 numbers. http://www.tec.reutlingen-university.de/uploads/media/DatenblattHC-05_BT-Modul.pdf

@IgnacioVazquez-Abrams It does not. But with just 10000 pins, it is not hard to brute force. Should I add an application layer security? Nonce / salting / hashing etc?

... But if you're not accepting pair requests then they could try 1000000000 pins and still not get in. Because you're not pairing.

@IgnacioVazquez-Abrams How do I disable pairing on an HC-05?

@LordLoh. what is your end application? Are you really sure that someone will/would want to hijack your device? If so, probably bluetooth is not the most advisable protocol (because the hijacker can just leave the device paired and you won't be able to access it again). Anyway you can't stop someone from connecting, but if there are security issues and you must use bt then encrypt the communication..

Configure your Bluetooth module to AT Command Mode
Then use AT+PIN Command to change the default PAIRING PIN of the Bluetooth Module.
Visit this link for more information about how to configure bluetooth to AT Mode

The question was not how to change the PIN, but whether on not to trust the link layer security? For my application.

In case someone else asks the same question in the future, here's the answer...
Technically speaking, the Arduino cannot be hacked for the simple reason that it doesn't have an Operating System like other devices such as the Raspberry Pi, BeagleBone, Rock64 etc. So in as much as someone might be able to bruteforce the HC-05 pin and get access, there's pretty much nothing else they can do past that point, so my advice to you is that don't stress over it. However I would suggest adding a few security measures to your HC-05 Bluetooth module:

Change the default pin (0000 or 1234) to something else.
Lock the module to connect only to a specific device via the MAC Address and the AT+BIND command.

Cheers!


text:
Arduino AD-converter tolerance
I created a quite simple Arduino sketch:
void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);

  float voltage = sensorValue * (5 / 1023.0);
  Serial.println(voltage);

  delay(1000);
}

I use the following circuit:

My multimeter measures 3.31 V, between the pin 3V3 and GND.
I get a sensorValue of 730 and a calculated voltage of 3.57 V. This is 8% higher that 3.3V. What is the tolerance by the AD-converter?

Did you connect the 3V3 directly to A0 with no current limiting resistor?

Of course. I added a picture of my circuit.

Is the circuit's supply a USB? if so, the 5V can have a 5% error... Moreover are you measuring between 3V3 and A0 or A0 and ground?

I measure between 3V3 and ground. I will fix it in my question.

It is powered via USB and I have 3.31V. So, this 5% tolerance is not the problem. My problem must be something with the ADC.

What voltage does your voltmeter say the "5V" supply is? That's the 5.000 that you're using in your calculation.

Ahhhhhhhhhh. It is just 4,65 V. This is 7%. Fixing my formula to  voltage = sensorValue * (4.65 / 1023.0) returns 3.3V.

In engineering (and usually also in life in general) when asking questions or seeking to learn, it is usually wise to avoid the mind set that goes with "Of course" and " ...the problem MUST BE something with ...". Both of these lock you into mindsets that hide information and/or  decrease the likelihood that people will make the effort to help you.

The absolute accuracy of the ADC in the ATmega328P when its clock is within its optimal range is given in the datasheet as 2LSB. This means that the actual value could be anywhere between 728 and 732.
Of course this depends on the accuracy of VCC, since it is being used as the ADC reference. This is why supply voltage measurements should be performed using the internal bandgap voltage instead.

Okay. Can you expain it a bit more detailed? Were are the 728 and 732 coming from? Like this, my 730 are fitting well. But then, calcuating the voltage does not fit: sensorValue * (5 / 1023.0) = 730*5/1023 = 3.57.

Did you read the first sentence of the answer?

730+-2LSB is 728/732. That is clear. Let me change my question: why is the value 730 for 3.3V and not 675+-2LSB?

The value 675 in the formula sensorValue * (5 / 1023.0) would give me a voltage of 3.3.

If I change the formula to sensorValue * (3.3 / 730.0), it returns the correct values for other input voltages. I still dont know, why it is the value 730

Please measure the value of your 5 volts, and tell us what it is. At a guess it's about 4.7 volts. Also, make sure to measure the voltage right on the Arduino board.

@Dennis: If 730 count is 3.31V, 1023 count is about 4.64V. Your supply voltage is low. Which is what the second paragraph covers.

Right, my input voltage is to low. With some adjustments, everything fits now.


text:
Venus GPS + Arduino. Kill 3.3V TX during sketch upload
I am playing around with the Sparkfun Venus GPS.  I followed this tutorial to get started.  In here the author states that you should

Upload the following sketch to your Arduino BEFORE making any
  connections. 5V from an IO pin left high on the Arduino may well kill
  the 3.3V output from the Tx pin on the GPS module.

However, I am using the Sparkfun bi-directional logic level converter in between the Arduino and the Venus GPS (because I'm using the 5V Arduino GSM shield stacked on top of the Arduino).  In that case, would the above statement still apply?

If you have a logic-converter between the Arduino and the GPS then you won't have any problems.
The warning was about having the output from the Tx pin on the GPS possibly being damaged by +5 V from the Arduino, if a previously loaded sketch made it an output and HIGH.
However you could just as easily upload a "do nothing" sketch like this:
int main () { }

That is sound practice anyway, if you are connecting up new hardware and are not sure what the currently-loaded sketch does.

I've been running it without any issues with a logic converter for a while now.  Thanks for the tip on the do nothing sketch though.


text:
Vibration sensor for arduino
I need vibration sensor for my project. I have found many sensors similar to this one. But it seems, that this sensor outputs only zeros for "non-hit" state and ones for "hit state". And I need something that can output levels of vibration, not only presence/abscense.
So is there any high-resolution vibration sensor for arduino?
Thank you!

The search term you are looking for is: "Accelerometer".  A common one is the ADXL345

Using the sensor, you can write the software that checks the amount of on's per second, effectively giving you the frequency of the vibration.

But are you looking to get the amplitude? (Intensity of the vibration)

Sounds like a dedicated Arduino would be necessary to gather this information and process it, then send it to another for the ultimate utilization.

I assume the OP wants the frequency of the vibration, which an accelerometer such as the ADXL345 won't give.
I have two workarounds: if the expected vibration frequency is low, say, under 100Hz, use instead an on/off vibration sensor (adafruit has them for under a dollar) and count the number of transitions. If it's more, how about a microphone and a band-pass filter?

That would seem to require that the Arduino has nothing else to do but count pulses.  Maybe one could do that part of the job then feed the results to another.

The MPU-6050 is a very low-price 3 axis gyroscope and accelerometer with both SPI and I2C interface options.
I found mine here:  https://smile.amazon.com/gp/product/B00KKR9ORI

EDIT:  Removed statement that it is accurate enough for this, based on comment.

The MPU-6050 is horrible for detecting vibrating motion. It is so innacurate! This module shouldn't be used for the purpose of the person's project.

Message received.  Thank you for handling this as a comment.  I added an edit to this effect.


text:
Custom Bootloader on Atmega328p - PU - 28 pin DIP
I am experimenting with low-power wireless arduino modules. For that, I needed 3V powered arduino so that I can do away with voltage regulators which eat up a lot of battery juice.
I am using 28 pin Atmega328p-PU dip IC with 8 MHz external crystal oscillator. Just for trying, I dumped the arduino pro mini 3.3V 8 MHz bootloader into it and it was a success. Everything is working as expected. However, I realized that SMD package which is being used in pro mini has 8 ADC pins compared to 6 in the DIP version.
Should I be worried about it?
Second feasible option is modifying the Arduino UNO board definition to use 8 MHz clock source as compared to 16 MHz and leave everything else same. Do you think this will serve my purpose?

The Atmega328p has 8 analog inputs. Some packages (such as the DIP) don't have enough pins to bring all of them out, but they are in there. The SMD package brings all of them out, but it apparently the Pro Mini does not pick up two of them. The net result is the same - 6 useable and 2 unusable analog inputs.

At least the sparkfun Pro Mini has plated-thru holes for A4-A5-A6-A7. Some clones don't have A6-A7, and some have them located near the reset switch

Then, I suppose there shouldn't be a problem with pro mini bootloader on 28 DIP. Thanks for solving the mystery. :)


text:
How do I scroll through the LCD vertically with joystick?
I have a device I'm working on and the only issue I'm running into is I can't manage to figure out how to get my LCD display to move around vertically with the joystick I have attached to it. I have a feeling with a tip this could be a very simple fix, but I'm just stuck. So the brief of this is that I need someone to fill in the ???'s for me provided in my example code.
//Include the LCD Library.
#include <LiquidCrystal.h>
#include <Wire.h>
//Declare the LCD object and define pins.
#include <MFRC522.h>
#include <SPI.h>

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define SAD 10
#define RST 5

//Ignore The below line it is for the master code
#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {

//Booting the LCD
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home
  lcd.cursor();

//Starting settings
  lcd.begin(1,0);
  lcd.clear();

}

//Sometimes you have to hit reset on the device

//Joystick Defaults X=484 Y=513

void loop() {
  lcd.setCursor(0,0);
  lcd.print("Example");
  delay(100);

for (int positionCounter = 0; positionCounter = 1; positionCounter++) {
if(analogRead(1) > 584) {
  lcd.scrollDisplayLeft();
  delay(30);
  } else if(analogRead(1) < 384) {
    lcd.scrollDisplayRight();
    delay(30);
  } else if(analogRead(0) < 413) {
     lcd.???????????????????();
     delay(30);
  } else if(analogRead(0) > 613) {
     lcd.??????????????????();
     delay(30);
    }
  }
}

The LCD library provides easy functions that activate commands in the LCD itself.  The LCD doesn't have functions that do what you want, so there is no simple vertical scrolling like you're suggesting.
If you need to have it, you'll need to re-write the screen with the content you want to display when the user scrolls around. I can't make any specific suggestions as I don't know the reason you need to scroll around the display this way, but one comprehensive method would be to create a buffer of data the LCD should be displaying, then scroll it using software (move the bytes around the way you want) and then send that buffer to the LCD when it changes.
There may be other more applicable or easier tricks, but that would largely depend on your specific use case and user interface design.

Thanks a bunch, I'm  pretty new to ardiuno, but I guess that makes sense I'll definetly keep it in mind, My LCD was dumping a large amount of data to the screen and it was dumping it line after line so I just wanted to be able to scroll through all the data.. I'm good for now tho I put a "band-aid" on the problem


text:
Comparing orientation data obtained using gyroscope and accelerometer
Recently, I have been playing around with a gyroscope and accelerometer in the hopes of building a quadcopter. I have plotted some of the data the two sensors and I am noticing that the pitch from the accelerator lags significantly behind the gyroscopic pitch.
From some research, I understand that these two are not going to equivalent values due to the mechanisms of measurement, however is it common to have such large discrepancies (i.e a difference of 20 degrees or higher) between the two sensors or is this an issue with my conversion?
I have listed the graph and source code here. Any help would be appreciated!
Sincerely,
Anand

Normally the values from gyroscope will drift overtime. It is natural and depends on the parameters of your code. It could drift a few degrees per seconds and the data will be far way from the accelerometer in a few seconds.
I have seen that you have applied the complementary filter, so you don't need to worry about the single value from the gyros since you combine them with the acceleromter and everything seems fine.
The gyros are good for short time response, in long time response the values get pretty bad as they drift a lot.
On the other hand, accelerometers are good for long time response, since short time response is noisy because of gravitational influence.
That's why you need a filter to combine them.
Wrapping up, it is normal to have this behavior in gyros. If you want to know more about the effect behind this sensor, try this reading.


text:
Reading data from airspeed v3 eagle tree
I am trying to get values from this sensor Airspeed v3 from eagle tree but it seems my I2C is not working properly.
I bought a module in third party mode and followed these instructions from the manufacturer website.
I went to rcgroups forum and discovered the right values for the bits mentioned in the documentation about WRITE and READ.
I started the development of a code but I cannot get the values from the sensor. It is supposed to send me a 2 byte-formatted value indicating the airspeed measured. But surprisingly when I call this method Wire.requestFrom(AIRSPEED_ADDRESS, 2) it returns 0, so someway the communication is not working. I have used I2C before for ADXL345 sensor and it works perfectly.
The results from these lines
Serial.println(data[0]);
Serial.println(data[1]);

are just -1 indicating that no data is available to display.
Does anybody know how to get this working? Am I missing something?
This is my code right now.
#include <Wire.h>

#define AIRSPEED_ADDRESS  0xEA
#define WRITE_BIT         0x00
#define READ_BIT          0x01

void setup() {
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Program started");
}

void loop() {
  byte data[2] = {0};
  int i = 0;
  int16_t velocidade = 0;

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(WRITE_BIT)) {
    Serial.println("error sending write_bit");
  }
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(0x07)) {
    Serial.println("error sending 0x07");
  }
  Wire.endTransmission(false);

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  if (!Wire.write(READ_BIT)) {
    Serial.println("error sending read_bit");
  }
  else {
    //Serial.println("ok sending read_bit");
  }
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Serial.print("bytes read from slave: ");
  Serial.println(  Wire.requestFrom(AIRSPEED_ADDRESS, 2) );
  data[0] = Wire.read();
  data[1] = Wire.read();
  Wire.endTransmission();

  velocidade = data[1] | (data[0] << 8);
  Serial.println(data[0]);
  Serial.println(data[1]);
  Serial.println(" ");

}

This is really helpful. Thank you very much!

That's interesting but after using a different library the code worked out.
It has to follow exactly what the datasheet says in order to get things done.
The following source code makes it and get the airspeed from the sensor:
#define SENSOR_ADDRESS 0xEA
#include <Wire.h>
#include <I2cMaster.h>
TwiMaster AIRSPEED_SENSOR(true);

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

long airspeed_update(void) {
  static struct {
    union { int16_t val; uint8_t raw[2];
    } airspeed16;
  } airspeedv3;

  long airsp;

  if(AIRSPEED_SENSOR.start(SENSOR_ADDRESS | I2C_WRITE)) {
    delay(10);
    AIRSPEED_SENSOR.write(0x07);
    delay(10);
    AIRSPEED_SENSOR.stop();
  }

  if(AIRSPEED_SENSOR.restart(SENSOR_ADDRESS | I2C_READ)) {
    delay(10);
    airspeedv3.airspeed16.raw[0]=AIRSPEED_SENSOR.read(false);
    delay(10);
    airspeedv3.airspeed16.raw[1]=AIRSPEED_SENSOR.read(true);
    delay(10);
    AIRSPEED_SENSOR.stop();
  }

  airsp=airspeedv3.airspeed16.val;
  return airsp;
}

void loop() {
  int airspeed = airspeed_update(); Serial.println(airspeed);
  delay(50);
}

Get this library from here.

I found the I2C address on my Eagletree Airspeed V3 sensor to be 0x75 NOT 0xEA.
the following code adapted from first sample above works on my Nano:
/*
 * note that timming is critical - see delay (5)
 * and bps set to 115200
 * works ok, but clean up 5-19-2019 jaf
 */

#include <Wire.h>

#define AIRSPEED_ADDRESS  0x75
#define WRITE_BIT         0x00
#define READ_BIT          0x01

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Serial.println("Program started");
}

void loop() {
  byte data[2] = {0};
  int i = 0;

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(WRITE_BIT);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(0x07);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.write(READ_BIT);
  Wire.endTransmission();

  Wire.beginTransmission(AIRSPEED_ADDRESS);
  Wire.requestFrom(AIRSPEED_ADDRESS, 2);
  data[0] = Wire.read();
  Wire.endTransmission();

  Serial.println(data[0]);
  delay(5);
}