text:
New UNO, BLINK not working
Finally got around to playing with my uno today for the first time. ( It's a branded sunfounder UNO R3)
First project. Simple blink. Using arduino 1.6.3, Windows 8.1 It is hooked up correctly.
void setup() {
   // initialize digital pin 13 as an output.
   pinMode(9, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
   digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(10000);              // wait for a second
   digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
   delay(10000);              // wait for a second
}

What I get is a fast blinking LED. I've tried multiple values and it doesn't change. No error on upload.
I've commented out everything except the digitalWrite(9, HIGH); and I get a fast blink.
I tried:
void loop() {
   digitalWrite(9, LOW);
   delay(5000);
   digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
}

And I get nothing, it doesn't even turn on.
Same if I remove the first digitalWrite();
So, I'm already a little lost here. I did a but of google searching tried adding a serial 9600 line, and a few other things. Nada.

For your second snippet, you will never be able to see a single blink, that's because a second delay(5000) misses, in the end of the main loop. If you have an oscilloscope, or anything that can measure a frequency, check if the embedded quartz beats at 16MHz

No oscilloscope, or anything else to check frequency.  This is my first attempt playing with hardware like this but even if it was at 16MHz wouldn't the blink speed still change?  I tried many different values in there and it never changed.

Do you have and LED (and resistor) connected to digital pin 9 or is it the on board LED (which is on digital pin 13) you are observing ?

I've tried pin 9 with resister and I've tried 13.  Same result with both.  Same fast blink that doesn't change no matter what delay value ( I've tried up to 100000).  I tried a previous version of the arduino IDE also. Same thing.

Have you corrected the code? You must change the pin state to LOW, then delay, HIGH and again a delay! Also, mind that the internal led is on pin 13!

@Spirine Corrected?  The original code is there, and yes I was changing to the correct pin.    There isn't much to this really its like 4 lines.  Should work.

What you've written in the second code (starting with void loop...) will never work: you put off the LED, then you wait 5 seconds, then you put on the LED, and the program goes to the beginning of the loop, which take circa 100 nanoseconds, you put off the LED, etc. So, if you're able to see a blink of a few nanoseconds, yes, your code will work.

That was only to test nothing else.  I'm just trying to get the original code to work.

Try a different sketch to check the internal timers are running ok e.g unsigned long time;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
}

Ok did that.  All I get is Time: 0 repeating over and over in the serial monitor. Also, did not seem to pause for a second.

Sunfounder thinks it's a bad board.  Probably going to return it and buy  a real arduino and not a clone.

it may just be the fuses aren't set correctly. You can correct this by using the IDE to 'Burn Bootloader' making sure the correct board (Uno in your case) is selected first. Double check the board labelling as I've found some supposed 'Uno' boards from eBay were in fact Duemilanove's

Ok, tried that.  Got a bunch of "Not in sync" errors.  Not sure if I did it right though.  Connected usb, chose the right board, then burn bootloader.  Think I'm just going to cut my losses and get a working board.

You can sometimes get round that problem by manually resetting the board (using the reset button) and releasing the reset button at the correct time whilst attempting to 'Burn Bootloader', can take a few goes to get the timing right. Failing that you can add a couple of components to temporarily disable the auto reset, which normally occurs when you upload a sketch. Use a 120 ohm resistance connected between the RESET pin of Arduino and +5 V, and a 10µF capacitor connected with the positive pole to the RESET of Arduino and negative to GND.

What should I be choosing under "programmer" when I'm doing this?  I just left it on the default of AVR ISP.

this is nonsense, you have initialized pin 9 as output and expecting pin 13 to do the job?

Defective board.  Thanks to @br1an for the milli idea.  New board in the way,  not a clone.

it's @Bra1n but you're welcome anyway

Sorry for the typo, thanks again for all the help.

Added as new answer because comments limit was reached
Doesn't really matter which programmer you set because in this instance you're not actually burning the bootloader just setting the fuses (to those already stored in boards.txt for the Uno) but 'Using Arduino as ISP' is the nearest to what you're doing


text:
Disassembling a RC car for a Arduino Robot
I am looking at making an Arduino robot car. I have a RC car( photos below). I was wondering if I could take the chassis of the car and modify it to make it Arduino controlled, if so how could I do that?(I have an Arduino UNO R3). I would like to make it into a wall avoiding robot. I have never soldered a thing in my life, and I don't own a soldering iron.

Depends what you want to do? But if you're good with soldering and electrics it should be easy... Tell us what you want your robot to do, and we will try to help..

Sometimes modifying something can be harder than starting from scratch. This is probably one of those cases, but it is over all not too difficult if you have the courage.
Start with a good example, like this robot.  It will give you an idea of what hardware you must add to your RC car and how to program the Arduino.

Someone has done exactly this, and written detailed instructions at http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/
Some remote control devices (usually not the really cheap ones, like the one shown here) will have a standard transmitter/receiver. See http://www.alibaba.com/product-detail/3-channel-radio-control-receiver-box_311659816.html for a picture of the receiver. If you can find this in your remote control device, you should be able to unplug it, and replace it with an Arduino. You will need the "Servo" library - see https://www.arduino.cc/en/reference/servo
You can probably get away without soldering - you will probably need to strip some wires, and you can use crocodile clips, and/or breadboard jumpers to connect everything up. It won't be pretty.
If you want to learn to solder (I know it's intimidating, but it's not so bad) I recommend that you find a local hackspace/makerspace, and find someone there - they will probably be more than happy to teach you. They probably have everything you need, be nice to them, and if you want them to continue, join up & pay regular subs. And take every opportunity to teach the skills you have to anyone else who asks for help.

source: Stack Exchange

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

sort: votes


text:
#ifdef / #include CPP issue
I'm developing a sketch which I need to run on an Uno (for debug) and a Gemma (as the target).  Adafruit has their own Wire library (TinyWireM) which I was planning on using on the Gemma.  Thus, I was trying to use #if's to automatically include the correct library for the given target board.  However, it appears that the TinyWireM include files is always included even if the AVR_ATtiny85  macro symbol is undefined (I get many undefined symbols reported inside the Arduino\libraries\TinyWireM-master\USI_TWI_Master.cpp file).  If I comment out the TinyWireM.h include statement (inside the #if define statement), then it compiles fine.  Code example below.
So why isn't this include statement being skipped?  I'm at a loss.  Anyone have any thoughts?
Thx all.
Mike
#undef __AVR_ATtiny85__        // Debug only - making sure not defined.

#if defined (__AVR_ATtiny85__)
  #include <TinyWireM.h>    // Seems this file is still being included and
                          // must comment out this line when compiling
                          // code for an UNO.  This should not be necessary
                          // given __AVR_ATtiny85__ is not defined.
#else
  #include <Wire.h>         // This is the Wire library for the Uno.
#endif

void setup() { }

void loop() { }

The problem isn't your code. There is a 2012 bug report on this issue in Google Code.
Once you start getting bitten by the non-standard behavior of the Arduino IDE, you've outgrown it and the only real remedy is to move up to real tools that work as you'd expect. A few of the choices include:

Eclipse is a good choice; it can take a little patience and searching to
get it set up right, but once you do it's a solid development
environment you can stay with for a long time. It runs everywhere  Java does.
Atmel Studio is well thought of. It's proprietary, not free [?], and only for windows.
Apple's Xcode can be configured to use the avr-gcc toolset. (Even thought it's right here on my system, I'm happy with Eclipse and haven't tried it).
Likewise, you can use Microsoft Visual Studio (the linked article is just one of many).
Command line: You can get down and dirty with your favorite editor, the gcc toolset for AVR, and bang away at your keyboard. Not sexy, but you'll learn everything that's going on between your code the board.

The Arduino IDE does its own non-standard preprocessing before the C++ preprocessor/compiler is invoked. One of the main purposes for this is to detect #include directives which refer to libraries so it can link them properly.
My guess would be that part of this procedure ends up moving all #include lines to the start of the file. In the code you've posted, that means I think it's being moved outside the whole #if/#else structure.
In most cases, you can avoid the Arduino IDE trickery by moving things into a separate header or source file. Unfortunately though, doing that means it may not link the libraries properly. As such, the easiest solution may be to switch to a 3rd party IDE which has Arduino support (e.g. Eclipse).

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


text:
Why all blink tutorials use 330 ohm resistor
When I do the led calculation I found 150 ohm resistor is enough for 3mm red led. If so why all arduino tutorials, like this one, are suggesting 330 ohm resistor?
I assume V = 5 Volt, diode forward voltage = 2V and diode forward current 20mA

I guess most people are using 1% resistors these days, but if someone does happen to use a 10% resistor rated at 150 Ω the actual value could be as low as 135 Ω. The forward voltage can vary, too; a red LED I was using the other day had close to a 1.7 V forward voltage. Under those conditions, you'd be putting almost 25 mA through the LED, probably exceeding the recommended maximum forward current by a good margin.

150 Ohms may be "enough", but it's often still far too bright, so many tutorials keep a lower limit of around 10mA to help the LED live longer without affecting the application.
You'll probably find that red LEDs are still visible at 1mA and a 330 Ohm resistor with a 5V supply will give about 8.5mA (assuming a 2.2V drop), which is plenty.
It's really a "lazy" choice that will work well in "most" situations.

True. Almost anything up to 1K will work. I always use 470 Ohm resistors just because I have a lot of them.

An important consideration is that the chip cannot necessarily source 20 mA on all output pins at once. In fact pins D5 to D13 on the Uno (PD5 to PD7, and PB0 to PB5) cannot source more than 150 mA combined. Thus the maximum you could source on those pins, if you are driving them all at once, is 150 / 9 = 16 mA.
So, designing for 10 mA per LED is allowing a safety margin, possibly to save tutorials the complexity of explaining that 20 mA is OK for one pin, but not for all the pins at once.


text:
RTC square wave
I have a DS3231 Real Time Clock module and I'd like to use the Square Wave output.
I wonder how can I set the frequency of the pulse?
How long is the (time) length of the pulse?
UPDATED QUESTION
In order to use the DS3231 as an 1PPS interrupt, I want to use the Square Wave output. Here's how I connected it to an Arduino.

