text:
How to build circuit to switch to other power source if primary source dies?
I would like to have a backup battery connected to a device that requires an uninterrupted power supply, like an Arduino or Raspberry Pi, so that if my primary power source (USB plug) gets pulled, the device will switch to being powered by the battery.
I need a solution that I can either build on a breadboard or buy for only a couple dollars. Does anyone know a solution? I'm assuming this is a common need and think I perhaps am not searching with the correct key words.
Edit:
I would like to add that I may also use 4AA batteries and a DC-DC step down module to produce 5V exactly to power a 5V device, so I'm looking for a solution that accepts 5V. Assume the device, let's say Raspberry Pi, takes 5V, the power supply is 5V, and the battery backup is 5V.

The edit says  “the power supply is 5V” ... does that refer to the 4 AA's with step-down to 5 V?  Or to a mains-connected power supply?

@jwpat7 5V is the rating of both the mains power (USB cable) as well as the DC-DC step down from the batteries

Your $2 budget rules out some of the more-effective possible solutions, such as using an actual UPS (uninterruptible power supply) system.
One affordable approach is to connect the plus side of a 3.7 V lithium-polymer battery through a Schottky diode [such as MBR0520, SS14, 1N5819] to the +5 V line of an Arduino board.  (I haven't looked at Raspberry Pi schematics and don't know if this will apply there.)  Hook the minus side of the battery to Arduino ground.
Ideally, the battery voltage less the voltage drop through the diode (say .4–.5 V) should be just less than the voltage that USB supplies.  Ie, just under 5 V if you have a 5 V board, or just under 3.3 V for a 3.3 V board.  Note, most 3.3 V Arduino systems are specified to run at 8 MHz rather than 16.  There's a good chance a 5 V Arduino running at 16 MHz would continue to run ok when powered by about 3.3 V, but it's out of spec.
If your battery voltage exceeds 5 V you won't be able to make the connection quite so directly.  Besides certain risks of damage (see eg Method #5 and Method #8 of 10 Ways to Destroy An Arduino) there will be the practical matter that the higher battery voltage will cause its power to be used preferentially to the USB power, thus discharging the battery so that it won't act as a backup.
Edit: The question-edit says the system uses 5 V, and seems to suggest the primary 5V power supply uses 4 AA batteries and a DCDC converter.
If the DCDC converter is a step-down buck converter it will go out of regulation when the input voltage from the four AA's goes below 5 V, which is 1.25 V per cell.
As you can see from the following graph, if the discharge rate of a typical alkaline cell is 100 mA, it still has about half its power left when its voltage goes below 1.25 V.  To fully use up the alkaline batteries, you could use a buck-boost converter or could test if your buck converter just passes the voltage on through, as opposed to shutting down when the input voltage is low.

(Note, the AA-battery discharge curves shown above and below are from the powerstream.com's “AA tests”  web page.)
For the backup battery, where you also want 5 V output, an economical possibility is use of four AA NiMH cells, with nominal voltage 1.2 V per cell. However, initial voltage officially can exceed 1.4 V per cell, giving 5.6 V total:

A Schottky diode in series will bring that down to say 5.2 V, an acceptable level for powering a 5 V system.  But if the primary supplies 5.0 V, the backup will end up discharging slightly until its output voltage goes below that of the primary.  If that's acceptable, fine.  Otherwise, you could use a diode like 1N4001, with 0.7 to 0.8 volts of drop at 0 to 150 mA output.  Instead of losing some backup power at first (due to higher backup than primary voltage) you will lose some at the end, due to backup voltage going too low slightly sooner. That won't be a problem, however, if you restore the primary supply and recharge the backups in time to prevent over-discharge damage to the backup batteries.

Thank you for the info. Please see my edit above. Does your suggestion still hold true?

@jake9115, see edit

Thanks for this thorough answer, it is truly helpful. May I ask a bit more of you, and request a circuit diagram or links for parts needed? Your solution sounds elegant and simple. However, other sources, such as here: http://raspberrypi.stackexchange.com/questions/1360/how-do-i-build-a-ups-like-battery-backup-system, suggest much more difficult and complex designs. Are there any obvious deficits with the simpler design you offer here?

Those designs are more complex because they include charging circuits for the backup batteries, and most of them use bigger-than-AA batteries, eg sealed AGM lead/acid batteries as are used in ordinary UPSs.  Because the R.Pi's typical current draw is on the order of 300 mA, vs say 30 mA for an Arduino, the circuit I suggested is only suitable for supporting an R.Pi through brief outages of its main supply (eg five to ten minutes).


text:
RF24 tranceivers: trouble with two way communication
I am using RF24 modules with my two Arduinos Leonardo with the RF24 library. My goal is to be able to press a button on the first Arduino which will light up an LED on the second Arduino, and be able to press a button on the second Arduino to light up an LED on the first Arduino. I was easily able to figure this out as a one-way transmission with the first Arduino only transmitting and the second only receiving, but I am unable to make it a two-way transmission, where each Arduino can transmit and receive at the same time.
This is my code so far:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
const uint64_t pipe2 = 0xF0F0F0F0AA;
void setup(void){
  Serial.begin(57600);
  pinMode(A0, INPUT);
  radio.begin();
  radio.openWritingPipe(pipe);
  radio.openReadingPipe(1,pipe2);
}

void loop(void){
  int charToSend[1];
  charToSend[0] = digitalRead(A0);
  if (!radio.write(charToSend,1)) {Serial.println('didn\'t send');}
  radio.startListening();
  if (radio.available()){
    bool done = false;
    done = radio.read(msg, 1);
    Serial.println(msg[0]);
    digitalWrite(13, msg[0]);
  }
  radio.stopListening();
  radio.powerDown();
  delay(10);
  radio.powerUp();
}

But the radio.write() is returning false and therefore not sending.

Please update your library to github.com/TMRh20/RF24. That way you'll get a faster and more stable library.

The main thing that I can see wrong with your sketch is that the logic of your methodology is backwards.
You are spending most of your time either with the radio asleep, or not in listening mode, so it can not receive anything.
Instead you need to spend all your time in listening mode waiting for messages to arrive, and only when the button changes state do you want to switch off listening mode and send a packet to the other end. As soon as you have done that you then go back to listening.
You can't listen while the radio is powered down, so using powerDown() and powerUp() is just nonsense.

source: Stack Exchange

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

sort: votes


text:
Arduino ultrasonic distance meter doesn't display correct distance
The Arduino distance meter that I made doesn't display the correct distance. It just displays "0.0 inches".
Here's the code I used:
#include <LiquidCrystal.h>

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

int pingPin = 7;
int inPin = 6;
long duration, inches, cm;
int indec, cmdec;
int inchconv = 147;
int cmconv = 59;
String s1, s2;

void setup() {
  lcd.begin(16, 2);
  pinMode(pingPin, OUTPUT);
  pinMode(inPin, INPUT);
}

void loop()
{
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);

  duration = pulseIn(inPin, HIGH);

  inches = microsecondsToInches(duration);
  indec = (duration - inches * inchconv) * 10 / inchconv;
  cm = microsecondsToCentimeters(duration);
  cmdec = (duration - cm * cmconv) * 10 / cmconv;
  s1 = String(inches) + "." + String(indec) + "in" + "     ";
  s2 = String(cm) + "." + String(cmdec) + "cm" + "     ";
  lcd.setCursor(0, 0);
  lcd.print(s1);
  lcd.setCursor(0,1);
  lcd.print(s2);

  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds / inchconv;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / cmconv;
}

Here's the wiring diagram:

Might there be a problem in my code, or in my wiring?

Please provide more information. Like e.g. code and way you hooked it up.

I provided more informations

Tip for debugging this kind of thing: Print the raw values first to see if you are getting a valid ping, then if you are print each stage of the calculation until you find the failure.

please explain me it properly

Question: Does the variable duration contain a meaningful value?

Another question: Are you sure the ping sensor has power?

Do you have some basic tools like a DMM (digital (or analog) volt meter) or an oscilloscope?

Another piece of information that would be useful is to know the actual sensor that you're using.

Using Arduino and Ultrasonic sensor Find The Range and Display reading on LCD

To solve a problem like this you need to break it down into smaller pieces so that you can build up some confidence about what is working and what is not. When you share a problem like this as a question it helps if you can give us some idea of your experience level and of what you've already done to debug the problem – that helps with avoiding telling you what you already know and makes it easier to focus in on where the problem might be.
From what you've said it appears that you have things working well enough that you get a display on the LCD but it does not represent a meaningful distance.
Looking at your schematic the first thing that comes to my mind is that you have the ultrasonic sensor at the opposite end of the breadboard from the LCD. Many breadboards split their power rails at the middle. So start by confirming that you have power to the sensor.
After that, double-check the rest of your wiring.
The next step for me would be to confirm that I understood the sensor and to try and prove that it was working as I expected. Look for some sample code that is known to work (often the site you bought the sensor from will have links to beginning tutorials or code samples). Try that to see if the sensor works with the sample code.
If that doesn't work then check to see what you can do to prove the sensor is good (or bad). You might also contact the vendor to see if they can give you advice on proving that the sensor works.
Basically, break the problem down into "bite sized" chunks and work through it one step at a time, doing the simple stuff first. Try not to assume anything…

Maybe you should use the New Ping library and check if the sensor works without LCD:
https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

I think you should first check it in simulation and for that install Proteus software and get this Ultrasonic Sensor Library for Proteus and then test your code in simulation.
Once you confirmed that your code is working fine then you can come to the hardware debugging but I think its more probably because of programming issues.

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


text:
Programming a USB mouse connected to the Intel Edison Arduino expansion board
How can I programme a USB mouse connected to the standard USB port of the Intel Edison's Arduino expansion board?  I would like to measure the displacement of the mouse and also specify the frequency of image capture using the mouse's optical sensor.  I do not know much about programming so tutorials relating to my project would be very helpful.
Thanks

Here's a simple introduction to using the USB mouse as an input device. That might be a good starting point.
http://tahmidmc.blogspot.com/2015/12/using-input-device-on-embedded-linux.html


text:
I2C LCD displaying weird characters
I have connected an LCD with an I2C backpack to my Arduino Uno but it prints the wrong characters. The weird thing is that it worked fine for a while and when I updated the code (but didn't change anything to do with the LCD) it started displaying the wrong characters. This happened earlier today too. That time, reinstalling the LiquidCrystal library worked, but it doesn't now.
Does anyone know what might be the problem so I can fix it permanently?
The LCD's SDA and SCL are connected to A4 and A5 respectively and I'm running this code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16     chars and 2 line display

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
}

void loop()
{
    }

and this is what's displayed on the screen:

add a picture of your wiring please!

Is "LiquidCrystal_I2C lcd(0x27,20,4);" that right for this display? It looks like a 16X2 display. Please post a picture of the LCD adapter.