I connected to the SQW output a 10kΩ pull-up resistor and an LED. After that I tested the code which shows the time and worked fine.
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup () {
   Serial.begin(9600);
   #ifdef AVR
      Wire.begin();
   #else
      Wire1.begin();
   #endif
   rtc.begin();

  if (! rtc.isrunning()) {
     Serial.println("RTC is NOT running!");
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
  }

void loop () {

   DateTime now = rtc.now();
   Serial.print(now.year(), DEC);
   // etc
   }

(The DS3231 works fine with the DS1307 library)
In this case the LED was just flickering, so I thought that the default frequency of the SQW should be grater than 1Hz. I googled a bit and realized that I had to change some registers. So I found this piece of code which I called from the setup() function, but with no success, the LED is still flickering.
void set1Hz() {
   // Frequency is stored in register 0x0e in bit 3 and 4
   Wire.beginTransmission(0x68);
   Wire.write(0x0e);
   Wire.endTransmission();
   Wire.requestFrom(0x68, 1);
   uint8_t register0E = Wire.read();

   // clear bits 3 and 4 for 1Hz
   register0E &= ~(1 << 3);
   register0E &= ~(1 << 4);

   // put the value of the register back
   Wire.beginTransmission(0x68);
   Wire.write(0x0e);
   Wire.write(register0E);
   Wire.endTransmission();
 }

Since I'm now qualified for low level programming, any suggestions on how to change the registers would be appreciated.

What does the datasheet say?

datasheet page 13.

Even though it is unusual for someone to answer his/her own question, I did some more digging and managed to solve the problem. So, I'd like to mention one or two items in order to help someone who may encounter the same problem.

I used the Jack Christensen's library https://github.com/JChristensen/DS3232RTC, but I had to update the Time.h library.
In the setup() I add this line in order to enable the SQW output and set it to 1PPS.
RTC.squareWave(SQWAVE_1_HZ);

Other options are SQWAVE_1024_Hz, SQWAVE_4096_Hz, SQWAVE_8192_Hz and SQWAVE_NONE
Using the LED and resistor (390Ω) as shown in the figure above, it works as a voltage divider. In that case the voltage between SQW output and Ground didn't exceed 2.0V. Thus someone should be careful if wants to have an LED indicator and wants to use SQW output as interrupt.

Please remember to mark your answer as solution in 3 days ;)

with DS1307 Tiny RTC library:
"rtc.writeSqwPinMode(0x10);" in the setup loop...
sets DS output to 1 Hertz, squarewave
Its not exactly 1PPS signal, which is typically a narrow pulse,
but this 50% duty cycle signal will do as a 1 second interrupt.

SQWV output only pulls low, it is an open drain output.
Wire up like this: 5V to LED anode, LED cathode to current limit resistor, other leg of resistor to SQWV pin.
Check the current capability of the pin. 10K will make very dim (if seen at all) LED. Try 1K.

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


text:
How to convert a String number Into a int value?
I want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be equal to that number. This is a small example of the code:
#include <Servo.h>
Servo myServo;

int val = 0;
String s = "";
void setup() {

  Serial.begin(9600);
  myServo.attach(9);
}

void loop() {
  while(BT.available() >0){
  s =  Serial.read(); // which wiil be a number between 0 and 255
  // So I want val to be = to ehatever the string is. So far I have try this but it doesn´t work.
  // first attempt # 1
  val = s:
  myServo.write(val);

  // Second attempt # 2
  Serial.println(s)
  val = Serial.read();
   myServo.write(val);
  }
}

The easiest way is to use the parseInt method available to Serial like this
int val = Serial.parseInt()

But, you will have to be sure that the non-number part of the message ("Slider") has already been dealt with.
You could also put the data into an arduino String Object and use it's toInt method, or put it in a C style string and use the atoi method.


text:
Arduino selection for RTOS
I am brand new to Arduino and am having a difficult time understanding the "lay of the land". I'm looking for the beefiest, fastest, most compute-centric Arduino available to the market that will run embox.
As I understand it, there is really only the Uno and the Mega, both of which are 32-bit. However I also believe that 64-bit variations/designs exist and was wondering if anyone has actually implemented Arduino Uno/Mega as a 64-bit MCU. I also see there is the Arduino Due, but not sure how that fairs (beefiness-wise) with Uno/Mega.
So to summarize: What is the beefiest Arduino one can find, is it 32- or 64-bit, and will it run an embedded RTOS like embox?

Why are you looking for something arduino related? the normal AVR arduinos are 8-bit cores packed full of IO, but not intended for doing much calculation.

I have some teensy boards, that aremore than sufficent, and fully supported by the FOSS, RTOS NuttX. teensy 3.x, 4.x are supported that I know of off hand. you miht find there is arduino stm32 support in which case you can run NuttX on that as well. Check em out: https://nuttx.apache.org/

While I'm not experienced with running an RTOS on it, I'd highly recommend Teensy 3.1 as the "beefiest, fastest, most compute-centric Arduino". FreeRTOS and ChibiOS both support Teensy.

Thanks @Arvid Jense (+1) - but what exactly is Teensy? Is it Arduino? if so, why don't I see "Arduino Teensy" anywhere on the Arduino.cc site? Thanks again!

Teensy is an Arduino compatible board made by Paul Stoffregen and is meant serve for specific applications where you'd want to use the Arduino IDE, but you need more performance than the Atmega chips can deliver, while still being less expensive than most other alternatives. Paul contributes a LOT to the Arduino code base, yet doesn't feel the need to pay for licensing, which is why you won't see it on the arduino website.

Thanks @Arvid Jense (+1 again) - what about my specific questions though? (a) How does Teensy compare to Arduino Due (which seems to be the beefiest)? (b) Is Teensy 32- or 64-bit? (c) Would Teensy run embox? How can you tell? Thanks again!?

a) Due's main advantages are that is has more IO pins and has the arduino form factor, Teensy 3.1 on the other hand is a lot cheaper and fits on a breadboard. Otherwise they are very similar, so I really depends on your specific needs.

b)  32 bit. If you want 64bit you might be looking towards something different than arduino. c) It doesn't seem like it, Google is your best friend!

Thanks @Arvid Jense (+2 for both!) - last follow up question, I promise! For (c) you said "doesn't seem like it", can I ask why? What makes you think Arduino Due/Teensy won't run embox? Thanks again!

Check out the Embox site to see what platforms are compatible with embox, Arduino doesn't seem te be in here. The other two RTOS' I linked to did seem to able to run on Arduino.

Okay @Avrid Jense (+1) - I think that is the root of my confusion here. On Embox's site, they mention ARM as a compatible platform...isn't Arduino Due ARM?!? If not, what is it? From the Due's own website: "The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM Cortex-M3 CPU"....thoughts?

It might be able to work if you know what to do, but why doesn't the STM32Discovery, which is already supported, suit your needs?

You could try an Intel Edison Arduino Kit.
It's 64 bit and can be programmed with a variant of the Arduino IDE.
You can interleave Arduino code with system calls to the Linux OS, depending on which approach better suits a specific need.
Running an RTOS inside Edison seems a bit overkill, however it should be doable.
Otoh you could just rely on the much higher clock to provide quasi-deterministic response.
Or just ditch the Arduino IDE and write a normal program with your programming language of choice.


text:
How to avoid report of unsuitable sketch names?
I bought a kit of 37 sensors for Arduino, and downloaded all the example sketches. Now, when I try to start up the Arduino IDE I get a lot of frustrating messages like this:

... and I have to click "OK" on every one in turn before the IDE will start up.
Obviously I do not want to delete the sketches and their accompaniments, so I have tried to rename all the files and directories, with a shell script, to remove non-alphanumerical characters, but my understanding of shell programming is not good enough, so I have had no success.
I have made backups of the files in case things went awry with my scripting, and now see that these messages are repeated, as in the image, for the backup copies as well. I cannot find out how the Arduino IDE finds them, they are not in my Sketchbook folder.
I would be grateful for advice on either how to avoid these messages, or to edit the names so that they do not occur: I would be happy to edit the names of each sketch as I come to try it out, but I baulk at doing the lot at once.
I am using Linux Fedora 20.

Similar question here:  https://arduino.stackexchange.com/questions/33996/how-can-i-use-my-arduino-sketches-on-my-raspberry-pi-ide/33997#33997 but the thing to know is that it is only complaining about the directory names.  But the IDE wants the filenames to match the directory names.  (continued)

See my answer below.  I flesh it out better than I can do in comments.

That message is actually a hang-over from when the IDE was Processing.  The name of a file had to match the name of the Java class within that file, and there are strict rules about what can be in a Java class name.
They just basically haven't got around to deleting that piece of ancient code yet.
So you have 3 options:

Rename all the folders and files.
Edit the IDE's source code to delete that old code
Use a different IDE.

The first option can be long winded if you don't know how to do good scripting, as you have found out.
The second option requires knowledge of Java coding.
So that leaves the third option.  Now, I'm going to be shamelessly advertising my own work here ;)  Why not try a better IDE?  Such as the popular and powerful UECIDE (yes, written by me). It's based on the Arduino IDE, so it will mostly be familiar to you, but the whole of the insides have been ripped out and re-written.  If you're feeling brave you might want to give the beta version a go - it has some really really cool features not found in any other IDE in the history of mankind.

Thanks Majenko for that brilliant answer. I am using Linux Fedora 20, andI have successfully installed UECIDE, using the.zip file, but I haven't time to look into it further today. I'd like to try the beat version, but don't know how to check for or install Java VM. I will report on my progress.

I meant beta not beat, but I took too long to notice and edit the comment.

I got lost in the Plug-in manager in UECIDE, couldn't see how to install the selected plugins, but I will pursue that. Meanwhile I have solved the immediate problem by backing up all the offending files to a USB stick, and will re-name and load those I need, as I come to them.

I caught that jab about long-winded, @Majenko.  Upvote anyway.  I still referenced my answer you probably were referring to, in my answer here, long-winded or not.  At least it is a proven method.  But Windows is a much easier way to do the renaming unless someone really likes running unreadable scripts like mine, and crossing their fingers until they see that it worked..  ;-)

Short answer:  You can't avoid that error in the Linux Arduino IDE until your sketches have allowable naming.
Similar question here: How can I use my Arduino sketches on my Raspberry Pi IDE?
Note that it is only complaining about the directory names. But the IDE wants the filenames to match the directory names.
So your best way to deal with this is to go into Windows IDE then load each sketch and resave it with allowable names, before transferring. Make a separate directory for the saves.
If you have dozens, or if you don't have the Windows IDE available, then the program I wrote (see the link above) will do the job for you on the Linux side. It definitely works.  I had a bunch and it ran through them all in a minute or two.
I suggest you avoid using the program  in favor of the Windows route..  But look at that link to get a feel for how I'm set up.
It is really easier to just use the Windows-based IDE to do the renaming.  One by one, just load them then resave them without the special characters, into a subdirectory to be used to transfer to Linux on a flash drive or FileZilla.
Another issue you will face in the Linux IDE is the libraries.  First put them in a libraries folder under sketchbook.
Then use the IDE menu item "Sketch..Import Library..Add Library" for each library - it then stores them elsewhere in the IDE's guts.
You can do this on an as-needed bases.  Start with the most common ones like Adafruit_sensor.h, (Note that the underscore is OK for that one) which you know will be used by many of the sensors.  SoftwareSerial.h is another good one.  DHT.h if using the temp/humidity sensor.  Wire.h must be in there for a lot of them.
In the end, it works fine, as you can see at the link above.  I rather enjoy sitting at my desk using Remote Desktop via WiFi to the Pis, then remote-reprogramming the Nanos (C++) and/or the Pi (Python, BASH, SCP, etc) to get them calibrated to collect my data.
Have fun with the sensors.  Those will take some time to absorb, but in the end it is all worth it.

Can I suggest you change the title of your question to something like "I have the Arduino 37 Sensor pack - how do I make the sketches work in Fedora Arduino IDE?"


text:
Servos don't move
I made simple code for a robotic arm, but the servos don't seem to be reacting at all. I made debug code before all the if statements, and those aren't working. I made sure my wiring was good and it is.
#include <Servo.h>

Servo release1;
Servo release2;
Servo updown;

int pos = 64;    // variable to store the servo position
int pos2 = 85;
int val = 0;
int val2 = 0;
int val3 = 0;

void setup()
{
    release1.attach(8);
    release2.attach(9);  // attaches the servo on pin 9 to the servo object
    updown.attach(10);
    release1.write(pos2);
    release2.write(pos2);
    updown.write(pos);
}

void loop()
{
    val = digitalRead(4);
    val2 = digitalRead(5);
    val3 = digitalRead(6);
    pos++;
    pos2++;
    if(val = LOW){
        pos = pos + 15;
    }
    if(val2 = LOW)
    {
        pos = pos - 15;
    }
    if(val3 = LOW)
    {
        pos2 = 180;
    }
    if(val3 = HIGH){
        pos2 = 0;
    }
    release1.write(pos2);
    release2.write(pos2);
    updown.write(pos);
}

I'm using this code and it still wont work.
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Have you tried debug the digitalRead function? Start with just one value and see if the motor moves. Maybe the position variable is changing too fast. Make sure the servo gets to the desired position by giving it some time.

Look at my edit.

This is the basic code for servos, it works okay for my Arduino UNO. Have you selected the right arduino before burning the code? Try changing the pin, maybe it is not working properly. It seems a board issue.

How are your connections to the servo motor? Usually the red is +5V, brown is GND and orange is the signal you connect to the attached pin in the code.

Did some test, all pins seem to be working fine, and yes the connections are right.

What is the model of your motor? Are you using enough power supply for it? In some cases just Arduino's 5V output is not enough... You need an external power supply.

SG90 motor, so im using plenty of voltage for it, it moves when I first plug it in but thats its.

5V is enough for it. Have you tried different digital pins to attach in the Servo library? Another way is to check if the signal is correct by testing with logic analyzer.

I used different pins for it, I never heard of a logic analyzer, what is it and how would I use it for an arduino/servo?

It is a device where you can plug in digital signals and analyze some behaviors. For example: see periods, frequencies and then debug you application. In this case you could see if the PWM generated to control the servo is based on the correct frequency accepted by the servo. They work using a specific period during "on" time and that could indicate where your problem is located.

Well I dont have one I used arduino 1,0 and that didn't work either, I will try with another computer later.

Try another board and update the IDE's version as well.

Have you tried the servo without using the Arduino ?

I made debug code before all the if statements, and those aren't working.
if(val2 = LOW)
{
  pos = pos - 15;
}
if(val3 = LOW)
{
  pos2 = 180;
}
if(val3 = HIGH){
  pos2 = 0;
}

That's because they are coded wrongly. Doing val2 = LOW assigns LOW to val2 and then tests it (which means it will fail the test). They should read:
if(val2 == LOW)
{
  pos = pos - 15;
}
if(val3 == LOW)
{
  pos2 = 180;
}
if(val3 == HIGH){
  pos2 = 0;
}

I tried uploading on a computer with windows 8 freshed installed and it still wont work, i tried serval differn't servo motors, looks like the arduino it self is broken.


text:
Arduino: ARM, MCU, SoC and RTOS
I'm trying to understand the relationship between embedded RTOSes, SoCs and chip architectures. Specifically, I have a hobby project that would involve me writing a real-time, embedded application for the embox RTOS, and use Arduino hardware for my proof of concept/prototype. Then, budget permitting, I'd like to port that app to run on another, non-Arduino ARM-based system.
My understanding is that ARM is the chip architecture (a conceptual design, really), and that Arduino simply implements this design, and is also a "system on a chip" because it has other things (USB ports, GPIO pins, etc.) that make it more of a computer than just a MCU.
My understanding is that if embox runs on ARM, which they claim it does, then at some point in the future I can take my application and run it on another ARM-based system without any real headache/pain.
Is my understanding of: ARM, Arduino, MCU, SoC and embox/RTOS correct? If not, please clarify/correct me! If so, what sort of considerations would have to be made when porting my app to another ARM system in the future?

My understanding is that ARM is the chip architecture (a conceptual design, really),

ARM is the CPU core architecture used in the Atmel SAM3X MCU family. The MCU is the CPU plus all of the facilities (PWM, ADC, DAC, DMA, etc.) that are implemented in order to allow the CPU to interact with external circuitry.

and that Arduino simply implements this design,

Most appropriately, "Arduino" is the IDE and the software libraries that come along with it, plus the specifications and connector layout of the various pieces of Arduino hardware.

and is also a "system on a chip" because it has other things (USB ports, GPIO pins, etc.) that make it more of a computer than just a MCU.

"SoC" is exactly what it says on the tin: it's an entire system on a single chip. The Due is not a SoC, since it's a full board. The BCM2835 found on the RPi is a SoC. The SAM3X is a MCU, since it still requires more than just connectors to become a full "system".

My understanding is that if embox runs on ARM, which they claim it does, then at some point in the future I can take my application and run it on another ARM-based system without any real headache/pain.

Provided that embox runs on the new system and that your application can be compiled for it.

Thanks @Ignacio Vazquez-Abrams (+1) - a quick followup question for you: when you say that Arduino is "...the IDE...software libraries...plus the specifications/connector layout for the various pieces of hardware", can you provide a concrete example of each? I'm just not seeing the forest through the trees there... For instance what kind of software library are you talking about? What kind of connector layout, etc.?Thanks again!

All the libraries that come with the IDE; EEPROM, Ethernet, GSM, LiquidCrystal, etc. As for the connectors, everything on a board that isn't actual electronics that allows e.g. a shield to connect.


text:
Receiving multiple bytes from an RPi using the i2c protocol
Trying to send bytes from an RPi as a master to an Arduino as a slave.
The send uses the write_byte(addr, value) function and seems to be working perfectly.
The Arduino however has issues with separating the received bytes into individual values.
I want to use the RPi to dictate when data is sent so I just need the Arduino to listen on wire.available.
Using the wire.onreceive event function I can have a separate function which has:

int var = wire.read()
Serial.print(var)   //for monitoring read byte

This code shows that the bytes being received are the right ones however, when I try something like
ledData[0] = wire.read();
ledData[1] = wire.read();
ledData[1] = wire.read();
etc
etc
...

This returns wildly different values as if the bytes are getting mixed up. Can anyone help me to specifically intake 16 bytes into array indexes for use in the main loop function.

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


text:
AVR Timer1 OCR1A controls TIMER1_COMPB_vect interrupt!
I was struggling with timer interrupts in my project. I couldn't make it work properly. So I decided writing a simple code and I saw a very interesting case.
ISR(TIMER1_COMPB_vect)
{
        PORTB ^= (1 << PORTB5);
}

int main(void)
{
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B

    OCR1A = 10000;
    OCR1B = 100;

    TCCR1B |= (1 << WGM12);

    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);

    TIMSK1 |= (1 << OCIE1A);
    TIMSK1 |= (1 << OCIE1B);
    DDRB= 0xFF;

    #define F_CPU 16000000
    sei();
    while (1)
    {

    }
}

Here is my code. When I change OCR1B value, nothing happens, but if I change OCR1A value then blinking gets faster. Is there a logical explanation for this?

@Gerben No. OCR1A is 2 byte. OCR1AH and OCR1AL are single byte.

By setting WGM12, you set the time to CTC mode. In this mode the timer will restart when it reaches that value set to OCR1A. So the lower the value, the faster it restarts, so the higher the frequency.
The OCR1B value only changes where in this cycle the interrupt occurs. It will however still only be called once per timer1 overflow.

Short but very clear explanation. respect

Thanks. Timers are a bit hard to understand, but very powerful.


text:
What connects to Arduino Solar Shield?
I see there is an Arduino EnergyShield available, and am wondering what (specific) solar shield/panels/attachments can be used to power it. Thoughts?
Bonus points if someone can explain how long the solar unit would take to charge the Energy Shield if the Arduino was on but idling (low-to-nonexistent power output).

First, panels that you can use...
There are a few at Adafruit (here, here or here)
You just want to check that the barrel jack and plug are the same size.  I couldn't find dimensions in the documentation for the energy shield so you may need to dig a little deeper or just swap it for one that you know will work.
Also, the question about how long it will take also depends.  First, if we assume that the arduino is not running we can get ~500mA from the second solar panel listed.  If we can get all of that into the battery, it would take (1200mAH/500mA) about 2.4 hours to fully charge the battery.  It looks like you have to make some adjustments on the shield to get the most out of your solar panel.  And of course, you'll want to adjust those calculations based on the panel that you end up getting.
Now, if we assume the Arduino is running and consuming about 25mA you will have to subtract that 25mA from the 500mA that the solar panel is providing.  So, in general...
**

(Battery Capacity)/(Solar Panel Current - Arduino Current) = Charge
  Time.

**
And you have a lot of control over the solar panel current and the arduino current based on the exact arduino that you use, etc, etc.
There is also probably some loss regulating the solar panel voltage from 5-6V down to charge the battery (which is probably at 3.7V). I also don't know if the charging circuitry will limit the amount of current going to the battery.
Take Away: There's a lot of stuff to consider when trying to answer this question.  I think your best bet would be to get a panel that fits and dump the fuel gauge values out to the console every few minutes.