If you look up the ASCII codes for what you sent vs what was displayed, and also look at "Table 4 Correspondence between Character Codes and Character Patterns (ROM Code: A00)" in an HD44780U spec sheet, you will find hexadecimal values like the following.

e 65, V  56
l 6C, ニ C6
o 6F, θ  F2
o 6F, π  F7
r 72, &  26
d 64, B  24
and so forth.

It appears that the high nibble of what you sent is being used as the low nibble of what is displayed, and the low nibble is being used as the high, but with some bits sometimes going wrong.  Note, a space is 0x20, and the reverse of that is 0x02, which would access a character from the character-generator RAM, which will contain random bits and produce a random blob as in your picture.
If your mis-specification of display size (20, 4 vs 16, 2) isn't responsible for the problem, then maybe there is a hardware problem with the backpack you've soldered on to the LCD.  Look at it under a bright light, using a binocular parts-examination microscope if you've got one, and see if there are loose solder particles, extra solder flux, or loose solder connections on that board.  If you have an oscilloscope, check if your I2C signals are clean and have full swing.

I doubt the swapping of nibbles is due to a poor soldering. But +1 for wading through the datasheet to find the link.

Thank you very much @jwpat7 and @brianrho! Strangely, when I reconnected my lcd with this code just now, it randomly worked again. Anyway, I fixed the 20,4 to 16,2 just to be sure and if it starts acting up again I'll have a close look at the backpack.

Thanks, @WoutervanDijke, I had the same issue, just my problem was that I was printing in the loop() without setting cursor to 0,0 position, hence internal LCD memory got corrupted and it started to print random characters. I fixed the code, but it won't help, just after re-connecting 5V power pin,- LCD started to behave as normal. Hence power pin re-connect works as "factory reset" button for LCD. Cool ! You saved my life :-)

From what I can see, it seems, in this line:
    LiquidCrystal_I2C lcd(0x27,20,4);

wrong parameters have been passed to the constructor. The last two arguments are supposed to indicate the number of columns and rows on the screen. Your screen has 16 columns and 2 rows, whereas you passed 20 columns and 4 rows to the constructor. This could be the problem.

I experienced this while using a STM32f429 discovery board,  and I found out there are two reasons that this happens.

when using a fast microcontroller (180 MHz clock),  if you send I2C packet consecutive LCD may not be that fast to understand it and as James said in other post LCD may lose some packet and get confused. To cope with that you have to put a delay between your packet.
If you reset your MCU board while your LCD is writing something without cutting off power, LCD may get first nibble but lose the second 4bit nibble and interprets your initialize data as second nibble data to show on LCD and simply get confused. If LCD had something like software reset it could help but I did not find anything in datasheet. Though I think there is a hardware walkaround

if you could disconnect K in 8050 transistor and connect LCD Ground to that point then you could disconnect and connect LCD power just by toggle P3 pin through PCF8574 IC when you are initializing your LCD.actually you will lose some control over LCD backlight. you can consider R/W pin too because almost all firmware just write on LCD and simply lower this pin. I bring the purpose schematic in below

in Module simply disconnect ground pin from module and LCD and in LCD board connect K pin to ground as i put the image here

in your Code When you are Initializing write 0xF7 in I2C and Delay for 200 ms then write 0 for and delay 100 ms then do your other Initialization
 Sorry for bad English

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


text:
Observing USB Gamepad with Arduino?
I have a gamepad which I want to treat as a sensor for my Arduino board. I want Arduino to trigger a certain action based on button pushes from the gamepad. Different buttons, different actions.
The gamepad comes with a USB connector. I cut the the USB cable open, solder it with pluggable pins which are then connected to a breadboard. I supply the gamepad with 5V power from Arduino and connect the USB's Data+ to Arduino's analog input pin (A0). Please check the images below.
I thought by observing the voltage coming from the gamepad's Data+ pin, I can probably determine if a button is being pushed. However, the observable input voltage in Arduino's A0 do not produce any meaningful difference between button push and release.
My question: Is it possible to detect Gamepad's button pushes with this arrangement? If it's possible, where do you think I'm doing wrong?

simulate this circuit – Schematic created using CircuitLab

You arduino doesn't have USB host controller, so you can't. You have broken the gamepad for nothing..

Ok thanks for mentioning USB host controller, that's the lead that I need!

Adding a USB host controller to an Arduino is technically and economically silly.  You'd be better off with something like a kl25z which is cheaper, more capable, and has that built in.  Or you can gut the gamepad and replace the electronics.

Hm. What did you think would happen here? What did you expect to read from the pin?

... or buy a real SNES gamepad, which just uses a simple shift register if I'm not mistaken.

Yes, the real SNES or Megadrive gamepads are much easier to read.

How is a 20,- closed source KL25z dev board cheaper than a open hardware 2,- nano with 3,- usb host shield ???

As mentioned, the problem is the gamepad you have uses communicates over USB, which requires a USB Host chip to communicate with. However, USB Host shields can be found on eBay (under "arduino USB Host shield") from US$10, and they come with a USB socket, so you could use it easily with another gamepad that hadn't had the connector snipped. This also would allow use with HID devices such as mice and keyboards if you wished, so a worthwhile shield to own.

USB devices make a serial communication, a series of packets of bits are sent and received, which is not beyond your power to learn and talk with. Using a USB Host shield or a chip would be easier (and more costly), but doing it yourself will be much more fun and educational.
Surprisingly, for some USB devices (like a keyboard) you need to poll the data. Nothing will be sent to the host automatically. To find out the protocol they speak, you need to connect the game-pad to a PC and monitor the signals.
Also you need to monitor both D+ and D- signals, they are both used.
Here is a wonderful video by Ben Eater about the USB Keyboards where he goes deep into monitoring the signals and the protocol, can be a good start for your project:  https://www.youtube.com/watch?v=wdgULBpRoXk


text:
uint8_t etc as color variable
I am very new to coding and I am attempting to teach myself the best I can.  I have no prior knowledge of coding and am filling in the blanks via YouTube and forums alike.  One place I keep getting hung up on is what seems to be an unsigned integer.
I have tried to figure out how these work (assignment and such) to no avail. I was wondering if anyone could offer some insight for me or at the least a link that gets specific for the Arduino.
I see them used as uint8_t, uint16_t, and uint_32 in various places.  Am I correct that it is an unsigned integer?  Meaning it is a whole positive number only.
The code I have attached is from Adafruit's article on multi-tasking.  I am trying to adapt my sketch for millis() over delay().
      uint32_t Color1, Color2;  // What colors are in use
      uint16_t TotalSteps;  // total number of steps in the pattern
      uint16_t Index;  // current step within the pattern

For instance: on the variable declarations they use these for the color.  I will need to change the colors, but have only seen them expressed in RGB.  They are in every sketch I see, but I am struggling to answer this question on my own.  Thanks in advance for any help.

If you search for information about C types on the internet, there will be much help to find, but effectively you are correct. One format of integer types in C take the form:
uint / int: Signed or unsigned integer. Unsigned integers are stored in simple binary representation, and signed integers are stored in two's complement form.
8 / 16 / 32 / 64: The number of bits to store the value. This means the number of possible values is 2x where x is the number of bits.
_t: Simply a suffix to indicate that it is a type name, not a variable.

Colour storage
Colours are generally stored as three components: red, green and blue (or sometimes four, adding alpha, the degree of transparency).
If each component is given an unsigned byte to be stored (so it has a value from 0–255), then the total colour size is 24 bits. However, 24 bit integers are not a standard size, so the next bigger size is selected, 32-bit. This also allows room for an alpha component if necessary, but otherwise the spare 8 bits are unused.
For example:
| 00000000 | 00000000 | 00000000 | 00000000  | = 32 bits
| red      | green    | blue     |alpha/empty|

Thank you so much for this. The breakdown helps to simplify it for me.

Everything about standard integer types is in <stdint.h>