text:
Arduino Attiny 85 IR library compiler error
I'm about to ask a question for the most common problem which everyone has with attiny85 and the IR library. I will try to make this question as simple as possible.
Few things about the lib and the chip
First of all the lib https://github.com/shirriff/Arduino-IRremote works great on the UNO and it's the best out there.
The Attiny85 is the smallest chip you can get able to run Arduino code. It has alot of limitations but it worth it!
The common problem
Attiny85 uses different timers from the normal Attiny and Atmega chips which makes it impossible to run the standard libraries. There are some fixes for some libs. For example the IR Remote has a version which ALMOST works with the chip and it can be found over here: http://gammon.com.au/Arduino/IRremote_Attiny.zip
However the problem lies in the core. The first time i used the patched IR i had the MIT High Low Media Group versino 1 of the core files which bearly worked but it was the first released so...
After reading this guide:http://www.instructables.com/id/Attiny-IR-library/?ALLSTEPS I used an updated core which can be found here: https://arduino-tiny.googlecode.com/files/arduino-tiny-0100-0017.zip
And the final problem
Even with the updated core i still got only 1 last error.
Compiling 'Shit' for 'ATtiny85 @ 8 MHz  (internal oscillator; BOD disabled)'
IRremoteInt.h:101: error: 'RAWBUF' was not declared in this scope
Error compiling

Does anyone know how to fix it?
Links

MIT high-low group first version: http://highlowtech.org/?p=1229
Tutorial for the chip and the IR: http://www.instructables.com/id/Attiny-IR-library/?ALLSTEPS
The IR original lib: https://github.com/shirriff/Arduino-IRremote
Updated core: https://arduino-tiny.googlecode.com/files/arduino-tiny-0100-0017.zip

Just in case you wanna know i'm using the Atmel Studio 6 with the Visual Micro plugin instead of the crappy-arduino-IDE

RAWBUF is defined in IRremote.h. Make sure you include that header before including IRremoteInt.h.

it worked but not im getting this:
Upload failed. Did you select the correct upload method for this board?
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(String buildPath, String className, Boolean verbose, Boolean ProgrammerUploadUsing, String mcuProgrammerOverrideName)
at processing.app.SketchEditor.Upload(Boolean verbose)

That's a problem with your build environment, not the code.

Indeed. I upload it through the IDE and its working however the receiver is just dead. nothinf happens when i press the button

Keep your Visual Micro up to date and the error above will not appear :)


text:
MQTT vs Tinkerkit sensor Shield
I'm working with this http://knolleary.net/arduino-client-for-mqtt/. I'm using Arduino Uno + Ethernet shield + Tinkerkit Shield. But, if i have only Arduino Uno + Ethernet Shield, i can connect my arduino with MQTT and make publish/subscribe, but, when i put the tinkerkit shield, i lost the connection and i cannot connect any more. Any idea? Tinkerkit sensor shield is incompatible with mqtt?
Thanks.

I think your problem is in wiring. Ethernet shield is using SPI communication, it requires pins: SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). Those pins must be left for the Ethernet shield. Information is from Arduino Uno description.
Does your Arduino communicates with you after you plug-in Tinkerkit? If not, maybe you have a short in Tinkerkit shield.

The problem was that. Thank you so much. I'm with one led plug in 10.


text:
Program Arduino Uno as a digital clock
I have an arduino Uno board with a screen attached on top (http://www.freetronics.com.au/pages/16x2-lcd-shield-quickstart-guide#.VUf0tMWN0iT This is the screen).
I'm trying to get it so that the screen displays the time in hours, minutes and seconds and counts on a 24 hours loop. Like a digital clock. I have it so that it can count but it just counts up to 99 then repeats.
I have this code which counts milliseconds but I need minutes and hours
    #include <Wire.h>
    #include <LiquidCrystal.h>

    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    void setup()
{
    lcd.begin( 16, 2 );
}

    void loop()
{
    lcd.setCursor ( 0, 1);
    lcd.print(millis());
}

Why not trying the timer interrupt from atmega328 uC. You'll also learn something usefully and I think is more interesting than using a library and some methods ( functions) without knowing how they are implemented.
It's really simple to make a digital clock just by interrupting every second. In ISR you'll just have to update the the values for seconds/minutes/hours. For displaying on the LCD, if you don't want to mess with LCD commands and bytes, you can use LiquidCrystal.
Example of code:(here I also used an analog pin for modifying time)
#define F_CPU   16000000UL
#include <avr/delay.h>
#include <avr/io.h>
#include <string.h>
#include <avr/interrupt.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const short buttonPin = 5;
volatile unsigned char seconds;
volatile unsigned char minutes;
volatile unsigned char hours;
void update_clock()
{
    seconds++;
    if (seconds == 60)
    {
        seconds = 0;
        minutes++;
    }
    if(minutes==60)
    {
      minutes=0;
      hours++;
    }
    if(hours>23)
    {
      hours=0;
    }

}

ISR(TIMER1_COMPA_vect)
{

  update_clock();

}

void setup()
{

  // initialize Timer1
  pinMode(A5, INPUT_PULLUP);
  cli();          // disable global interrupts
  TCCR1A = 0;     // set entire TCCR1A register to 0
  TCCR1B = 0;     // same for TCCR1B

  // set compare match register to desired timer count:
  OCR1A = 15624;
  // turn on CTC mode:
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR1B |= (1 << CS10);
  TCCR1B |= (1 << CS12);
  // enable timer compare interrupt:
  TIMSK1 |= (1 << OCIE1A);
  sei();          // enable global interrupts
  lcd.begin(16, 2);
  lcd.print("HH:MM:SS");
  Serial.begin(9600);

}

void display_on_lcd()
{

  lcd.setCursor(0, 1);
  lcd.print(hours);
  lcd.setCursor(2,1);
  lcd.print(":");
  lcd.setCursor(3,1);
  lcd.print(minutes);
  lcd.setCursor(5,1);
  lcd.print(":");
  lcd.setCursor(6,1);
  lcd.print(seconds);

}

void loop()
{

  display_on_lcd();

  Serial.println(analogRead(5));
  if(analogRead(buttonPin)<1000)
  {
    if(minutes==59)
    {
      minutes=0;
      if(hours==23)
        hours=0;
      else
        hours++;
    }
    else
    {
      minutes++;
    }
  }

}

Just search and you'll find a lot of examples.

Nice sample! Do you think it's better to use the Timer Interrupts instead of the millis() function?

I really don't know how millis() is implemented to say why my implementations in bettter that one with millis(). I thought that is more "natural" to implement with timer interrupt compare, cause in real embedded you don't have a millis() function. Also, millis() return an unsigned long and that is a lot of bits. If you have a microcontroller with limited memory, you can't declare & store a lot of unsigned long variables just for calculating time. Also, think about that, for example, in the code with millis() you call the function on each iteration in while-loop and update the values.

those calls to function will generate delays ( clock cycles). also, for this type of problem you have to use extra variables? why to declare 3 more variables unsigned long currentMillis, previousMillis, elapsedMillis; when I only need seconds/minutes/hours. extra code! not talking about how much clock cycles take the branches. Again, not saying that is better with timer interrupts compare, but maybe the code is cleaner, less memory is used etc. millis() is more like a nice to have function, and was developed just to make development simpler but not to use in real projects.

Thanks for the clarification! yes, im with you, its more reliable and cost-efective. Thanks again

Simple but really unnecessary.  You already have a timer interrupt doing this in the core, why do you need a second one?  Now you've got two timers tied up instead of one.  Now Timer0 and Timer1 are both tied up counting time and now you've made Timer1 unsuitable for PWM.  Why not just stick with the timer interrupt that's already incrementing milliseconds and calculate the time from that?

Im with @arvid-jense on this one, if you are working on a serious Digital Clock, then you should get the Real Time Clock.
Now if you are learning Arduino and want to play with your LCD Minidisplay and build a clock, you must know some important limitations of the millis() function on this project:

The mills function will overflow, after approximately 50 days.
Your clock will be inexact because the cycles of the Arduino
loop, you will be checking how much mills has passed on each loop.
(it will be lagging ~ 10 seconds each day, so on day 7 you will be one minute late)
the parameter for millis is an unsigned long, errors may be generated
if a programmer tries to do math with other datatypes such as ints.

That being said
#include <Wire.h>
#include <LiquidCrystal.h>

/**
 * Clock Variables
 */
unsigned long currentMillis, previousMillis, elapsedMillis;
int seconds, minutes, hours;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
    lcd.begin( 16, 2 );
}

void loop()
{
    setClock();
    /**
     * After set clock now you have 3 int variables with the current time
     */
     //seconds
     //minutes
     //hours
     lcd.setCursor ( 0, 1);
     lcd.print(millis());
}

void setClock()
{
    currentMillis = millis();
    elapsedMillis += currentMillis - previousMillis;

    /**
     * If we use equals 1000 its possible that because of the mentioned loop limitation
     * you check the difference when its value is (999) and on the next loop its value is (1001)
     */
    if (elapsedMillis > 999){
        seconds++;
        elapsedMillis = elapsedMillis - 1000;
    }

    if (seconds == 60){
        minutes++;
        seconds = 0;
    }
    if (minutes == 60){
        hours++;
        minutes = 0;
    }
    if (hours == 24){
        hours = 0;
    }

    previousMillis = currentMillis;
}

Nice tutorial on building an Alarm Clock

Your MILLIS_OVERFLOW is wrong. On recent versions of the Arduino library, millis() overflows at 2^32 (49.7 days), which means that testing for the overflow is useless.

Didn't know, thanks! i updated the constant MILLIS_OVERFLOW. (it's a digital clock, testing for the overflow isn't useless). Anyway, i think that the proposed solution by @23ars using Timer Interrupts is better than mine.

This code is still incorrect. Testing for the overflow is definitely useless: per the rules of modular arithmetic, which are guaranteed for unsigned numbers by the C and C++ languages, currentMillis - previousMillis will always yield the right answer, regardless of overflows.

@EdgarBonet sorry, but i don't get it. Did you test this code on Arduino? Please could you explain how this code should work without testing for the overflow. Thanks!

I tested it right now. When millis() overflows, it goes like crazy changing the time at each loop iteration. If you remove the test for the overflow, it works just fine. If you read carefully the liked article on modular arithmetic, it should be obvious that the test is useless.

I get it, i removed the test for the overflow. The difference will be always reflected by the two unsigned numbers.

Others mention a Real-Time Clock (RTC), and it may look like the obvious choice, but maybe it isn't. All a RTC does is keep counters for hours, minutes, seconds, date and month, but your microcontroller can do that as well.
Unfortunately the Uno doesn't have a crystal, but a ceramic resonator, which isn't nearly as accurate. Not that it matters much, even a crystal-based RTC may deviate several seconds a day. You can measure the error over a long time, and correct at regular times in software, but this is tedious.
If you want long-time accuracy there are two cheap ways:

use an atomic clock receiver. In Europe there's DCF77, in North-America it's WWVB which broadcasts very accurate date and time information. A receiver module for these costs around 10 dollar
use the mains frequency to clock your clock. On the long term this is extremely accurate (just think about your alarm clock: how often do you have to adjust that?) In Europe you would count 100 half periods per second (120 in the US). When your counter reaches that count, reset it and increment the seconds. If seconds reaches 60, reset it and increment minutes. And so on. If you're not exactly electronics-savvy you can ask on electronics.stackexchange.com to help you out. It's not difficult.

Getting a RTC over an Arduino will do you much better. The whole point of an RTC is to use a temperature stable crystal that is guaranteed to keep N seconds of accuracy every year.  The accuracy varies by model but the arduino xtals or ceramics will drift wildly faster

@portforwardpodcast: yes, the Arduino ceramic resonators will drift more than a crystal, but even a crystal-controlled RTC can drift a couple of seconds a day. That's a minute a month. You'll have to synchronize your clock from time to time anyway, so why not allow the Arduino's relative inaccuracy and sync once a day. With an RTC you'll have to do that too, only less frequent.

Also, while there exist temperature-compensated oscillators, the 32kHz crystals used for RTCs are not temperature stable.

Not sure what you're asking, but getting a Real Time Clock module will make your life a lot easier when dealing with time. Maybe post some sample code to show what your issue is.

Well you need to break this problem down.
If you are currently able to count in milliseconds, then you know 1000 milliseconds equal 1 second, so every time the milliseconds equals 1000, you reset it to 0 and increment the seconds by 1.
You keep going from here, if seconds equals 60, then you increase minutes by 1, and reset seconds to zero.. You get the picture.

Thanks everyone for your help! I've ended up with the code below which works quite well, there's the odd glitch with the seconds which is for some reason fixed if milliseconds is added on the end, but other than that it works very well.
#include <Wire.h>
#include <LiquidCrystal.h>

#define MILLIS_OVERFLOW 34359738

/**
* Clock Variables
*/
unsigned long currentMillis, previousMillis, elapsedMillis;
int seconds, minutes, hours;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
  Serial.begin(9600);
  lcd.begin( 16, 2 );

}

void loop()
{
    setClock();
    /**
   * After set clock now you have 3 int variables with the current time
   */
   //seconds
   //minutes
   //hours
     lcd.setCursor ( 0, 1);
     lcd.print(hours);
     lcd.print(":");
     lcd.print(minutes);
     lcd.print(":");
     lcd.print(seconds);
     lcd.print(":");
     lcd.print(elapsedMillis);

}

void setClock()
{
    currentMillis = millis();
    /**
     * The only moment when currentMillis will be smaller than            previousMillis
     * will be when millis() oveflows
    */
    if (currentMillis < previousMillis){
    elapsedMillis += MILLIS_OVERFLOW - previousMillis + currentMillis;
} else {
    elapsedMillis += currentMillis - previousMillis;
}

/**
 * If we use equals 1000 its possible that because of the mentioned loop limitation
 * you check the difference when its value is (999) and on the next loop its value is (1001)
 */
if (elapsedMillis > 999){
    seconds++;
    elapsedMillis = elapsedMillis - 1000;
}

if (seconds == 60){
    minutes++;
    seconds = 0;
}
if (minutes == 60){
    hours++;
    minutes = 0;
}
if (hours == 24){
    hours = 0;
}

previousMillis = currentMillis;
}

The takeaway from the previous answers is that your best option is to
use an RTC (real-time clock). Failing that, you can emulate the RTC
using millis(), at the cost of a significant drift, especially if your
Arduino is clocked off a ceramic resonator.
I would just like to add that you do not have to write the logic of that
millis()-based “soft RTC” yourself, as this has already implemented in
the RTC_Millis class from Adafruit's RTClib:
#include <RTClib.h>
#include <LiquidCrystal.h>

RTC_Millis rtc;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
    rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
    lcd.begin(16, 2);
}

void loop() {
    static DateTime last_time_printed;
    DateTime now = rtc.now();
    if (now != last_time_printed) {
        lcd.setCursor(0, 1);
        lcd.print(now.timestamp(DateTime::TIMESTAMP_TIME));
        last_time_printed = now;
    }
}

One nice thing about this option is that, if you later opt for a real
RTC, you will only need to do minimal changes to your code. Another nice
thing is that, if you measure the drift of your clock, you can easily
correct it: just replace RTC_Millis with RTC_Micros
and call rtc.adjustDrift() in setup(). You will be able to adjust
the drift with a 1 ppm resolution. Note that both RTC_Millis
and RTC_Micros are immune to rollover problems.

How stable is a ceramic resonator though? Doesn't the drift vary? A quartz crystal based clock is quite stable, so an adjustment factor should be quite effective, but doesn't the speed of a ceramic resonator vary by a good bit more than a quartz crystal?

@DuncanC: It does vary quite a bit indeed, but the average drift is typically larger than the drift variations.


text:
Programmed device causes issues between computer and ISP
I'm using a Digispark, which is basically an attiny85 packaged with a few other things, as an ISP to program attiny85's. The Digispark is loaded with Littlewire and recognized as an USBtinySPI device on the computer. The target attiny85 to be programmed is stacked on top of the Digispark. All pins are connected 1-to-1, 2-to-2, etc. Programming is done from the Arduino IDE. The tutorial I followed can be found here...
http://digistump.com/wiki/digispark/tutorials/programming
The Digispark uses port 3 (USB-) and port 4 (USB+) to communicate with the computer. There are series resistors and shunt zener diodes on both USB connections. The Digispark schematic can be seen here...
https://s3.amazonaws.com/digispark/DigisparkSchematicFinal.pdf
I have been happily programming attiny85's with this setup, but recently hit a snag. On the target chip, if port 3 or 4 produce an output, the computer will no longer recognize the programmer. The computer will immediately connect to the programmer once the target chip is removed from it's socket. The target chip must be messing up communication between the computer and the programmer.
Curious if I was missing something, I compared my setup with Sparkfun's Tiny AVR Programmer. It seems like a more robust programmer. I thought it might have extra components or something, but it's almost identical. It uses an attiny84 with pins directly connected to an attiny85.
After lots of random guesses, I added series 2.2kohm resistors on ports 3 and 4 between the target attiny85 and the programmer. This solves the problem, but seems like a workaround.
Am I missing something? It seems like a programmer should be able to work without worrying about what the pins on the target device are doing. I assumed poorly, that was the purpose behind the RESET pin. Is there a better solution?

With  the Tiny AVR programmer, the D+ and D- lines are connected to there own input pins on the ATtiny84, see below:

This means that the pins from the target chip do not interfere with the function of these.
Whereas the digistump board has the outputs of the USB connected to pin 3 and 4, these pins are also connected to pin 3 and 4 of the target, as you know,

This means that as soon as you have your outputs active on 3 and 4 these interrupt the function of the USB lines.
By adding the 2.2k you are increasing the resistance before the Zener regulator circuit(thus decreasing the effect of the voltage from the target on these lines) and allowing the main tiny to have 'control' over the bus lines.
This is actual done on the SPI buses as well when a ISP is programming a target, while the target has other SPI chips on the bus, you add series resistors on the SPI bus, as seen below:

The R is usually between 1k - 4k7ohm. So you method is not a workaround, but normal procedure.
Another method to use instead of the resistor would be to cut the traces on the target board for pins 3 and 4, thus preventing it from going back onto the USB line. This is as I see no need to have control over the USB lines from the target.

Am I missing something? It seems like a programmer should be able to work without worrying about what the pins on the target device are doing. I assumed poorly, that was the purpose behind the RESET pin. Is there a better solution?

The programmer only toggles reset when programming, and once the target is flashed with your firmware that uses the same lines as USB and the PC then does not recognize the programmer because of this, the programmer won't be able to issue a RESET to the target, as

the PC can't issue it,
the programmer won't know to do that on its own.

I like your idea of just cutting the traces or adding jumpers. The target chip only needs MOSI, MISO, SCK, and RESET, correct? So, ports 3 & 4 aren't even needed.

@curtis - yes only those four(MOSI, MISO, SCK, RST) are used the other two aren't, it would be nice to have the others if one ever wanted, I was thinking of solder jumpers( cut trace, expose a bit of copper on each), that would be possible if there is space as I don't think a standard jumper would fit.

The target board/socket is connected to the digispark with stackable headers, like an arduino. I'll probably just bend the male pins out that I don't want connected. Sweet, this has been bugging me and it makes sense now. I'd upvote your answer, but can't with only 3 rep.


text:
How to get string parts from string?
I have this method:
void getWeatherData() {
    String resp = "";

    Process p;
    p.begin("python2.7");
    p.addParameter("/root/weather.py");
    p.run();

    while (p.available() > 0) {
        char c = p.read();
        resp = resp + c;
    }

    Serial.print(resp);
    Serial.flush();
}

In the serial monitor, I see the string 70.7|45|1030.29|06:05|20:04|04 May 2015 22:24. The delimiter here is the pipe. Now, the parts I take a send them to methods that puts the values on the TFT screen.
However, I fail to understand how to split this long string into individual parts.
Can somebody help?
Thanks
EC

Would you like to share the platform in use?

Do you mean which Arduino? If so, it is the Yun. I've also added a tag for it.

I used to have my own String class with a member method called Chomp which did exactly what you are requiring.  The body was something similar to this untested code:
String chomp(String& pSrc, char pMatch)
{
    int matchPos = pSrc.indexOf(pMatch);    // Find the first occurrence of the separator
    if (matchPos < 0)   // Separator was not found.
    {
        String ret = pSrc;  // Return the remainder of the source string.
        pSrc = "";          // Clear the source string
        return ret;
    }

    String ret = pSrc.substring(0, matchPos - 1);   // "Chomp" the start of the string up to the separator into the return value
    pSrc.remove(0, matchPos);                       // Remove everything up to and including the separator.
    return ret;
}

Hopefully the above code should be pretty understandable and fixable if there are any errors.  Our version worked on a "this" pointer rather than passing in the source string, so we would have something like:
String sourceCoords = "12,47,292,85";
int x1 = sourceCoords.chomp(",").toInt();
int y1 = sourceCoords.chomp(",").toInt();
int x2 = sourceCoords.chomp(",").toInt();
int y2 = sourceCoords.chomp(",").toInt();

Hope this is of some use.