text:
I'm pretty sure I fried my Arduino Uno. Given my setup, what caused it to be fried? (I can't identify the short)
I was trying to drive a Nema 17 stepper motor using an arduino uno and an A4988 driver. I had it wired up according to this instructable (http://www.instructables.com/id/Drive-a-Stepper-Motor-with-an-Arduino-and-a-A4988-/) at step 2 without the motor power supply wired to the bread board yet. ALSO, I hadn't wired the sleep to reset yet (I just didn't read directions carefully). The board was connected to my computer via USB and I had uploaded the sketch on the instructable to it.
Then, because I misunderstood the directions, I plugged my 12V 8A power supply into the power input on the arduino. All of the sudden, my computer turned off. My computer is fine after restarting, but now the arduino isn't recognized at all by the computer when I plug it in.
Given this information, I am pretty sure that my arduino is fried. However, I can't understand why plugging in the power supply to the power input, which has a voltage regulator, would cause the board to fry.

That's an odd problem. If you power the arduino from a 9V/12V power supply to the jack on the board, with no USB connected, test the arduino chip and the voltage regulator with your finger; do they get hot to the touch? That's the best indication that one has fried.

When I look at picture 2 of step 2, there is a connection Vin of the Arduino to the motor power. On the picture 3 this is missing. How was your cabling?

Are you absolutely sure you used the RAW pin and not the VCC pin?

Do any other usb devices work?

I had tested other devices and know that neither my computer nor the cord are the issue.

The board doesn't get hot when I plug it in now, BUT it was hot right after the incident. Like I said, I'm pretty sure its fried, I'm just trying to figure out why so I don't do it again.

@ott-- Interesing, I did not have anything wired to vin.

@PandaLion98 does the arduino uno even have a RAW pin? (sorry if its obvious or something; I am new to arduino)

@Jere82 Oh, sorry. It's labeled VIN on an UNO. On Pro Minis, it's labeled RAW.

@Jere82 Where exactly did you connect your "12V 8A power supply"? The Arduino has a lot of power inputs.

Please specify the datasheet for the stepper motor.

@PandaLion98 I connected it through the barrel plug connector, which to me seems like no problem because of the voltage regulator. Is it possible I got a crappy board with a bad voltage regulator?

The Uno is not one "thing" that fails. It has various components, some of which may have failed. I wrote a lengthy page about how to test various parts:
Have I bricked my Arduino Uno? Problems with uploading to board

I plugged my 12V 8A power supply into the power input on the arduino.

Perhaps you reversed the leads, and shorted the USB power to ground, thus causing the PC to turn off? This would probably also blow most of the components on the Uno because they would have had -12V applied to them, assuming it got past the voltage regulator.
However there is a reverse polarity protection diode on the power input jack. Did you use that or the Vin pin? (or the Vcc pin?)
Note that the reverse polarity protection does not protect you if you use the Vin pin.

Thanks for the info page. What do you mean by reversing the leads? I used the 2.1 mm center-positive barrel plug connector on the arduino so wouldn't that be impossible? Also, I didn't have anything wired to the vcc pin, and the Vcc pin was wired to the input voltage on the stepper motor driver.

You said I plugged my 12V 8A power supply into the power input on the arduino. I assumed you had to make up a lead for a heavy-duty power supply, and might have got them the wrong way around.

I wonder if you destroyed your Arduino's voltage regulator.
If the Arduino was connected to the stepper motor via the A4988 when you powered the Arduino with a 12V supply, the stepper motor might have drawn current from the Arduino's regulator. This current is likely ~2As, which is far more than the tens of milliamps the Arduino is designed to output. This kind of current draw could quite possibly destroy the regulator on your Uno.
This could also explain why your computer restarted. USB ports on computers are designed to provide an output voltage to their USB devices, so if you provide a voltage on the USB power lines your computer is also driving, you can short your ports if the two voltages are not exactly the same. This is actually why USB cables have the A vs B end design - they mark which side should supply power (A), and which should be powered (B). The Arduino might have provided a voltage on the USB cable's 5V line and thus shorted something in your computer that provides the voltage for your USB ports (I believe Unos are not designed to be powered by both USB and the 12V connectors simultaneously).
If the regulator fried on your Uno, you might have had a voltage that was way off of the expected 5v on the USB port. A well designed USB port will usually try protect itself in a situation like this, often causing the computer to shutdown or the USB bus to deactivate until restarting the computer.
You could check your Uno's voltage regulator with a multimeter or better yet and oscilloscope to see if that is in fact the problem. If so, you could solder a new one on pretty cheaply and quickly. However, there is no guarantee nothing else got fried, in which case buying a new $10-20 Uno looks like a pretty appealing option.


text:
Problems using an arduino with vex motors and motor controller 29
I am using a VEX 2-wire motor with the Motor Controller 29 to use it like a three-wire motor.
I was told that I am able to program it like a servo using the Arduino Servo class. When I use the write() function to set the power, it works from values around 50-85 in one direction, slowing down the power as I increase the value, but when the value exceeds around 90 then the motor stops working and makes strange clicking sounds. It is not a hardware problem, because the motor works fine in either direction when I plug it straight into a power source.
Does anyone know what my problem is?

What power supply are you using to power the motor? Those VEX motors have a stall current of at least 3A, so you'll want to be providing a fair bit of power to the motor controller.

I'm using the 5V pin that is built-in to the arduino.

and what is that powered by? USB will not be enough power, and the voltage regulator on board cannot cope with that much current. You should be powering the motor from at least a 2A 5V power supply, and you can power the arduino from it via the 5V pin if you wish.

I'm using a 9V battery to power the Arduino.

VEX motors with Servo library have the following functionality:
0 one direction (full speed)
90 stop
180 opposite direction (full speed)
So at 90, it is trying to remain motionless and hence creating that sound.
btw. You should provide power to motors separately from the Arduino. You might fry your Arduino if you run VEX motors from it. Best solution is to power using 7.2V 3000mAh Flat NiMH High Power Battery Packs.


text:
What happens when there's no space left on SD card?
I'm coding a data logger and I would like to know what happens if there are no bytes remaining to be written using SD library, ie, if the SD card is full of data. The logging would just stop or I would get some nasty error?

Unless you list your code no one can say.

Open-source is just great. Lets have a look at the source code for SD. Here is what happens on write of a block.
/**
 * Write data to an open file.
 *
 * \note Data is moved to the cache but may not be written to the
 * storage device until sync() is called.
 *
 * \param[in] buf Pointer to the location of the data to be written.
 *
 * \param[in] nbyte Number of bytes to write.
 *
 * \return For success write() returns the number of bytes written, always
 * \a nbyte.  If an error occurs, write() returns -1.  Possible errors
 * include write() is called before a file has been opened, write is called
 * for a read-only file, device is full, a corrupt file system or an I/O error.
 *
 */

The source code shows that blocks are allocated from the free list and if there are no more blocks the function will return an error.

There doesn't seem to be any definite answer in the library documentation, but I am fairly certain that writes will simply fail, and not cause any sort of corruption. The last log entry may be incomplete, but the file should still be readable.

Any of us can speculate in that manner about what might happen, and come up with an answer like that that's hardly worthwhile.  I suggest that if you don't know the answer and don't have evidence one way or another, then don't put what you have to say in an "Answer" but instead in a comment, if at all.   ¶ To answer a question like this, either examine the library code itself (rather than its documentation) or run an experiment (eg, declare a big file, seek to near its end, write some bytes, repeat until fail, ie until write() < bytecount)


text:
How to hook up an LED strip to an Arduino
I want to add 6 LEDs  under my Arduino case and have the Arduino Uno pulsate the colors. How do I do this?

What have you tried so far? Which part of your code is not working? Can you post your code and a schematic? Thanks.

i dont have a code or schematic that is my problem

https://learn.adafruit.com/rgb-led-strips/usage

Depends on what they are and how much you don't know :-)
I'd suggest starting off by looking at the tutorials for NeoPixels and DotStars on Adafruit's site – that should give you a general idea of how things work. Then take a look at the FastLED library, it supports a large number of LED strips and has some decent examples.
The FastLED examples that will show up in the Arduino IDE after you have installed the library.
Once you've gotten as far as identifying the strip you have and reading some of the basic tutorials and trying out some of the examples you'll either know how to do it or have some much more specific questions to ask.
OK, after looking at the info on Amazon and looking more closely at the strip (and the price). I don't think these are individually addressable LEDs. More likely the RGB lines are grounds. So what you would do is to provide a +12V supply on the 12V line and ground one or more the RGB lines to turn on that LED. You could probably control brightness with PWM (pulse width modulation, turning them on and off quickly). The catch here is that the current draw will be more than the Arduino can sink and it's at 12V – two quick ways to kill your board in one tidy package.
You'll need to do more research on this to get the details right, but I think you could use a transistor to do the switching (to protect your Arduino for the 12 V and from the current necessary to drive the LEDs). You would connect an Arduino pin to the base of the transistor to control it. You'd need to select a transistor that can handle the current of all of the LEDs of that color. As a guess I'd figure 60 mA per LED at full brightness (for each color) – this is based on NeoPixels running at 5 V so I could be way off.
If I'm right that these are not individually addressable then the programming would be relatively easy – just turn on the output to turn on the color.
I'd start off by cutting off a strip of the LEDs to experiment with. Use the 12V supply that came with them and see what happens when you connect 12 V to the 12V line and ground one of the color lines. It doesn't look like there is a resistor to limit current, so you should add one to hold the current down. I think the LEDs would be wired in parallel, so you'd be looking at needing to supply 6 times the individual LED current. To be safe you could start at around 20 mA and use a 100Ω 1W resistor – you can find an LED resistor calculator here, be sure to select the parallel calculation and use a low current to start with to be safe.
Once you know that the strip works the way you think it does, try adding a transistor to control each color. Then when you've got that working, hook up to the Arduino. Just remember that you will also need to respect the Arduino's current and voltage limits on the digital pins.

what do you mean identifying the strip?

http://www.amazon.com/gp/product/B00MA397GI?psc=1&redirect=true&ref_=oh_aui_detailpage_o06_s00

@laxus There are two ways to control your strip. a) You somehow make the Arduino behave as the controller or b) You send the Infrared commands with your arduino to emulate the remote.


text:
How fast is an Arduino?
Can an Arduino Uno calculate the time that an assembly instruction will take in nanoseconds, not microseconds? I don't want to use a PC, because the calculation will be more accurate using an Arduino, as the processor won't be running other tasks.
If the Arduino can't, is there any way to improve it, or any other open source hardware that can do?

Hardware timers might help

I just want to know how much time (in nanosecond example: 14 microsecond and 145 nanosecond ) it'll take for a CMP instruction comparing 2 strings, because in theory it will take less time if the two strings doesn't match.

You can set up a hardware timer (eg. Timer 1) with a prescaler of one, so that each "tick" counts one clock cycle. Thus it can time to a resolution of 62.5 ns if running at 16 MHz.
Then you could read the timer, do your target instruction (eg. compare two strings) and then read the timer again. The difference in counts will be the time (in units of 62.5 ns).
I have a page about timers which might help you get started.

... calculate the time that an assembly instruction will take ...

Generally speaking the C++ compiler does a good job of generating code. You won't necessarily make things faster by writing in assembler and you might make it slower, because compiler-writers know various tricks which you might not.

How fast is an Arduino?

Arduino Uno is based on AVR MCU and run at 16 MHz. Due to the processor architecture it can execute almost 1 instruction per clock cycles (62.5 ns). It uses a simple two step pipeline which may require restart if a branch is taken. There are some instructions such as memory access that take more than one clock cycle.

Can an Arduino Uno calculate the time that an assembly instruction will take in nanoseconds, not microseconds?

It is possible to measure the execution time with a resolution of 4 us with micros(). Please describe what you want to calculate/measure.
For more details on ATmega328p please see the data-sheet, chap. 6.6 Instruction Execution Timing.

i just want to know how much time (in nanosecond example: 14 microsecond and 145 nanosecond ) it'll take for a CMP instruction comparing 2 strings, because in theory it will take less time if the two strings doesn't match.
thank you

Could you provide a list of some functions that you would like to know the execution time for? With the assemble listing for the functions (written in C/C++ I assume), the number of clock cycles per instruction, and the clock frequency it is possible to calculate the execution time accurately given specific parameters e.g. to explicit strings.

Here are some benchmarks that might help answer your question(s): http://www.nongnu.org/avr-libc/user-manual/benchmarks.html

If you're asking "can an AVR measure how long it works on a task" then the answer is yes, but I don't think that's what you're looking for.
If you're asking "can I craft a program that takes a specific amount of time to run" then the answer is also yes. The trick is to look in the datasheet or in the AVR Assembly Instruction manual to see how long each instruction takes in cycles and then multiply that by the MCU's clock period.