text:
Microcontroller controlled power supply
Can anyone assist me to make a power supply whose output voltage will be controlled by an Arduino, with the latest voltage setting automatically saved in non volatile memory?
I am in an OJT (On the Job Training Scheme). I was given a task to make a Arduino controlled voltage variable power supply whose outputs can be switched between several preset values using pushbutton control.   It's like switching between two different outputs when a designated button is being pushed.
Here is what I have done so far. I made an LM317 based power supply with the output voltage controlled by a potentiometer. I followed this youtube tutorial. It works well but I was ask to upgrade it.
Instead of using a potentiometer to adjust the voltage, I wish to use switching buttons to choose between two or more preset voltage levels. Each switch buttons have their corresponding voltages.
This link may also be relevant.
Code is given below the circuit diagram.
ARDUINO AS A POWER SOURCE ALTERNATOR

I suggest that you make sure that your words mean what you intend. The example (via link) that you gave  switches between two batteries. An "Alternator"  is an "AC Generator" a rotating electromechanical machine used to turn mechanical energy into electrical energy.An Alternator regulator is a device which controls the output voltage (usually) of an alternator. If you wish to swap between two batteries alternately you want a program controlled battery selector with selected-battery stored in memory.

@RussellMcMahon - Yes I need a program that swaps two different power source.

@RussellMcMahon It's a simple adjustable power supply and I've made one. I followed this youtube tutorial [link] (youtube.com/watch?v=F-ahtojVl4M). It works well but I was ask to upgrade it, instead of using a potentiometer in adjusting the voltage, he suggest to have a swicthing buttons which I can swap two or more power sources automatically. Each switch buttons have their corresponding voltages. Can you help me figure out how to apply it maybe by using an arduino?

AC  - I have extensively rewritten your question based on the original plus what you said in comments.I did this because the words you were using gave a wrong impression of what you say that you want to achieve. If you do not like my edits please modify them. I could easily provide an answer BUT it is useful to see what other people say.

@RussellMcMahon Thank you for editing the question. I appreciated what you've done. That was exactly what I am supposed to ask.

@RussellMcMahon Sir, I would gladly wait for your answer. That would be a great help.

An important question: Is this like an assignment or test where you are trying to learn or show what you know or will somebody use the end product for an application ? We can answer either type of question here but the approach taken is different in each case.

If you want to output preset voltage levels in distinct steps, rather than an 'analogue' range from X volts to Y volts, then the answer is in the datasheet for the LM317:

Connect each of the INPUTS through a 1k base resistor to your Arduino pins. Selecting different values for all the resistors will of course allow you to vary Vout by turning each transistor on or off, by themselves or together. You can use any standard transistor: 2N3904, 2N2222, BC548, etc., but I might elect to use a (low power) MOSFET like a BSS138 instead (and omit the base resistor). Of course you can use add more resistor/transistor lines if you want more output options. I recommend using R2 so that Vout is always limited, otherwise - if Vin is quite high - you may damage whatever Vout is powering due to some runaway voltages.
Calculating resitor values is your mathmatical challenge. If you really apply some brainpower you can change Vout in linear steps with minimal Arduino pin usage:
'Input' states            Vout
  A  B  C  D            (/volts)
  0  0  0  0              5.00  [Vmax set by R2]
  0  0  0  1              4.75
  0  0  1  0              4.50
  0  0  1  1              4.25
  0  1  0  0              4.00
   ...  ...                ..
  1  1  1  0              1.75
  1  1  1  1              1.50

This shows that with N Arduino pins you can have (N^2)-1 levels. Using R2 gives your final level whne all INPUTs are off.
If you want to be able to drop Vout down to 1.25V, add transistor/MOSFET that connects R1/ADJ straight to ground. Turning this on will drop Vout to 1.25V, irrespective of the state of the other INPUTS.

I would like to add few extra notes for this interesting approach for digitally control the voltage output. What described in the original datasheet is in fact a very "minimalistic" 4 bit, DAC circuit. For some rationale it would help to study this two docs from AnalogDevices: One and Two.

I am wary about providing a complete answer without knowing what is expected of YOU - is this like an assignment where you are being tested on understanding and what you have learned. The following will be useful to you. You need to give some more details if you want more assistance with these circuits.
Here is an existing stack exchange question. I see that I answered it in 2011 :-).
How does this power supply circuit work? (MCU + LM317)
The circuit and my previous answer should help greatly.
In your case you apply PWM  using analog.Write to R1.
You MUST understand how the circuit works and not just apply it.
The original appears to be here with circuit description, with diagram here

On this page from EDN magazine is a similar circuit. The pot between pins 1 & 5 would not usually be used.

In another stack exchange question there is a very useful caution about the opamp's load limits in a similar circuit.
Problems controlling an LM317 with an op-amp - 2013

You can get many possible ideas here - search = lm317 voltage controlled power supply - this is an immensely powerful way of finding information -  IF a picture is worth a thousand words then this is priceless. Note the terms used.

Bad designs:
There are some bad designs around which can look OK but behave badly.
Despite the detailed writeup,
This poor design uses "open loop control" and the output voltage varies with load and is only "sort of controlled".
I was asked why I think this circuit is "open loop". I could not find a complete circuit diagram on the page but this diagram was shown of the output stage. If this is NOT the actual circuit used it would be "good" to have the complete circuit easily accessible.

IF this is the actual circuit used, then:
Call the transistors Q1 Q2 Q3 Q4 in left to right order.
Call intended output voltage = Vset = Vdac x (R6 + R7)/R7.
Vdac is applied to Q1 base and amplified by Q1 & Q2 to form the desired output voltage, appearing at Q2 collector. A lesser voltage appears as Vout due to the Vbe drop in Q3 & Q4. As load current increases Vout will "droop" thereby increasing the drive to Q4. This in turn increases the load on Q3 and Q3 emitter voltage will droop increasing Q3 drive. The actual Vbe voltages will depend on the beta (current gain) of Q3 and Q4, their temperatures (which depends on heat sinking, load and ambient temperatures) and manufacturing variation. At no or very low loads Vout will be about 1 Volt below Vset. At heavy loads Vbe_Q3 will be in the 0.6-0.8V range and Vbe_Q4 will be 0.8V+. So Vout will be around 1.5+ Volts below Vset and variable with (at least) the factors mentioned above.
This is still a usable design, but Vout could 'easily enough' be made far more stable with load by feedback from Vout to the Q1-Q2 amplifier - essentially forming a comparator that compares Vset and Vout.
Update:
This [reference provided by NilsB] MAY be the actual circuit diagram or close to it. It's an earlier 2005 design which presumably is much the same as the later version.

It appears not to be open loop in the broad sense. The Vout is still decoupled from Vset, with the software feedback allowing him to adjust the Vset to make Vout what he wants on a "nudge it and see" basis. ie Vset is not a fixed ratio wrt Vout so he can never set it and have it "just track". So it does not automatically stabilise for load or temperature changes and there is a variable drp between k x Vset and Vout.
Software is fastish but not as fast as a closed loop in hardware which allows Vout to track Vset within mV in a time delay as short as you provide an error amp loop for.
That's a 2005 circuit diagram so an earlier version than the originally cited V3 - one assumes he has not 'gone backwards' in design concept. It's strange that he does not include the whole circuit diagram or a good discussion of the provided current and voltage feedback. He may have wanted to sell kitsets rather than give away his final design. The link to the kitset sales is now broken so he now manages neither.
I'd consider it preferable to add a simple hardware error amplifier so Vout = k x Vset and THEN measure Vout and Iout with ADCs (as he does). Vout is then essentially "set and forget" with the added ability to check that Vout is what it should be (which allows eg heavy overload to be detected.
Constant current mode operation is still "nudge and see" but 'not too bad'.
Also, Vout includes the Vdrop across the current sense resistors - about 0.5V/A. Measuring with 2 x AD C channels as he does allows this to be compensated for. If the Isense resistors were in the "high side" feed before the regulator this would remove this variation but make current sensing somewhat harder.

What makes you think that this solution: http://tuxgraphics.org/electronics/201005/bench-power-supply-v3.shtml is "open loop control"?

@NilsB Please see my updated answer. I've assumed that the actual circuit is the one shown on the page. If there is a complete circuit diagram anywhere and/or if this is not the actual circuit used I'd be pleased to know. (Both those comments are genuine - I feel I MAY have overlooked some final diagram somewhere but if so I cannot find it.) As it stands I assume that what is shown is what is used and my comments apply.
The developer seems to have attempted to minimise use of ICs use of a comparator in the output stage would improve the result and make the design task easier.

I guess this  http://tuxgraphics.org/common/images2/article379/powersupply.gif is the whole circuit. And as the feedback loop is done in software IMHO it's not "open loop". What do you think?

@NilsB If your guess is correct then it appears not to be open loop in the broad sense. The Vout is still decoupled from Vset, with the software feedback allowing him to adjust the Vset to make Vout what he wants on a "nudge ity an see" basis. ie Vset is not a fixed ratio wrt Vout so he can never set it and have it "just track". ie it does not automatically stabilise for load or temperature changes and there is a variable drp between k x Vset and Vout. ...

...  Software is fastish but not as fast as a closed loop in hardware which allows Vout to track Vset within  mV in a time delay as short as you provide an error amp loop for. || That's a 2005 cct diagram so an earlier version than the originally cited V3 - one assumes he has not 'gone backwards' in design concept. It's strange that he does not include the whole circuit diagram or a good discussion of the provided current and voltage feedback. He may have wanted to sell kitsets rather than give away his final design. The link to the kitset sales is now broken so he now manages neither.


text:
Arduino IR not returning data
THIS QUESTION ISN'T IN USE ANYMORE

Solved by using an other remote that is supported by the libary

====NEW CODE====
    #include <IRremote.h>

    int RECV_PIN = 11;
    int relay1 = 2;
    int relay2 = 3;
    int relay3 = 4;

    int on = 1;
    int on1 = 1;
    int on2 = 1;

    IRrecv irrecv(RECV_PIN);
    decode_results results;

    void setup()
    {
      digitalWrite(relay3, HIGH);
      pinMode(relay3, OUTPUT);
      digitalWrite(relay2, HIGH);
      pinMode(relay2, OUTPUT);
      digitalWrite(relay1, HIGH);
      pinMode(relay1, OUTPUT);
      pinMode(13, OUTPUT);
      irrecv.blink13(true);
      irrecv.enableIRIn();
    }

    unsigned long last = millis();

    void loop() {
      if (irrecv.decode(&results)){
        if (results.value == 0x36167A85) {
          if (millis() - last > 250) {
            on = !on;
            digitalWrite(relay1, on ? HIGH : LOW);
          }
          last = millis();
        } else if (results.value == 0x36161AE5) {
          if (millis() - last > 250) {
            on1 = !on1;
            digitalWrite(relay2, on1 ? HIGH : LOW);
          }
             last = millis();
        } else if (results.value == 0x3616FA05) {
         if (millis() - last > 250) {
            on2 = !on2;
            digitalWrite(relay3, on2 ? HIGH : LOW);
          }
            last = millis();
        }
        irrecv.resume();
      }
    }

================
I'm working on this bit of arduino code for a while now but i can't get it to work. My circuit is wired up correctly, but it isn't returning any data in the serial prompt. Here is my code:
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

int main = 0;
int left = 0;
int right = 0;

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

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    switch (results.value) {
      case 0x2E3A06C0:
        main = 1;
        Serial.println("MAIN: on");
        break;
      case 0x8C2921D6:
        left = 1;
        Serial.println("LEFT: on");
        break;
      case 0x226270DA:
        right = 1;
        Serial.println("RIGHT: on");
        break;
      case 0x4AC6E6A:
        main = 0;
        Serial.println("MAIN: off");
        break;
      case 0xDD5E26EF:
        left = 0;
        Serial.println("LEFT: off");
        break;
      case 0x3E5BEF99:
        right = 0;
        Serial.println("RIGHT: off");
        break;
    }
    irrecv.resume();
  }

  delay(100);
}

I'm using the libary Arduino-IRremote. When I try the demo "IRrecvDemo", it works fine. I have the hex codes from this demo. So can someone help me get this code working? It would be nice!

I'd start by troubleshooting at a hardware level first, e.g. checking with a logic analyser or oscilloscope if any 5V pulses are detected on pin 11.

I have checked it with an oscilloscope and it is working fine, but I still have the problem that it isn't returning any data into my serial prompt. Please help!

My suspicion is that the IR library was unable to decode your IR signal. What kind of remote control are you using, and is it supported? Your code looks fine on face value (compared to the IR library example), so that's the only thing I can think of.

Try also the receive example from https://www.pjrc.com/teensy/td_libs_IRremote.html

This is working and it is returning data "UNKONWN: (hex code here)", when i try my code it isn´t returning data

That essentially means that the protocol on your remote (you didn't say what type it is), is not supported. "results.value" will be 0 in this case.

@Reezy I'm using an old remote for a helicopter, Maby I should try it with an other remote, thanks for your help Reezy !

Try to put Quotation mark like this:
switch (results.value) {
  case "0x2E3A06C0":
    main = 1;
    Serial.println("MAIN: on");
    break;
  case "0x8C2921D6":
    left = 1;
    Serial.println("LEFT: on");
    break;
  case "0x226270DA":
    right = 1;
    Serial.println("RIGHT: on");
    break;
  case "0x4AC6E6A":
    main = 0;
    Serial.println("MAIN: off");
    break;

If this doesn't work too, maybe you've got a hardware problem

Did you try removing the 0x indicator? If I remember correctly the incoming signals are raw, e.g. 2E3A06C0, even though the script requires the 0x indicator on the send routines.
Alternatively, you'd need to rewrite, but you could try this IR Library and code, which I found has much better documentation and data analysis options on the receiving side: https://github.com/cyborg5/IRLib/

I need the 0x because it is hex, I tried the other lib but it is stil not working....

You're right. I tried to run your code without the 0x and it trips a type incompatibility error.

Well, found the problem but I don't know why. It was your variable declarations. The following code with "main, right, and left" integer variables commented out ran, the original didn't:
 #include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;
//int main = 0;
//int left = 0;
//int right = 0;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
        switch (results.value) {
      case 0xB9F56762:
        Serial.println("MARNIX IS RIGHT");
        break;
        case 0x8C2921D6:
//        left = 1;
        Serial.println("LEFT: on");
        break;
      case 0x226270DA:
//        right = 1;
        Serial.println("RIGHT: on");
        break;
    }
    irrecv.resume();

  }
   delay(100);
}

I have it already working, but thanks!

the answer is now inside the main post

THIS QUESTION ISN'T IN USE ANYMORE

Solved by using an other remote that is supported by the libary
  and tweaking the code.

====NEW CODE====
    #include <IRremote.h>

    int RECV_PIN = 11;
    int relay1 = 2;
    int relay2 = 3;
    int relay3 = 4;

    int on = 1;
    int on1 = 1;
    int on2 = 1;

    IRrecv irrecv(RECV_PIN);
    decode_results results;

    void setup()
    {
      digitalWrite(relay3, HIGH);
      pinMode(relay3, OUTPUT);
      digitalWrite(relay2, HIGH);
      pinMode(relay2, OUTPUT);
      digitalWrite(relay1, HIGH);
      pinMode(relay1, OUTPUT);
      pinMode(13, OUTPUT);
      irrecv.blink13(true);
      irrecv.enableIRIn();
    }

    unsigned long last = millis();

    void loop() {
      if (irrecv.decode(&results)){
        if (results.value == 0x36167A85) {
          if (millis() - last > 250) {
            on = !on;
            digitalWrite(relay1, on ? HIGH : LOW);
          }
          last = millis();
        } else if (results.value == 0x36161AE5) {
          if (millis() - last > 250) {
            on1 = !on1;
            digitalWrite(relay2, on1 ? HIGH : LOW);
          }
             last = millis();
        } else if (results.value == 0x3616FA05) {
         if (millis() - last > 250) {
            on2 = !on2;
            digitalWrite(relay3, on2 ? HIGH : LOW);
          }
            last = millis();
        }
        irrecv.resume();
      }
    }

================


text:
How do I use the additional serial ports on an Arduino UNO R3 clone?

I bought this Arduino clone over eBay. It seems to have an extra SPI and serial ports. How do I use these?

Even without extra ports, you can use multiple devices on a single SPI or I2C port anyway by their chip select lines / device addresses respectively.

UNO means ATmega328. It has always only one serial and one I2C port regardless of how many connectors (or solder pads) it is hooked to. They are just parallel outputs to ATmega pins:

D0 - TX
D1 - RX
A5 - SCL
A4 - SDA
Extra pads are just for user convenience, for easier wiring.

Those are not additional I2C and UART ports, those are additional connectors connected to the normal peripherals. They are used in exactly the same manner as the normal connector.


text:
IR not working on Attiny85
After countless attemps on making this thing work i'm not sure what the hell is going on. First of all you can't use the normal IR library because Attiny85 is crap and due to timer isses it wont work. So basicaly you need just the specific part which gets the data from the remote and thats all.
This is what i did but i failed badly again.
This time i used the simplest possible code which works perfectly on the Arduino UNO but it wont do anything on the Attiny85
The code
int irPin     = 4;
int tipPin    = 3;
int start_bit = 2200;    //Start bit threshold (Microseconds)
int bin_1     = 1000;    //Binary 1 threshold (Microseconds)
int bin_0     = 400;     //Binary 0 threshold (Microseconds)

boolean state = 0x0;

void setup() {
   pinMode(tipPin, OUTPUT);
   pinMode(irPin, INPUT);
   //Serial.begin(9600);
   //Serial.println("IR/Serial Initialized: ");
}

void loop() {
   int key = getIRKey();   //Fetch the key
   //Serial.println(key);
   if (key != 0) {
     state != state;
     digitalWrite(tipPin, state);
   }
   delay(400);    // avoid double key logging (adjustable)
}

int getIRKey() {
  int data[12];
  int i;

while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit

for(i = 0 ; i < 11 ; i++)
  data[i] = pulseIn(irPin, LOW);      //Start measuring bits, I only want   low pulses

  for(i = 0 ; i < 11 ; i++)             //Parse them
  {
    if(data[i] > bin_1)                 //is it a 1?
data[i] = 1;
else if(data[i] > bin_0)            //is it a 0?
data[i] = 0;
else
return -1;                        //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
  }

  int result = 0;
  for(i = 0 ; i < 11 ; i++)             //Convert data bits to integer
    if(data[i] == 1) result |= (1<<i);

  return result;                        //Return key number
}

The ouput values are 3-digit numbers which work OK and i'm not even checking the value here. Just if something came in. And it doesn't bloody work!!!!
Stuff i've already checked

The circuit
If the pin works
If the timers are set correctly
Using adafruits library
Changing every possible core
If the receiver works
The wiring

If you are trying to toggle the LED when a signal comes in, then there is a glitch in the code and I have no idea how the UNO worked for you as I tried and it only spat out Serial, but didn't do anything with the LED.
Try changing this line of code:
state != state;
to
state = !state
you are not actually toggling the LED state with the other line, but instead doing a logical not equal to which won't do what you want.

Oh my god.... Now i see it. It worked on the arduino because i wrote state != state; the first time then i deleted it to make it blink to test the pin and then i typed it manualy instead of pressing ctrl+z

@MeletisFlevarakis - thought it odd for a mistake like that anyway, done it myself a few times.


text:
How can i use a TFT Screen shield along with other sensors and transmitters
I want to use Arduino as described in this instructable:
http://www.instructables.com/id/Uber-Home-Automation-w-Arduino-Pi/
But i thought i would give it a little twist by adding a TFT monitor to some devices. I have bought and got the following tft shield to work:
http://www.banggood.com/UNO-R3-ATmega328P-Board-2_4-Inch-TFT-LCD-Screen-Module-For-Arduino-p-945755.html
But now it strikes me:
How can i combine the screen on an arduino where i also have a sensor and a radio transmitter?

You need another layer! A breadboard shield - from the same source if you like - would seem the obvious answer.
Alternatively, take flying leads from the pins you are using to the screen & mount it elswhere, then connect the sensors.
LCD's use quite a few pins, you'll probably need to be creative with an Uno. I have one on a Mega, & have been there with the same problem!

Link seems to be incorrect. I think you mean something like this. Also, I don't think there is enough room in between the two shield for an breadboard, and associated wires. Soldering would an a good option here.


text:
Arduino/DuinOS vs Normal C/ARM Programming
I'm trying to understand the difference between programming Arduino hardware (Atel/ARM based) versus 'normal C-based ARM programming'.
My understanding is that the Arduino language is cross-compiled into C-compatible binary, and the Arduino EEPROM libraries are used to effectively 'flash' your Arduino code onto the Atel/ARM chip, which is running DuinOS. Your Arduino 'app' (software) can then take advantage of DuinOS utilities, such as scheduling, semaphores, events, critical sections, etc.
My understanding is that if I wanted to program an ARM chip myself from scratch, I would have to use something called an ISP programmer to 'flash' an embedded RTOS onto the chip first. Then, I would have to write C code, compile it, and again use the ISP programmer to deploy the compiled binary to the ARM chip, which is already setup to boot the RTOS when powered on.
I'm sure I'm mucking up a few things here, but this is my general understanding: can someone correct/clarify these things for me?