text:
Generate 2 PWM signals Vc and Vh from Arduino Uno
I want to generate two PWM signals VC and VH to give input to the gas sensor  with the duty cycle mentioned below. I also want to take the reading from the same sensor at the same time using Arduino Uno.
[
I am confused how to proceed with the code in Arduino Uno.

I'd not use PWM for this. It's a pretty slow PWM signal, and you probably need to synchronize the measurement with the PWM signal. Just toggle the pins and add a delay. It would be helpful if you specified the part nr.

I cannot use the delay and toggle the pin because that will be running in a loop function and i want to perform some other function too in that loop function. And as far as i know, it will execute other statement only if it has completed the pulse generation. I have found this technique in Arduino site   and it mentions that it has a second disadvantage - you can't leave the output running while the processor does something else.

I don't understand what you are saying? All you need to do is turn on the heater, wait a bit, turn on the sensor, wait a bit, read the sensor, turn off the sensor, wait a bit, turn of the heater, do whatever calculation needs to be done in the remaining 236ms, and repeat. What is it exactly? Something like a TGS2442 CO sensor?

Thank you Gerben.  Its TGS2444 ammonia sensor. But this is not what i want to do. I want to use the delay in reading my value, e.g. every 1 sec , etc. As i need to store the value for my future reference and analyse it. I don't want to store value after every 250ms. Along with this i will be using other sensors too like VOC's.

236ms is a lot of time to store an read other sensors.

Let me try. If it works i will inform you. Thank you.

You can use the millis() function to see how much time has passed and use this to create your waveform while still being able to perform other tasks. You will check in which part of the wave you are in each iteration of loop() and adjust your outputs accordingly.
E.g:
long vhtime;
uint8_t vhpin = 9;   // the VH output pin
uint8_t vcpin = 10;  // the VC output pin

long period = 250;   // the period of your pwm signal in ms
long vhduty = 14;    // amount of ms vh should be high
long vcdelay = 2;    // amount of ms we wait for vc to go high after vh has gone high
long vcduty = 5;     // amount of ms vc should be high

long curtime;        // this will hold our current position in one period of the waveform

void setup() {
  pinMode(vhpin, OUT);
  pinMode(vcpin, OUT);
  digitalWrite(vcpin, LOW);
  digitalWrite(vhpin, HIGH);
  vhtime = millis();
}

void loop() {
  curtime = millis() - vhtime;
  if (curtime > vhduty)        // we are in the last 236ms of the wave, vh should be low
    digitalWrite(vhpin, LOW);
  else                         // we are in the first 14ms of the wave, vh should be high
    digitalWrite(vhpin, HIGH);
  if (curtime > vcdelay && curtime < vcduty + vcdelay) // vc should be high during this time
    digitalWrite(vcpin, HIGH);
  else
    digitalWrite(vcpin, LOW);
  if (curtime > period) {
    // we should start a new period
    digitalWrite(vhpin, HIGH);
    vhtime = millis();
  }
  // do your other calculations here
}


text:
Suggestions for a program for drawing simple schematics
I'm wondering if there are free programs or web sites that let you draw simple schematics similar to this example:

https://www.circuitlab.com/ ; Fritzing ; Circuitmaker ; Eagle ; KiCad (kind of in order of complexity)

See Good tools for drawing schematics from our sister EE.SE site. It's a pretty complete list of software for drawing schematics.

While at it, see also Rules and guidelines for drawing good schematics, from the same source.

A compilation of possibilities mentioned the comments. I'll add to this as I try out the suggestions.
From @Gerben, "kind of in order of complexity":

circuitlab.com - online schematic capture and simulator (analog, digital, and mixed signal). Licensed for professional, student/educator, and hobbyist (free) usage. Officially runs in Chrome and Firefox, and they report users having success with Safari and Opera which are not officially supported.
Fritzing - cross-platform (Mac, Windows, Linux). Has Breadboard View mode with built in Arduino support that allows you to create diagrams like this one:

From there you can click on the Schematic view to route wires and convert the breadboard into a traditional schematic.
CircuitMaker - Windows only, requires creating an account.
Eagle - cross-platform (Mac, Windows, Linux), paid and free versions.
Component library collections (thanks to Marko Mackic for the idea):

Adafruit
Element14 Arduino library - requires registration, lots of other libraries as well
Sparkfun

KiCad - cross-platform (Mac, Linux (with packages for several distributions), Windows, and source code), open source and also on GitHub.

Found Autodesk's 123D Circuits in a question on Arduino Simulators (and emulators).

I've been using ExpressSCH (Express Schematic) from: http://www.expresspcb.com/
That is a free install for Windows and is pretty easy to use.
Example of its output:

It comes with quite a few symbols defined, and you can easily make your own extra ones (like the Uno I did in the schematic above).

Myself, I prefer to use Eagle, and download Sparkfun and Adafruit libraries for components based around Arduino. There you can create schematics, and create PCB layouts too.

There are many cicuit drawing softwares available on the internet.
Besides the softwares mentioned above, I would like to recommend EasyEDA editor.
It’s a free, web-based EDA suite, you can use it without installing anything.
Mac, Linux, Windows and Android,All platforms supported.
EasyEDA has simple but powerful drawing capabilities, it’s part library is quite massive and there is plenty of parts to pick from. Users can create their own symbols and footprints either by copying existing ones into My Parts then editing and saving them or by drawing them from scratch.
For example, here is a simple 555 circuit.


text:
Arduino Uno R3 (with Atmega 16u2) and MAC OSX 10.11 (El capitan) not working
I have Chinese copy of arduino which uses ATmega16u2 (at least that's what is written on the chip itself). When connected, it is visible in system information under USB section:

Communication Device:
Product ID:   0x0043
  Vendor ID:    0x2341
  Version:  0.01
  Serial Number:    75237333636351600270
  Speed:    Up to 12 Mb/sec
  Manufacturer: Arduino (www.arduino.cc)
  Location ID:  0x1a140000 / 6
  Current Available (mA):   1000
  Current Required (mA):    100
  Extra Operating Current (mA): 0
  Built-In: Yes

But it doesn't show up in arduino program ports.
I've searched a lot, and it seems that people mostly had problems with arduinos on CH340 chips. I also have one such arduino, but it works properly after installing signed drivers as described here.
Are there any solutions for atmega 16u2 chips?
My system:

OS X El Capitan 10.11.2 (15C50) (hackintosh if it changes anything).
Arduino Uno R3 (chinese copy)
Arduino soft version 1.6.7

Additional info:
I've tried connecting Arduino Mega 2560 with Atmega16u2 chip and it also doesn't work
Info I've got using Nick's awesome program:
Atmega chip detector.
Written by Nick Gammon.
Version 1.17
Compiled on Jan  8 2016 at 21:35:08 with Arduino IDE 10607.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x94 0x89
Processor = ATmega16U2
Flash memory size = 16384 bytes.
LFuse = 0xFF
HFuse = 0xD9
EFuse = 0xF4
Lock byte = 0xFF
Clock calibration = 0x56
Bootloader in use: No
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 4096 bytes starting at 3000

Bootloader:

3000: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
3010: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
3020: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
...

MD5 sum of bootloader = 0x6A 0xE5 0x9E 0x64 0x85 0x03 0x77 0xEE 0x54 0x70 0xC8 0x54 0x76 0x15 0x51 0xEA
No bootloader (all 0xFF)

First 256 bytes of program memory:

0: 0x90 0xC0 0x00 0x00 0xA9 0xC0 0x00 0x00 0xA7 0xC0 0x00 0x00 0xA5 0xC0 0x00 0x00
10: 0xA3 0xC0 0x00 0x00 0xA1 0xC0 0x00 0x00 0x9F 0xC0 0x00 0x00 0x9D 0xC0 0x00 0x00
20: 0x9B 0xC0 0x00 0x00 0x99 0xC0 0x00 0x00 0x97 0xC0 0x00 0x00 0x48 0xC4 0x00 0x00
30: 0x0C 0xC4 0x00 0x00 0x91 0xC0 0x00 0x00 0x8F 0xC0 0x00 0x00 0x8D 0xC0 0x00 0x00
40: 0x8B 0xC0 0x00 0x00 0x89 0xC0 0x00 0x00 0x87 0xC0 0x00 0x00 0x85 0xC0 0x00 0x00
50: 0x83 0xC0 0x00 0x00 0x81 0xC0 0x00 0x00 0x7F 0xC0 0x00 0x00 0x02 0xC1 0x00 0x00
60: 0x7B 0xC0 0x00 0x00 0x79 0xC0 0x00 0x00 0x77 0xC0 0x00 0x00 0x75 0xC0 0x00 0x00
70: 0x73 0xC0 0x00 0x00 0x71 0xC0 0x00 0x00 0x6F 0xC0 0x00 0x00 0x6D 0xC0 0x00 0x00
80: 0x6B 0xC0 0x00 0x00 0x69 0xC0 0x00 0x00 0x67 0xC0 0x00 0x00 0x65 0xC0 0x00 0x00
90: 0x63 0xC0 0x00 0x00 0x61 0xC0 0x00 0x00 0x12 0x01 0x10 0x01 0x02 0x00 0x00 0x08
A0: 0x41 0x23 0x43 0x00 0x01 0x00 0x01 0x02 0xDC 0x01 0x09 0x02 0x3E 0x00 0x02 0x01
B0: 0x00 0xC0 0x32 0x09 0x04 0x00 0x00 0x01 0x02 0x02 0x01 0x00 0x05 0x24 0x00 0x01
C0: 0x10 0x04 0x24 0x02 0x06 0x05 0x24 0x06 0x00 0x01 0x07 0x05 0x82 0x03 0x08 0x00
D0: 0xFF 0x09 0x04 0x01 0x00 0x02 0x0A 0x00 0x00 0x00 0x07 0x05 0x04 0x02 0x40 0x00
E0: 0x01 0x07 0x05 0x83 0x02 0x40 0x00 0x01 0x04 0x03 0x09 0x04 0x32 0x03 0x41 0x00
F0: 0x72 0x00 0x64 0x00 0x75 0x00 0x69 0x00 0x6E 0x00 0x6F 0x00 0x20 0x00 0x28 0x00

Programming mode off.

Fuses info:
Atmega fuse calculator.
Written by Nick Gammon.
Version 1.10
Compiled on Jan  8 2016 at 22:19:34 with Arduino IDE 10607.
Attempting to enter programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x94 0x89
Processor = ATmega16U2
Flash memory size = 16384
LFuse = 0xFF
HFuse = 0xD9
EFuse = 0xF4
Lock byte = 0xFF
Clock calibration = 0x56
Hardare Boot Enable..................... [X]
Debug Wire Enable....................... [ ]
External Reset Disable.................. [ ]
Enable Serial (ICSP) Programming........ [X]
Watchdog Timer Always On................ [ ]
Preserve EEPROM through chip erase...... [ ]
Boot into bootloader.................... [ ]
Divide clock by 8....................... [ ]
Clock output............................ [ ]
Bootloader size: 4096 bytes.
Start-up time: SUT0: [ ]  SUT1: [ ] (see datasheet)
Clock source: low-power crystal.
Brownout detection at: 3.0V.

Do any other USB devices appear on this machine? Have you tried either Arduino on another machine (unlikely that both are faulty, but...) Do the Arduinos also fail to show up in the /dev/ directory?

Yep, USB is working fine. At the moment, I'm developing with another arduino, that has CH340 usb chip, which works great. Device is not appearing in /dev: ls tty.* tty.Bluetooth-Incoming-Port tty.serial1

The CH340 has a custom driver, while the ATmega16u2 runs off the standard USB stack. It's possible that this is an incompatibility with your hackintosh, so it would be interesting if you could try this on a genuine Mac. (I'm not sure whether an Apple store or dealer would permit you to plug an Arduino into their store Macs, but it can't hurt to ask).

@microtherion I'm working with arduino on my macbook, but it has yosemite, yet, and I'm afraid to update it, because then I will not have the possibility to program my arduinos. PS. It worked on this same hackintosh until it was using yosemite (with chimera), now I installed el capitan (and switched to clover) and this is when problems started :(

After two months I finally found a solution. The problem was with USB drivers for my hackintosh. Few days ago new Multibeast 8.1 was released with new USB drivers. After installing El Capitan 10.11.4 update and then installing USB drivers from Multibeast my Arduinos magically starter working again!

You can use my Chip detector sketch to confirm (using another Arduino to run the sketch) if the target chip is a Atmega16u2 or not, and if so, what fuses etc. are set.
Wiring would be like this:

Close-up:

ICSP header (from above):

You should see something like this:
Atmega chip detector.
Written by Nick Gammon.
Version 1.17
Compiled on Jan  3 2016 at 07:34:08 with Arduino IDE 10605.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x94 0x89
Processor = ATmega16U2
Flash memory size = 16384 bytes.
LFuse = 0xEF
HFuse = 0xD9
EFuse = 0xF4
Lock byte = 0xCF
Clock calibration = 0x96
Bootloader in use: No
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 4096 bytes starting at 3000

Bootloader:

3000: 0x4B 0xC0 0x00 0x00 0x64 0xC0 0x00 0x00 0x62 0xC0 0x00 0x00 0x60 0xC0 0x00 0x00
3010: 0x5E 0xC0 0x00 0x00 0x5C 0xC0 0x00 0x00 0x5A 0xC0 0x00 0x00 0x58 0xC0 0x00 0x00
3020: 0x56 0xC0 0x00 0x00 0x54 0xC0 0x00 0x00 0x52 0xC0 0x00 0x00 0xEE 0xC4 0x00 0x00

...

MD5 sum of bootloader = 0xD8 0x8C 0x70 0x6D 0xFE 0x1F 0xDC 0x38 0x82 0x1E 0xCE 0xAE 0x23 0xB2 0xE6 0xE7
Bootloader name: Arduino-dfu-usbserial-atmega16u2-Uno-Rev3

First 256 bytes of program memory:

0: 0x90 0xC0 0x00 0x00 0xA9 0xC0 0x00 0x00 0xA7 0xC0 0x00 0x00 0xA5 0xC0 0x00 0x00
10: 0xA3 0xC0 0x00 0x00 0xA1 0xC0 0x00 0x00 0x9F 0xC0 0x00 0x00 0x9D 0xC0 0x00 0x00
20: 0x9B 0xC0 0x00 0x00 0x99 0xC0 0x00 0x00 0x97 0xC0 0x00 0x00 0x48 0xC4 0x00 0x00
30: 0x0C 0xC4 0x00 0x00 0x91 0xC0 0x00 0x00 0x8F 0xC0 0x00 0x00 0x8D 0xC0 0x00 0x00
40: 0x8B 0xC0 0x00 0x00 0x89 0xC0 0x00 0x00 0x87 0xC0 0x00 0x00 0x85 0xC0 0x00 0x00
50: 0x83 0xC0 0x00 0x00 0x81 0xC0 0x00 0x00 0x7F 0xC0 0x00 0x00 0x02 0xC1 0x00 0x00
60: 0x7B 0xC0 0x00 0x00 0x79 0xC0 0x00 0x00 0x77 0xC0 0x00 0x00 0x75 0xC0 0x00 0x00
70: 0x73 0xC0 0x00 0x00 0x71 0xC0 0x00 0x00 0x6F 0xC0 0x00 0x00 0x6D 0xC0 0x00 0x00
80: 0x6B 0xC0 0x00 0x00 0x69 0xC0 0x00 0x00 0x67 0xC0 0x00 0x00 0x65 0xC0 0x00 0x00
90: 0x63 0xC0 0x00 0x00 0x61 0xC0 0x00 0x00 0x12 0x01 0x10 0x01 0x02 0x00 0x00 0x08
A0: 0x41 0x23 0x43 0x00 0x01 0x00 0x01 0x02 0xDC 0x01 0x09 0x02 0x3E 0x00 0x02 0x01
B0: 0x00 0xC0 0x32 0x09 0x04 0x00 0x00 0x01 0x02 0x02 0x01 0x00 0x05 0x24 0x00 0x01
C0: 0x10 0x04 0x24 0x02 0x06 0x05 0x24 0x06 0x00 0x01 0x07 0x05 0x82 0x03 0x08 0x00
D0: 0xFF 0x09 0x04 0x01 0x00 0x02 0x0A 0x00 0x00 0x00 0x07 0x05 0x04 0x02 0x40 0x00
E0: 0x01 0x07 0x05 0x83 0x02 0x40 0x00 0x01 0x04 0x03 0x09 0x04 0x32 0x03 0x41 0x00
F0: 0x72 0x00 0x64 0x00 0x75 0x00 0x69 0x00 0x6E 0x00 0x6F 0x00 0x20 0x00 0x28 0x00

Programming mode off.

On my genuine Uno I get these settings from OS/X:
  Product ID:   0x0043
  Vendor ID:    0x2341
  Version:   0.01
  Serial Number:    74134373733351300000
  Speed:    Up to 12 Mb/sec
  Manufacturer: Arduino (www.arduino.cc)
  Location ID:  0xfd130000 / 8
  Current Available (mA):   500
  Current Required (mA):    100

I haven't had any problems using the Uno with OS/X however I don't remember whether or not I had to install a device driver for it.

Info I've got using Nick's awesome program:

...
Signature = 0x1E 0x94 0x89
Processor = ATmega16U2
Flash memory size = 16384 bytes.
LFuse = 0xFF
HFuse = 0xD9
EFuse = 0xF4
...
Bootloader:

3000: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
....

MD5 sum of bootloader = 0x6A 0xE5 0x9E 0x64 0x85 0x03 0x77 0xEE 0x54 0x70 0xC8 0x54 0x76 0x15 0x51 0xEA
No bootloader (all 0xFF)

It is interesting that they are shipping without a bootloader on the ATmega16U2. Whilst that chip doesn't need one (and it is disabled by the fuses in mine) clearly there are some differences. I checked the "first 256 bytes" of the code between your board and mine and they are the same, so possibly the main code is identical.
I would try to plug your Arduino into another Mac, if possible. It may be that your "hackintosh" has enough differences in its loaded software that it doesn't recognize that USB interface.

Thanks for the answer. I have checked your link, and as far as I understood, if I'll connect it like shown on the pictures, I'll get info about Atmega328p chip. How should I connect it to get info from the chip for working with usb (Atmega16u2)? PS. On older Mac OS X versions, it worked flawlessly and without any drivers,

See images in amended reply.

I've made a cable today, and here is what I found out: the chip is ATmega16U2, but it's configured slightly different. Here is what I got. Maybe You can say something from the log? I've added in my question.

See amended reply.

It works on my macbook, but it's using Yosemite (10.10), and not El capitan. And now I can't upgrade it, because if the problem is in El capitan, then I'll be left without the possibility to program my arduinos :(

There is complete documentation on Arduino website, I followed the steps and I was able to install driver
https://support.arduino.cc/hc/en-us/articles/4408887452434-Flash-USB-to-serial-firmware-in-DFU-mode

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.


text:
Interfacing Gammon's RS485 with computer
I'm using the non-blocking RS485 Gammon's library for Arduino (as shown at http://www.gammon.com.au/forum/?id=11428) to handle the communication between some arduinos.
Now I'm having trouble to add a Raspberry Pi (or otherwise a non-arduino platform) to the network.
How can I integrate the Gammon's protocol in a python or processing software?

Surely the Pi supports the C++ language?

Open-source and Web-search is just great. This might be what you are looking for.
Cheers!


text:
Decision maker loop problem
Today, I've started a decision maker, using a Arduino UNO R3, a button and a RGB led.
This project makes a decision for you (yes, no, or maybe) when you don't know your own decision about something.
The code I used in the project is the following one (written by me):
#define out OUTPUT
#define in INPUT
#define H HIGH
#define L LOW

int red = 2;
int green = 3;
int blue = 4;

int randomValue = 0;

int button = 5;
int buttonState = 0;

void setup(){
    pinMode(red, out);
    pinMode(green, out);
    pinMode(blue, out);

    pinMode(button, in);
}

void loop(){
    buttonState = digitalRead(button);
    if(buttonState == H){
        randomValue = random(0,4);
        if(randomValue == 1){
            digitalWrite(red, H);
            delay(200);
            digitalWrite(red, L);
            clear();
        }
        if(randomValue == 2){
            digitalWrite(green, H);
            delay(200);
            digitalWrite(green, L);
            clear();
        }
        if(randomValue == 3) {
            digitalWrite(blue, H);
            delay(200);
            digitalWrite(blue, L);
            clear();
        }

    }
}

The connections are correct, and the code also. The problem is: when I push the button, the LED starts showing random colors, and what I want is for the LED to show one color per push.
What can I do?

There is one basic concept that you are lacking.  At the moment you are looking to see if the button is pressed, not when the button has been pressed.
Instead of just looking to see if it is HIGH you need to look if it was LOW but is now HIGH. It's that transition from LOW to HIGH that you need to use as your trigger for when to set the LED colour, and that means remembering the state of the button the last time you went through the loop.
buttonState = digitalRead(button);
if (buttonState != oldButtonState) {
    oldButtonState = buttonState;
    if(buttonState == H) {
        // Do your stuff
    }
}

oldButtonState is defined the same as buttonState.

oldButtonState is a new variable?

Of course. What else could it be?

You may also need to debounce the button – if you still see multiple changes before the decision is finalized :-) Unless, of course, you consider a bit of dithering to be a good thing…


text:
Low Cost Motorized Valve
I'm looking for a low cost motorized water valve.  I've done a number of searches and have found nothing compelling.  Has anyone here used a motorized water valve with Arduino?  What would you recommend?
A fail-open solenoid might also work but I'd like to try my hand at a motorized valve.
The valves I found start at US$50.  I'm looking for something cheaper.  The purpose is tinkering and I'd like to make an "if water detected - then close valve" sketch.  Ir's simple, just more expensive than I expected.

This is not Arduino-specific. You may find Robotics Stackexchange useful for this question.  More-specific questions are more answerable.

It would help if you could describe what you didn't like about the valves that you found – that would help folks trying to answer understand more about what you want. Specifying what you mean by low cost and what the valve needs to manage (type of liquid, size, operation speed) would also make for better answers.

You can get sprinkler valves, that use solenoids, for under $20 that fit on plastic PVC pipe and are designed for water, such as these at SprinklerWarehouse.  They typically use pipe sizes of about 1 inch.

Right, but I'm looking for a motorized valve or a fail-open solenoid.  I think the lawn stuff is fail-closed.


text:
android app to control arduino using usb
I am trying to figure out how i could make an android app like this one, https://www.youtube.com/watch?v=cVj0jqOlGXo but instead of transmitting through bluetooth it would transmit it through a usb cable that plugs from my phone directly into my arduino.

There are no "good" answers for this, but two classes of possibilities - USB host mode, and "accessory" or "ADK" mode.  Both have a number of issues.  Both have received substantial coverage on the main stackoverflow site which you should read (do not simply post a new question there) and elsewhere online.

I think you may want to look USB Serial port communication in android. Some googling will help
 here's a nice example of such work, described in detail:
http://felhr85.net/2015/01/09/a-dirty-and-quick-example-of-serial-port-communication-in-android/
And in case the codes/that source gets lost, here is the
GitHub link of the developer: https://github.com/felHR85/SerialPortExample


text:
Access denied when Uploading
I went to upload my sketch to my Uno (r3), but unusually, the Upload Console returned this error:
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.

Just started seeing this, cannot upload.

I had Ultimaker Cura open, this seemed to be hogging the com ports. Make sure your other apps aren't using them.

I can confirm here that for me it was also Ultimaker Cura. Once closed, COM port was free again. I think it's worth a try, if all the other things look ok (i.e. checking the device manager).

There might be another device has already connected to that port. It could even be a terminal emulator which is left connected from last debugging session.
Otherwise, make sure that your UNO is really presented on COM4 by checking with "Device Manager". if not, change the port where it is available.

Mine was locked down by Cura - a program that will (among other things) control 3D printers via serial. Closing it fixed the problem

@Chris thanks a lot, same problem

Yes - be careful Cura seems to do this.

same thing here with Cura, that is way wrong I don't even have a 3d printer plugged in so .. I'm going into Slic3r then

In my case, I simply forgot to close "Serial Monitor" window for another Arduino sketch, and that was it.

I'm using a windows 10 and had this happen randomly. I closed several other applications and it started working again.

How did you find out what other applications are using this port?

I guessed. I was using my USB drive for some other things and just started closing stuff.

Worked for me by just closing File Explorer and Cura not sure which one was the problem.

You have selected the wrong COM port. Go to Tools -> Port -> Select the right port. If you do not know the port number disconnect the Arduino, open the same menu again and look what is listed there, write down if you can't remember, now plug your Arduino back in and select the option that wasn't there before.


text:
In UART, what mechanism sets the "new data received" flag back to 0?
I was reading documentation on UART on AVR and it looks simple: when a flag (bit RXC0 of register UCSR0A) is set to 1, it means the micro controller has new data for you, and you read this from register UDR0.
But something boggles my mind: How does the micro controller know that we have read the data? Or, in other words, after it received the first byte on UART, the flag is set to 1, but when is it set back to 0?

can someone explain the -1 ?

I'm not sure I understand it either. He indicates that he's been reading the documentation and is puzzled by it. The learning curve here gets steep very fast in places.

What you read is not the documentation, it is a simplified tutorial. Maybe take a look at the datasheet... I would imagine that the UDR0 register is hardwired, so that when it is read (and the "READ" line goes active) then the "latch" on the RXC0 flag is cleared (by the same "READ" line going active). Have a look at some UART design documents, and/or "State Machines".

The ATmega328p data-sheet describes the setting of RXCn:
Bit 7 – RXCn: USART Receive Complete

This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXCn bit will become zero. The RXCn Flag can be used to generate a Receive Complete interrupt (see description of the RXCIEn bit).

The hardware seems to keep a register the size of the receive buffer. Incremented when received and decremented when read. It is only one level so the size is 0..1, i.e. one bit.
Actually there is two registers; one for possible incoming data and one for the latest data until read.
Cheers!
More details in ATmega328p data-sheet, chap. 19 USART0

So the micro controller actually tracks all myvariable = UDR0 or f(UDR0) ?! this doesn't seem uncanny ?

It is the implementation of reading UDR0 that is "special". There is no special instruction or tracking by the compiler. The hardware does this. Think of it as a hidden bit parallel with the data register.


text:
How does the PID controller actually work?
Preferably PID functions on an Arduino uno or any other examples. I have been researching but many of the the websites really do not explain it.
P.S is there an algorithm for a PID? Thanks

Wikipedia explains it perfectly. Maybe the problem is that you don't understand the explanation?

@Majenko, Hmm, I'd say if people aren't understanding it perhaps the Wikipedia explanation isn't "perfect." Also, quite a few sites don't really explain the terms and what each one does (e.g., how you'd think about or tune a PID controller).

When you're asking questions about subjects you're not understanding it really helps if you can say what you've learned in your research and focus the question on the next part you'd like to understand.

https://controls.engin.umich.edu/wiki/index.php/PIDIntro

http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ is an excellent explanation of the http://playground.arduino.cc/Code/PIDLibrary

http://ninja-calc.mbedded.ninja/tool/pid-tuner - You can play around with a online PID simulator and see how changing the P, I and D terms affects the response.

I, also, didn't get the idea behind PID from just reading Wikipedia. After some videos/tutorials, I believe the best way to explain it is:
What is PID
PID is an algorithm. It involves three factors which can be adjusted to tune a signal.
It is often used in servo's (and things like thermostates, basic signal controllers)
Imagine this
The servo will be used in the practical examples.
A servo has:
- a current position (signal)
- the position you want the servo to be in (goal signal)
- a speed (PID output signal)
The PID output signal/algorithm makes sure that the servo reaches it's goal.
In short:
PID is an algorithm that can adjust a signal towards an setpoint. Or correct it for that matter.
It regulates how much you have to adjust the signal, without getting serious overshoot, or oscillation around the setpoint.
Detail:
P stands for proportional.
Which means that the further the servo is from it's setpoint, the more speed we want to/can give it. So that we're faster towards the set point.
This also means that we slow down as we near the set point.
Of course you can multiply each of these rules with a factor, to achieve a better balance.
I stands for integrating.
It basically comes down to the fact that it constantly keeps adding to the signal, depending on how long there is a difference between the current point and set point. This is so that if P is still a little slow, it adds some speed over time.
D stands for differentiating
It's less commonly used. (Wikipedia)
The D factor reacts on the speed of the change in value. Or speed of change in setpoint (Dutch wikipedia is not 100%, comment if neccesary :) )
These factors / the algorithm provides a smooth regulation of various systems, hence that's why it is so adjustable.
It can be used for balancing quadcopters or making your house comfortably warm (without sudden changes, or too slow changes)
Why?
How would you balance a quadcopter?
If it shifts to one side, you don't want to fully reverse the throttle.
It'll make it wobble, since you get a lot of overshoot.
Controlling things can be hard, PID is an known working algorithm for those cases. But you have to adjust the factors right to adjust it to your specific system. (They all react differently, or have to react differently).

+1, but stabilizing a quadcopter can't really be done with a single PID loop; it usually takes 2 cascading PID loops, one for rotational position and one for rotational velocity /Pedantry

@BrettAM Good point, I thought each axis could be controlled individually by a PID loop, but it might indeed make sense to couple them in some way.

You can use a single pid for each axis, roll, pitch, & yaw.  Velocity is handled by bias.  Eg https://github.com/benripley/Arduino-Quadcopter

How a PID controller works depends on the particular implementation.
There is a algorithm/library for PID on the Arduino: http://playground.arduino.cc/Code/PIDLibrary and an excellent explanation of the all of functions within it at http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
Over on stackoverflow and electronics, there are some good questions and explanations that might help:

https://electronics.stackexchange.com/questions/190606/understanding-a-pid-controller
https://stackoverflow.com/questions/14614124/how-do-i-use-a-pid-controller?rq=1
https://stackoverflow.com/questions/21516143/pid-control-value-of-process-parameter-based-on-pid-result?rq=1
https://stackoverflow.com/questions/13542447/i-dont-understand-integral-part-of-pid-controller?rq=1
https://stackoverflow.com/questions/21534996/pid-controller-intuition-for-when-error-0?rq=1


text:
Audio Visualizer (not working properly)
Parts

Arduino Uno R3 (Atmega328 - assembled)
Adafruit Bicolor LED Square Pixel Matrix with I2C
Backpack
Electret Microphone Amplifier - MAX4466 with Adjustable Gain
Half-size Breadboard
Breadboarding wires

Description
I have been following the build guide for the "Piccolo Music Visualizer" on the Adafruit website (https://learn.adafruit.com/piccolo?view=all), using all of the same components and code (following the guide exactly as shown). I first tested the 8x8 matrix to see if it was working properly, and it works beautifully. The problems started when I wired up the electret microphone...
In regard to how I wired this to the breadboard, I followed the example for the R3 on the Adafruit guide (since that's my current version):
Note
The files (code) used for this project are found here: (https://github.com/adafruit/piccolo). The ffft file is supposed to be saved to the library (this worked for me). The Piccolo file is supposed to be saved to the Sketchbook (this did not work for me - kept giving error messages when trying to reference it). I instead copied the code found in the Piccolo file, and saved it as a new sketchbook file. Let me know if this might be the cause of the problem. This is my first arduino project, so I am still trying to figure out how the IDE works.
Problem
The electret microphone is supposed to pick up audio and the LED matrix should display a waveform based on the loudness and frequency of the audio. Instead, I only have 2 bars on the bottom left lighting up (the effect is static - wont respond to volume or frequency changes). Oddly, when pulling out the microphone from the breadboard, the waveform begins displaying as it should, but in a glitchy/unstable form. I figured the problem was with the adjustable gain on the microphone, but no matter how much I adjust the screw only the 2 bars are affected and still static (when adjusted to the left only green LED, in middle is green and orange, to the right is red/orange/green on the matrix).
A little confused as to what the problem could be... is the microphone broken, code malfunctioning, wiring incorrect, etc.
Pictures to reference (DropBox link):
- See comment below for link (must have 10 rep to use more than 2 links in post)
(zip file contains 3 pictures: "wiring", "when_on", "pulling_out_mic")
Photos are over 2MB so I couldnt upload here.

DropBox: https://www.dropbox.com/s/22uojp0w0u039kc/SE_Arduino_Problem.zip?dl=0

Check your soldering on the microphone board header pins; sounds like a dry joint.

@CharlieHanson How would I fix a dry joint? I don't see any problems with the soldering, but I could be wrong.

Just add more solder; the more the merrier. The fact that the LED matrix seems to work 'better' when you're fiddling with the microphone board makes me think that the problem lies entirely with that little board.

@CharlieHanson You were right, it works perfectly now! Thanks so much! Post your comment as an answer and I'll accept it.

It sounds like a dry joint; the fact that the LED matrix seems to work 'better' when you're fiddling with the microphone board makes me think that the problem lies entirely with that little board.
Try adding more solder; the more the merrier.


text:
Can I use a GPS from old Garmin with an Arduino?
I'm working on an Arduino project, and I'd like to add GPS functionality. I could buy a GPS module, but those are expensive. I had an old Garmin Forerunner 305 lying around, so I took it apart and took a peek inside. There are two PCBs - one connected to a screen and one to the GPS. In addition, there was a battery and a small part for charging.
I'd like to know if it is possible to connect this GPS to my Arduino, and if so, how?
Edited:
To make my question more precise,
-I see the pins in the top right of the picture. How do I connect those to my Arduino? Is there any specific kind of wire? Because the pins are too small for standard wires.
-Once I connect it, how do I figure out the voltage requirements and pin layout? I tried googling the  GPS model, but nothing helpful came up. What kind of scope should I put on it?
The two pictures below show only the GPS part of the inside of the watch.

http://www.instructables.com/id/Connecting-GPS-module-to-Arduino/ this could be the exact thing you want.

Yes, unless it is a gps that requires software to function, this is probably not one of those.  Also you have to deal with voltage levels, 1.8, 3.3, 5.0 and match that to your arduino.  ideally put a scope on this one while running to see what the pinout is, or find markings on it (remove the antenna if possible) and search for that.

It may be easier to use a lo price "GPS Dongle".

Cheap GPS modules are only ~10USD; nicer ones are <100USD. You are likely to spend more than 100USD worth of time trying to reverse-engineer that thing.

But reverse engineering it could be fun…

The short answer is NO, unless you have solid experience with microelectronics.
Finding documentation for a module you take out of a commercial device is hard to impossible. Chances are, that module is specific to Garmin, and even if it isn't, it's certainly EOL by now, with no support whatsoever.
Even if you do find the spec, there is a high chance that you'll have to write a software library to support it on Arduino. Don't expect the supplier to share the code they gave to Garmin.
Finally, to put together and debug this project, you will need quite some equipment:

oscilloscope to debug the electrical interface
soldering station to solder small pins properly

Like people said in comments, this equipment alone will cost much more than a brand-new GPS receiver.

Yes, interfacing with arduino, PC, ESP8266, whatever, easy peasy.  Simple to breakout the serial comms off the Garmin, and whether or not you want to use a logic level shifter (Depending on your RS-232 logic requirements), easy too implement.
I've got a whole bunch of old Garmins (and some new ones) interfaced with some cheapy ESP8266's so I can share the GPS output (All of it.  Not just the x,y,z position data), with multiple devices.
I'd be willing to share the code, wiring if you wish.


text:
Using Arduino Uno as ISP to program Mega 2560
I'm trying to use Arduino Uno as ISP to program Arduino Mega 2560 using this Pin connections (Uno->Mega):
slave reset: 10:       ->        RESET on target
MOSI:        11:      ->           51
MISO:        12:      ->         50
SCK:         13:      ->        52
It runs perfectly when I "Burn Bootloader" from Arduino IDE and LED starts blinking on target. So I assume my pin connections are correct.
However, when I open the Blink example and perform "Upload Using Programmer" in Sketch tab after choosing "Arduino as ISP" in Tools>Programmer it uploads the code but LED on Mega doesn't blink.
I'm afraid that I have problem in my Mega Bootloader hex file and think it's not configuring Pin 13 as a LED pin. But in this case I shouldn't have seen the led blinking after burning the bootloader.
What am I missing here? I appreciate your help.
-Bex

The problem may be related to reset. See http://arduino.stackexchange.com/a/19131/3879

No, I checked the connections and they look fine. I set the RESET pin as D13 in Arduino Uno and don't think it's wrong. Also defined the RESET pin as D13 in the ArduinoISP Example.

When you "upload using programmer" the target board's bootloader is not involved, and I believe it actually gets removed by doing that.

Find the file called "boards.txt" located in your Arduino installation directory. In my case, the path is "arduino-1.6.5/hardware/arduino/avr/boards.txt". Open it with your favourite text editor and locate the ATMEGA2560 section. (not in notepad, it breaks the file format, notepad++ my choice)
in boards.txt

back-up the file incase you break it,
find the line :
mega.menu.cpu.atmega2560.bootloader.high_fuses=0xD8
and change it with :
mega.menu.cpu.atmega2560.bootloader.high_fuses=0xD9

Source : http://soc.ninja/documentation/programming-atmega2560-with-arduino-uno-or-mega/#rating-74


text:
How to send data from ThingSpeak to ESP-8266 (Arduino) using ThingHTTP?
I have made an Arduino kit that acts as a weather station. It sends sensors data (DHT11 & LDR) to the ThingSpeak web server.
Now I want to perform some actions based on the data on the ThingSpeak server (like if temperature exceeds a limit turn on the fan, etc).
I've searched and I found that there's a React app on ThingSpeak, which will trigger events if data exceeds some values.
The problem where I got stuck is that I want to send a signal from the ThingSpeak web server to my ESP8266 (Arduino) to turn on/off the device connected to a relay on Arduino.
I've figured out that there's also a ThingHTTP feature which sends HTTP requests. But I don't know how to send requests/signals to my kit to perform some actions.
I've already spent 2 months building this project, and now I'm stuck in the last part. Please give your valuable suggestions and solutions.

Why do you think you need to bounce the value via ThingSpeak when the Arduino already knows what is going on, since it has send those values to ThingSpeak in the first place?

You raised a valid point! Yes we can burn such code which will perform action according to the sending values but It'll be considered as hard coding and will result into more problems !! Because we've 110 nodes (Arduino kits) and suppose for some reason we've to change the threshold of temperature data for performing some relevant action, then we'll have to burn the modified code again to all the 110 kits. We are thinking to control all these devices from 1 place ( web app). Thanks for your response. Looking forward for your suggestion.

That makes perfect sense.

For sending information to/from Arduino best option is MQTT. It's lightweight and very simple to use.
While your Arduinos are using MQTT to send info and receive commands (like changing thresholds), your Web server has access to the same information in real time. You can format it and present it in any way you like, without any Arduino participation.


text:
Sending 5 Led pixel values to arduino , is this a good way?
I wanted to install a 5 LED strip underneath my PC's front panel. I want to send color over PC so it can change when i open different apps, with temperature or etc!
So all I think the best way to do this is to just use Arduino to set the LED Values!
But I have had some troubles creating a good communication protocol for this, I've been just simply sending 45 digits (15 3 digit numbers) to my Arduino with serial. here's code:
Arduino :
#include "Adafruit_NeoPixel.h"
#include "WS2812_Definitions.h"

#define PIN 4
#define LED_COUNT 5

struct pixel {
  int R = 0;
  int B = 0;
  int G = 0;
};

Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);

char count = 1;
int pixelNumber = 0;
struct pixel tempPixel;
//struct pixel Pixels[LED_COUNT];

void setup()
{
  Serial.begin(9600);
  Serial.println("Init");
  leds.begin();  // Call this to start up the LED strip.
  clearLEDs();   // This function, defined below, turns all LEDs off...
  leds.show();   // ...but the LEDs don't actually update until you call this.
}

void loop() {
  if(Serial.available() > 0) {
    if(count == 1) {
      tempPixel.R = PC_Receive();
    } else if (count == 2) {
      tempPixel.G = PC_Receive();
    } else if (count == 3) {
      tempPixel.B = PC_Receive();
      count = 0;

      setPixelColor(pixelNumber, tempPixel);
      Serial.println(pixelNumber);
      leds.show();
//      Pixels[pixelNumber] = tempPixel;
      if(++pixelNumber >= LED_COUNT) {
        pixelNumber = 0;
      }
    }
    count++;
  }

//  if(pixelNumber == 0) {
//    for(int i = 0; i < LED_COUNT; i++ ) {
//       setPixelColor(i, Pixels[i]);
//    }
//
//    leds.show();
//  }
}

void setPixelColor(int a, struct pixel P)
{
  leds.setPixelColor(a, P.R, P.G, P.B);
}

char PC_Receive() {
  int result = 0;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0') * 100;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0') * 10;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0');

  Serial.println(result);
  return result;
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
  for(int i = 0; i < LED_COUNT; i++) {
    leds.setPixelColor(i, red, green, blue);
  }
  leds.show();
 }

And here's PC's dirty code in python:
import serial
import time
import random

class Pixel:

    def __init__(self, R, G, B):
        self.R = R
        self.G = G
        self.B = B

def clearAll():
    for i in range(0,5):
        ser.write("000000000")

def sendPixel(pixels):
    for i in range(0,5):
        ser.write(str(pixels[i].R).zfill(3))
        ser.write(str(pixels[i].B).zfill(3))
        ser.write(str(pixels[i].G).zfill(3))

ser = serial.Serial('/dev/ttyACM2', 9600)

little = [0,0,0,0,0]

for i in range(0,5):
    little[i] = Pixel(0,255,50)
sendPixel(little)

time.sleep(0.5)
clearAll()

the problem is it isn't stable, i think i should just use an \n at end or send back OK or something to confirm it, but that would make it slow if i did it for each value! (and checking only once after all 5 leds are send would mean sending more values until i receive the ok and clearing and sending them again!)
Can you recommend me a better way?
Thanks!
EDIT: Just wanted to say! it's almost done! It does change color when i open chrome, and i think at 115200 baud rate it's fast enough to not notice a delay (although at 9600 i felt like it's slower then my (xxx/xxx/xxx....) protocol but it's better and works at 115200
i will add some basic functions to my python side and add a rainbow effect
I will also add GPU temperature and etc... it's not going to be really hard on linux but windows, im not sure :D

Please edit your question and include the Arduino's setup() function as well.  The code doesn't make sense when includes, variable declarations, and initialization code isn't shown.  That is not to say it will make sense when they are shown :), merely that without them it doesn't.

I don't think you need to worry about speed or data size from what you've described. Prioritise for ease of coding and reliability. Forget all the binary stuff. Send whole bytes. Start with a known sequence, and end with a known sequence of bytes and take advantage of the arduino's readBytesUntil function to find those start and end sequences. This avoids problems with the arduino getting out of sync and picking up the data stream partway through, causing lighting mayhem

I would recommend a similar solution as DaveX with a small modofication.
If you bitmask your LEDS, and leave room for a possible additional 3, you can mask any combination of them in the space of 00-FF. then you could send to the arduino a single string of 0xFFFFFFFF  FF(LED bitmask),FF(Red value), FF(Green Value), FF(Blue Value).
so
LED 1 {00000001 =01} all red {FF0000} would be 0x01FF0000
LED 2 and  4 {00001010 =0A} all green {00FF00} would be 0x0A00FF00
LED 5 and 1 {00010001 =11} all blue {0000FF} would be 0x110000FF
ALL LEDS off would be 0xFF000000
All LEDS onn full white would be 0xFFFFFFFF

my led's are barely going to be the same color, so is it still worth using this? I think sending them in a chunk (but still binarry to reduce the size) will be easier! but im not sure how to convert a hex string to integer in arduino side, also im not sure how i can turn a int into hex string in python but i guess that one will be easy!

AFAIK C++ treats all numeric values as binary to start with, so if you say that rgbRED=127 it's the same as saying rgbRED = 0x7F

Here is a file with some likely colors as well as an interactive RGB slider and LED picker so you can generate the values you would need.. https://marvinfrancois.com/19228.php

Thanks a lot! as I'm inexperienced with these kind of stuff it will take em a lot of time, and googling :) but i will try to do it :) thanks a lot!

btw, just wanted to say, it's underneath my pc pointed to gound, it's a 5 strip led which EACH led has 3 colors, so it can be 5 different colors

Not sure if you're using the neopixel library, but if it's a strip of addressable LEDs, that may make your coding easier. I updated the page I pointed you at with some example arduino code that will update with the values you set, both which led and what color.. you'll still need to write your own logic for when to actually update  and how you are getting your value in. I will work on it for a bit more to see if I can get it to decode the values the way I suggested, but I don't have an arduino with me so can't test the code..

I'd recommend adding digits to a digit register, setting the an R,B,G register with R,B,G and setting values of led a-e to the RBG registers when you get an a-e, ignoring whitespace, and clearing the register otherwise.  So:
 ser.write("xRBGabcde\n")  # clear all the LEDs
 ser.write("x127RBb")       # make led b half-purple, relying on prior state
 ser.write("x255Gc")        # make led c greenish-white


text:
Arduino Neopixel affecting IR receiver module
I have tried this on both an Arduino Uno and an Arduino Mega2560. my issue is as follows. Without a 150 LED string of addressable pixels attached, I can pretty consistently capture and read the input from an IR sensor connected at digital pin 2. Once I connect a addressable string of 150 LEDs at digital pin 3, it seems that I am no longer able to reliably read the input from the IR sensor. This seems to be more the case when the pattern I have running on the LED string is heavy, i.e., the majority of the pixels are lit, or the brightness is high. This project also includes a mic connected at analog 5 and aref. Additionally, I am using a 16×2 LCD Display & Keypad Shield connected at digital pins 4-9. Is there any reason that the voltage difference could screw with reading the IR input.

What are you using to power the LEDs? Have you tried enclosing all of the LEDS in something light-proof, like a cardboard box?

turned out I needed to switch to a hardware interrupt for the IR sensor on the more cycle-intensive routines. the short interval didn't allow for sufficient time to poll for incoming IR data.

Interesting! Maybe you could post an answer to your own question? So does taking that hardware interrupt affect the LEDs? The timing for the WS2812/B LEDs is quite tight, so I'd expect some visible effect when IR is being received.


text:
Multi-drop RS485 device control v1.0 - why is limit for "TIME_BETWEEN_MESSAGES "?
I am going to use Nick's rolling-master system library (http://www.gammon.com.au/forum/?id=11428) in my home project.
For first experiments and testing, I have:
- BAUD_RATE = 9600
- max adress = 2 (it means max 3 drops)
- 2 active drops with adress=0 and adress=1, 1 intentionally missing drop (simulation    of malfunction one of drops :-))
- TIME_BETWEEN_MESSAGES = 200000
- Packet length = 200 bytes
- Packet time = 208333 microseconds
- Timeout for no messages = 1633332 microseconds
- gap between messages = 200 ms (measured value by oscilloscope).
It work perfect.
I would like to increase the gap between the messages, but after I increased the constant "TIME_BETWEEN_MESSAGES"  from 200000 to 300000, then start bad communication  between the drops:
- TIME_BETWEEN_MESSAGES = 300000
- Packet length = 200 bytes
- Packet time = 208333 microseconds
- Timeout for no messages = 2033332 microseconds
- gap between messages = 2170 ms
Adress first started after reset (for example 1)  broadcasts, but nothing receives from other adress (for example 0), which started later.
Adress 0 receives all messages from adress 1 OK, but nothing transmits (subroutine "sendMessage ()" is never called).
After reseting of broacasting drop with adress  1, it works in reverse (addr 1 only receives, no broadcast, and addr 0 broadcasts).
Why is there limit for "TIME_BETWEEN_MESSAGES" value ? How to increase gap between messages ? For my purpose be enough gap 1 - 2 sec and so drops should have enough time for their own job.
Thanks for advice,
Vava
(Sorry for my English... :-)


text:
WiFi repeater using ESP8266
I have a ESP8266 and I wonder if it is possible to create a Wi-Fi signal repeater using this module.

I can create a network so that devices connect it.
I can connect to an existing network.

But I can not connect the network created with the network that I connected
Does anyone know how to do this? or you have any examples?

Even if that is possible, the speed will be very low.

You can't have a single ESP8266 be both an access point and a client, at least not using the exposed API (recall that the Arduino libaries do not implement much functionality themselves, all they do is call the underlying RTOS API).
Also, a signal repeater is not a radio-only device. It would have to understand the low-level 802.11* protocols and packet types so you don't end up with forwarding loops. You can't do it just by connecting a pair of 8266s back-to-back over SPI and blindly forward packets; there is a lot of networking code that would have to be written.


text:
Print string and integer LCD
How do I print a string and integer on an LCD? Here is what I have tried:
int number = 2;
int result = (number + number);
lcd.print(number, DEC + " plus " + number, DEC + " equals " + result, DEC);

And the result is an error.  When I try:
lcd.print(number + "look");

or
lcd.print("1234 " + number);

Then the result on the LCD is "34 ", as it deleted the first two numbers!
I want it to print:
1234 2
Please help!  Thanks!

The lcd.print() method takes a string or a number as an argument, but not both at once. Using the + operator for concatenation is not native to C strings. C strings are basically stored as pointers to the first character of the string. So when you tried lcd.print("1234 " + number) and got "34 ", what most likely happened is that you advanced the pointer, pointing to the first character of "1234 "(i.e. '1') by number (i.e. 2), thus making the pointer point to the 3rd character in the string and thus making lcd.print() display "34 ".
In order to print something that contains both strings and integers, the most straightforward way is to convert each piece to an Arduino string and then concatenate them, using the + operator like you did earlier.
    lcd.print(String("1234 ") + String(number));
    lcd.print(String(number) + String(" plus ") + String(number) + String(" equals ") + String(result));

These are some examples. You could also use create a sufficiently large char buffer and use sprintf() from stdio.h to build a string made up of integers and strings. Look up a textbook on C/C++ for more details.

I got the same problem and I printed the string and the integer on the same line by moving the cursor like this :
   lcd.setCursor(0, 0);    <----------Column 0 , Line 1
   lcd.print("This code failed");
   lcd.setCursor(0, 1);    <----------Column 0 , Line 2
   lcd.print("Error Code = ");
   lcd.setCursor(13, 1); <-change the cursor for the INT. Column 13 , Line 2
   lcd.print(int);

What happens if a first error code is, say, 1234, then another one is 57... the display would show "5734" right?

What is wrong with this:
lcd.print(number, DEC + " plus " + number, DEC + " equals " + result, DEC);

It is the number of parameters and the assumption that plus will concatenate string literals.
lcd.print("1234 " + number);

This gives "34 " when number is 2. Why? This is because that is the result of adding 2 to the string literal pointer, i.e. the string starting at the character "3". Please use separate print statements instead:
lcd.print("1234 ");
lcd.print(number);

Do not use String to concatenate strings. That is a waste of SRAM, processing and has a risk of heap fragmentation. Simply a bad idea in small scale embedded systems such as AVR.
To understand these errors you should go back and read about strings and string literals in C/C++ (compared to Java :).
Cheers!

int a=0;
float b=10.01;

char str[16];

sprintf(str,"a=%d, b=%.2f, c=%d", a, b, 2); // use sprintf() to compose the string str

lcd.print(str);

The output will be 'a=0, b=10.01, c=2'


text:
panstamp device signature is random
I Have 2panstamp. I can program the first but not the second with the arduino program.
When I upload the sketch (a simple blink) on the second, I got this

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x004e22
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

And if I retry, I got this.

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x81f014
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

The device signature is not the same anymore ...
I've changed the wire and re-open arduino program. But it don't change, the device signature change (often 0xE1E1E1). I've check the connection between the ATmega and the wire and everything is ok.
Is the Panstamp broken ? or should I do a kind of factory reset?

Is the Panstamp broken ?

Sounds like it. If one works, and the other does not, using the same wiring, it looks like you have a faulty one.

or should I do a kind of factory reset?

You can't really "factory reset" a chip like that. Possibly there is a problem with the fuses. You may be able to explore further here:
Have I bricked my Arduino Uno? Problems with uploading to board


text:
>> << and -> Syntax in arduino
I was trying to follow this tutorial and came across >>. What exactly does this do?

>> is right shift a value by a certain number of bits.
<< is left shift a value by a certain number of bits.
-> is accessing a member of a class or struct that is referenced by a pointer.
Right Shift and Left Shift
If you have a binary number 0b00010000 and right shift it two bits you get 0b00000100. The C notation for that is val >> 2.  The same for left shift - val << 2 would result in 0b01000000.
Pointers and members
Normally when you access a member of a class or struct you use ., such as Serial.println().  However it is possible to make a pointer to a class instance, and when you do you need to access the members with -> instead of . - such as mySerial->println().
This arrow notation serves as syntactic sugar: mySerial->println() is interpreted as (*mySerial).println(). The parentheses are necessary because the dereferencing operator * has a lower order of precedence compared to the dot . operator.


text:
Plug/socket between thermocouple wires and the amplifier
I am building a temperature monitoring system that has 24 thermocouples. Managing all the wires is a hassle, and I'd like to connect all 48 wires to a few plug and socket connectors. Maybe 6 of these lead wire harnesses from eBay (see below).
The point of this would be to allow me to quickly disconnect all the thermocouples from their amplifiers when I need reposition the arduino, and then reconnect them afterwards without tracking each individual cable.
I don't know if this will have a negative impact on the function of the thermocouples. Is it ok to have a 'joint' (i.e., the socket) in the thermocouple cables, or do they need to remain intact from the end all the way to the amplifier?
Alternatively, would having a few inches of regular copper wire inserted between the thermocouple wires and the amplifier be ok? That is, having two copper wires attached to the amplifier, joining 8 of these wires together in a socket, and attaching the plug to the actual thermocouple (alumel/chromel) wires? The thermocouple wires are several feet long.

I do not know the accuracy that you will require in your temperature measurements.
Your idea of using copper wire and connector sockets is reasonably ok as long as you are aware of the following :
Where you make a connection from thermocouple wire to copper, that creates another thermocouple in itself. This isn't a great problem since the temperature of the "undesired" thermocouple is likely to be at room temperature (constant?)
No matter what you do, you always end up with undesired thermocouples (example when you connect your thermocouple directly to your circuit board copper, darn it.)
Thermocouple Selection and use is a page you can go to for more information.  Especially the Cold junction compensation (CJC) section.
EDIT added : You should twist your extention leads together to reduce electrical noise from the environment. Twist each pair, do not twist the bundle all together.

Thanks Marla! The whole setup is in a greenhouse, and the temperature of the thermocouples (desired and undesired) will fluctuate from 0C (hopefully not lower, but it is -20C outside tonight) to +35C. I'll study the page you linked, it looks like exactly the info I needed.

On the linked page, the author uses words like "must use", strong language encouraging to use thermocouple wire for extensions.  But that merely reduces the number of unintended thermocouples.

I'd put the sockets upstream of the amplifiers, ie arduino---sockets---amps---TCs