My understanding is that the Arduino language is cross-compiled into C-compatible binary,

There is no "Arduino language". Programs are written in C++ or C, and the IDE mangles them in certain ways in order to ease development by beginners (and on occasion frustrate development by veterans).

and the Arduino EEPROM libraries are used to effectively 'flash' your Arduino code onto the Atel/ARM chip,

No. The uploading of the compiled code is done using a separate program, usually AVRDUDE or bossac, and the code is uploaded into flash. Data can be optionally uploaded into EEPROM via the same program, but this is not required.

which is running DuinOS. Your Arduino 'app' (software) can then take advantage of DuinOS utilities, such as scheduling, semaphores, events, critical sections, etc.

Not by default. If you want to use DuinOS then you will need to download, compile, and upload it yourself.

My understanding is that if I wanted to program an ARM chip myself from scratch, I would have to use something called an ISP programmer to 'flash' an embedded RTOS onto the chip first. Then, I would have to write C code, compile it, and again use the ISP programmer to deploy the compiled binary to the ARM chip, which is already setup to boot the RTOS when powered on.

Nope. Any system can be run without an OS.

Thanks @Ignacio Vazquez-Abrams (+1) - I follow your first two answers 100%, but have a few quick followups on the last two.  (1) Regarding DuinOS, if I don't use DuinOS, then what is running on the Arduino chip at the OS layer? And if I do use DuinOS, do I install it ahead of time on the chip, and then install my application, or do I bundle/compile them together ahead of time, and deploy them to the chip (via AVRDUDE, etc.) at the same time? And (2) Regarding my understanding of "normal C/ARM programming", is what I said about using the ISP programmer correct or am I way off?

^ I understand you don't need on OS, but if I want to use one, how do I deploy my app/RTOS to an ARM (basic, 30,000 ft view of the procedures)? Thanks again!

There is no OS layer. There is only your code. You will need to see the OS documentation to learn how to deploy it and applications. 2. Low-level ARM programming usually uses JTAG, but many ARM MCUs support programming via UART or USB via a bootloader.


text:
Writing C Program outside of Arduino IDE?
I like the idea of using the Arduino IDE for simple projects and for getting started with Arduino, but the consensus I've gotten so far is that it is for those who are new to Arduino and/or programming in general.
My understanding is that it is possible to write a C program from scratch, completely outside of the Arduino IDE, and then use a tool like AVRDUDE to upload it to an Arduino MCU. This option, albeit appealing and interesting, leaves me with a few concerns:

What Arduino libraries would need to be imported/linked by such a "raw C" program? I assume that when an Arduino IDE-based program executes a digitalWrite(...) it is really calling a C lib, probably provided by Arduino, under the hood. I am concerned about making sure all these "underlying libs" get included with my C program. Thoughts?
Is anything else "lost" by flying solo and venturing outside the Arduino IDE? Any capabilities/features that I would now have to "roll my own"?

http://arduino.stackexchange.com/questions/9538/using-an-arduino-board-to-program-an-avr
The answers on my question helped me to set it up.
You can replace/leave out anything from arduino.
You can: -Make your own board. -Use your own IDE. -Use your own libraries.

Here you are two nice articles how Arduino actually works in background. How it removed friction from microcontroller  programming.

A Tour of the Arduino Internals: How does Hello World actually work?
Arduino and GCC, compiling and uploading programs using only makefiles

It was also discussed here Is there a way or tutorial for converting Arduino code to C code?

Thanks @Michal Foksa (+1) - I guess I'm just shocked that the answer to this isn't much more well known! I would have thought that the Arduino IDE had, say, a lib/ directory somewhere under its installation root that had things like arduino-core.dll, arduino-io.dll, etc.

@smeeb: You're correct, the Arduino IDE installation does - has to - include libraries of the basic run-time functions plus user supplied ones. Halfway down the page of link 2, in the makefile, the symbol LIBS points to them. They aren't .dlls (which in Windows, are called at run-time); they are object files (.o under unix-like systems, probably the same under Windows) that are statically linked with your compiled object files into (ultimately) a .hex load file, which is the complete loader image. ...

... It is well known to people who write programs for a living, but the Arduino (brand) tool designers have deliberately hidden as many of the messy details as possible to make applying digital electronics available to people without them having to become professional level programmers and engineers to do it. To the extent you're finding this information hard to find in the Arduino community, they've been successful!

Unfortunately, for legacy reasons, you build Arduino software quite differently than the standard accepted way. In 'removing friction' to make it simple, they created a huge incompatible community. Every IDE 'plugin' is an attempt to make something not standard work in near standard way. Keep that in mind as you run into problems.

You're absolutely right about needing to link against other libraries. However, you don't necessarily need to worry about all of the details yourself, unless you want/need to do something unusual. Several alternative IDEs already support Arduino, typically via plugins which handle a lot of the details automatically.
I normally recommend Eclipse as it's a very widely used IDE for various purposes. However, there are several other possibilities. See this question for more information:

What are the other IDEs for Arduino?

Thanks @Peter R. Bloomfield (+1) - however I'm really looking for a non-IDE centric answer. Not that I have anything against IDEs, it's just that in order to understand the "library landscape" of Arduino, I feel like IDEs are just an unnecessary middle man. Having said that, I would assume that there are 1+ "core libs" that ALL Arduino apps must link with, and that there are then optional libs that you may or may not need, depending on what your app actually does.  Can you point me to a list of these "core libs", as well as any other optional ones? Thanks again!

And to qualify what I was saying above about IDEs being "unnecessary middlemen", what I really mean is: I should be able to write a C app outside of any IDE (Arduino, Eclipse, or otherwise), link to the Arduino libs that my app needs, and still compile/deploy the app to Arduino hardware. I'm wondering what those libraries are, and where I can find documentation on them.

@smeeb Given that Arduino is aimed at beginners, I don't think there's much (if any) official documentation along those lines. I expect the best way to research it would be to search online for examples of Arduino makefiles. There are some old examples near the bottom of this page.

@smeeb: Like you, I am not fan of IDEs. There are a few generic Arduino makefiles floating on the Web. You basically have to compile the Arduino core library into libore.a, then compile your .ino file with -x c++ -include Arduino.h for your compiler to understand it (plus a bunch of -D, -I, etc) and link with libcore.a.

Yes, you can write a program outside Arduino IDE.
For example I tried Eclipse IDE with AVR plug-in and now I stick with AVR Studio. Of course,you won't have some functions that you maybe usually use when you write in Arduino IDE and also some libraries. But, why not to try implementing stuff. Why to limit yourself to functions and libraries made by others when you can learn and write your owns, maybe better than the existing ones.


text:
When and where do I have to worry about accounting for sensor "noise"?
I just watched this excellent video tutorial that shows a simple Arduino program that toggles an LED via a pushbutton. Very cool!
Being brand new to electronics/robotics, I was shocked that something as simple as a pushbutton required his debounce behavior. That's something I would have never thought about in a million years. What is the 'rule of thumb' for when this type of debounce behavior (regardless of what sensor we're talking about, pushbutton or otherwise) must be accounted for? Is it simply that any type of analog sensor can generate this kind of unexpected 'noise'?
Can someone provide other examples for when special code must be put in place to accommodate unexpected sensor noise?

Switch bounce and sensor noise are two distinct issues.

Thanks @IgnacioVazquez-Abrams (+1) - ok then my apologies for getting my terminology mixed up. What I'm asking for is: what types of sensors, besides pushbuttons and their 'bounce', also exhibit this unexpected behavior. For instance, if I try integrating my Arduino with some new "Fizz Buzz Sensor" (that detects Fizz Buzz), how do I know that I can't just accept the readings it gives me, and that I won't have to do something similar to debounce?

I'm not sure if this is called noise, per see, as the problem with buttons is mechanical, not electrical. I can't think of any other sensors with similar (unexpected) gotchas. Most electrical noise is caused by varying power use, that will result the supply voltage not being stable. This instability can cause malfunctions or give inaccurate readings (like e.g. measuring a voltage while the supply voltage isn't stable, will lead to inaccuracies). Most of this can be negated by adding (decoupling-) capacitors.

Thanks @Gerben (+1) - so to confirm - this "switch bounce" is more of the exception than the rule, and these types of problems are not really encountered with other types of sensor readings, yes? Thanks again!

Rotary encoders  have the same problem (as they work just like buttons on the inside), but other that I don't think so. All sensors probably  have some things to look out for. E.g. light sensors will detect IR (that we humans can't see); Range sensors won't work on certain material; magnetometers might not give correct information when near speakers or microwaves. etc. etc. But nothing as "illogical" as switch bounce (to my knowledge).

Switch bounce is a physical issue that can be cleaned up with filtering. Since the sense states are very simple, only very crude (time-based) filtering is required to clean up its signal.
Other mechanical sensors that can exhibit similar characteristics are bump sensors, tilt sensors, and accelerometers. Bump and tilt sensors are also very simple, and similar filtering will clean up their signals.
Accelerometers on the other hand react to very minute perturbations, so they may require more advanced filtering based on the application they will be used in; orientation sensing can use time-based filtering, whereas things such as motion tracking including dead reckoning will require one or more layers of calculus in order to clean up the signal.

Awesome, thank you @Ignacio Vazquex-Abrams (+1) - when you say "filter/filtering", how does such a filter manifest itself in an Arduino program? For instance, in that video tutorial, the author simply implements a delay(...) inside his debounce function. Is that an example of an actual time-based filter, or does Arduino have some "filter API" that can be coded against to implement various types of filters. Thanks again!

@smeeb you can either filter in software, or with additional components (resistor+capacitor)

@smeeb: There are entire series of university courses that cover digital filtering.

@smeeb: Summing (averaging) several readings is one way of filtering. It depends on the assumption that the signal is consistent and the noise is random with a mean of 0. Thus summing statistically emphasizes the signal and deemphasizes the noise. The average can be as simple as the mean of the last n readings; or: f * (previous average) + (1-f)*(present reading), called an exponential average; and on up to much more complicated ways of treating the signal to reject specific kinds of noise. For most projects, a mean or an exponential average will do and are easy to code.

Anyone who believes sensors do not have noise has never used one.  True you may not encounter noise while reading the digital information, but I promise you the information will have noise in it.  Noise from a switch can be dealt with by hardware or software, such as his debounce behavior.  Other sensor noise is 4 years of study at college.  Look into Kalman Filters, probabilistic robotics.  Even the self driving cars you hear about currently require large compute capacity, mostly in order to deal with sensor noise.