text:
DS3231 DTCXO and GPS
I am experimenting with this idea: keep a DTCXO in sync with some frequency standard. I have all the parts I can afford, but I cannot figure out a way to do it.
Parts I have: Arduino Leonardo, a u-blox 6010 based GPS module with PPS output, and a proto shield with DS3231 DTCXO chip mounted.
My big idea is that DS3231 have aging registers that would affect the clock frequency. By keep counting the 8192Hz square wave output of DS3231 and keep it in sync with the 1Hz signal from the GPS module, I can keep the DTCXO in sync with a reference clock. This, in turn, would give me a relatively good 32768Hz clock reference that I can build a frequency counter on.
Both 8192Hz and PPS are interrupt driven.
Anyone have an idea on how to do it? Does this spell Artificial Intelligence on AVR, as my instructor suggests?

Perhaps use the 8192Hz signal as a timer clock signal?

@IgnacioVazquez-Abrams Not gonna work so well I think. The Leonardo is counting this 8192Hz and checking it against the 1Hz PPS from the GPS module, decrease the clock frequency if there is too many counts and increase it if there is too few.

And why can't you use the 1Hz signal as an interrupt to count the timer pulses?

@IgnacioVazquez-Abrams I am doing this, clocking the microcontroller at 16MHz, one interrupt counting the 8192Hz and another interrupt sensing the 1PPS.

Eh. Probably easier to use a timer.

Ehh... I am essentially calibrating the DTCXO so timer isn't really a good idea...

Why? All it's doing is counting the pulses for you.

By counting the pulses I change the "aging register" of the DTCXO and try to discipline it with the GPS.

Yes, and instead of having to create a separate interrupt for the 8192Hz signal, you let the timer count it for you.

So your suggestion is to feed the 8192Hz to a counter input, interrupt on the PPS, let the counter handle the 8192Hz and react based on the counter value (and reset it) when the PPS interrupt fires?

Yes. There may be a small amount of jitter to start of course, but a clever algorithm can handle that.

Well I would not start using the counter before GPS gets a fix, and GPS fixing can take minutes. So not that much a problem actually. Please post this as an answer so I cna accept it.

Hope you get this.  Trimming the aging compensation in the DS3231 is not worth the trouble.  You won't significantly improve the temperature accuracy or aging drift due to the crystal used, etc.
On the other hand, 10MHz Double Oven Reference Oscillators are available for under $50 on EBAY.  These are good to 2x10-12 short-term, or about 1x10-6 yearly drift.  For timekeeping purposes, you can ignore the short-term drift, could not measure it anyway :).  On the other hand, the aging drift will be large because you do not know how long these have been in service.  The good news is that aging drift is very stable if temperature is kept constant, the reason for the double ovens. So once you determine how far off frequency the OCXO is, you just periodically add a count to your divider during one period to keep it synched to the GPS signal.  For more info write mhuss103athotmaildotcom

Those are EXPENSIVE and all I have is cheap components: $10 Arduino clone, $8 GPS module, $0.5 NOS DS3231 chip,


text:
Emergency! INO file disappeared on computer. Still on Arduino!
For some reason, my Arduino program has disappeared from my computer, and it was a really long, complex program. It is currently still on my arduino, and I HAVE to get it back. Please, someone help me. Arduino UNO, Macbook Pro.
Edit: Perhaps I wasn't clear. I need the INO file back FROM MY ARDUINO.

Time to fire up your undelete program...

Lesson learned: perform backups...

Your edit changes nothing. The .ino file is not on the Arduino.

To be specific, the .ino/.pde/.cpp/.h source code is not in the Arduino.  But a working binary built from it us, which can normally be copied off and flashed to other devices.  In some cases that might help, but it's a pain to modify or reverse engineer.

Perhaps a trip around Macbook advice on undeleting files would be more fruitful? "Ask Different" maybe? Does foremost work on MacBook?

Don't you have a thing called time machine on a macbook pro?

The .ino file is lost, however, your Arduino IDE uses your %temp% to store immediate data.
Look in %temp%, folders akin to build116193871148509168.tmp contain build files. The original ino is not there, but I remember the cpp files generated by IDE should be there.
Some info about how to find the temp on Mac: https://stackoverflow.com/questions/11607834/where-are-the-hex-files-compiled-by-arduino

I am on mac, so I went to /tmp, but no cpp files were there. Thanks for trying to help, though.

Surprisingly, when i look in my folders, the cpp is not always there. But when i searched for .cpp it found some. Dunno when the postprocessed cpp is stored there.

http://stackoverflow.com/questions/11607834/where-are-the-hex-files-compiled-by-arduino

Your INO file is not (ever) on your Arduino.
When you "upload your sketch" to the Arduino, it is first compiled. Your Arduino cannot interpret a sketch directly, and there are various processes which convert your sketch into machine code. This process is not practically reversible.

source: Stack Exchange

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

sort: votes


text:
Multiple 7 segment displays blinking
i just set up 2 displays ( 3 digit 7 segments ), and the displays seems to be blinkin ( i know they are suppose to blink but so fast that the human eye cannot detect it ).
I'm using the SevSeg Library and this is how my code looks:
void setup() {

   byte numDigits = 3;
   byte digitPins[] = {2, 3, 4};
   byte segmentPins[] = {5, 6, 7, 8, 9, 10, 11, 12};
   sevseg1.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);

   byte digitPins2[] = {14, 15, 16};
   byte segmentPins2[] = {17, 18, 19, 20, 21, 22, 23, 24};
   sevseg2.begin(COMMON_ANODE, numDigits, digitPins2, segmentPins2);

}

void loop() {

  while(true){
     sevseg1.setNumber(number,0);
     sevseg2.setNumber(number,1);
     sevseg1.refreshDisplay();
     sevseg2.refreshDisplay();
  }
}

I need to add 2 more 3 digits 7 segment displays so i was wondering what is it that is causing the blinking.
Im using Arduino Mega.

Could you give the link to SevSeg library? There several different libs with that name, I have checked 2 and none had the methods you use.

First of all, you have a while(true) in your loop, that makes no sense. The loop already loops for ever.
You are also changing the number every time the loop() is run, making it flicker. If you follow the Arduino library example, you can see they only use setNumber every so often and use refreshDisplay every time the code runs through the loop().
Also, you didn't setBrightness, which shouldn't be a problem since the library probably sets a default value, but I'd advise on including it in your code to eliminate unforeseen problems.
Try this code and let me know if it works:
#include "SevSeg.h"

SevSeg sevseg1; //Instantiate a seven segment controller object
SevSeg sevseg2;

void setup() {
  byte numDigits = 4;
  byte digitPins1[] = {2, 3, 4, 5};
  byte segmentPins1[] = {6, 7, 8, 9, 10, 11, 12, 13};
  byte digitPins2[] = {14, 15, 16};
  byte segmentPins2[] = {17, 18, 19, 20, 21, 22, 23, 24};

  sevseg1.begin(COMMON_ANODE, numDigits, digitPins1, segmentPins1);
  sevseg1.setBrightness(90);

  sevseg2.begin(COMMON_ANODE, numDigits, digitPins2, segmentPins2);
  sevseg2.setBrightness(90);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;

  if (millis() >= timer) {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100;
    if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
      deciSeconds=0;
    }
    sevseg1.setNumber(deciSeconds, 1);
    sevseg2.setNumber(deciSeconds, 1);
  }

  sevseg1.refreshDisplay(); // Must run repeatedly
  sevseg2.refreshDisplay(); // Must run repeatedly
}

Thanks for your response, i removed the while true, the thing that if i remove one 7 segment displays it doesn't blink.

Yes i did, but it is like if every time i do the   .refreshDisplay();  it takes its time and shuts down the other display

I have completely revised my answer. Please do try ;)

Actually, the while() does make a little sense; looping your code that way is a lot faster.

@Tom, actually this is Arduino's demo code, not mine. Using the while also makes it loop extremely fast. As you can see from this demo code, they only refresh the display ever 100ms, preventing it from continuously refreshing.

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


text:
Possible arduino burned (5V shorted to Vin), explanations and suggestions
Please apologize my english.
I am working in a project using an original arduino uno, one generic servo (no factory marks) and one HC-SR04 sensor.
I make a circuit like the one here: http://s24.postimg.org/43jra5l9h/mycircuit_bb.png ([url=http://postimg.org/image/lgu1p0gkh/][img]http://s24.postimg.org/lgu1p0gkh/mycircuit_bb.jpg[/img][/url], sorry, upload of image not allowed due reputation)
As you can see from the picture I accidentally connected green into Vin instead of GND. (If the image won't load, that means that my positive is connected to arduino 5V and the ground of the circuit is connected to arduino Vin)
Now my board turn on the lights but I am unable to execute the program already in the microcontroller as aslo I cannot upload a new program to it. (It gives some error message of failed to connect).
I think I burned the microcontroller(mc) by short circuiting 5V and Vin.
That said, I have three questions:
1 - Is there any way to find out if I really burned my board using just a low budget multimeter? And if I did, which parts I need to replace?
I have access to some spare ATMEL mc and I think I could replace and reprogram them by using another arduino board. However, I am affraid that I may have burned few other items and just by replacing the mc will not give me back all the funcionallities of a new board.
2 - I have basic knowledge of electronics, could someone explain to a beginner like me which impact did that mistake could/have make in all components of the circuit? (Arduino board, the servo and the sensor)
3 - Even before the accident, the circuit just work well for few minutes. I read tons of pages and tried a lot of suggestions, most of them related with power supply (capacitors to avoid flutuations, One battery just for the servo, one battery just for the sensor...) and none gave me good results.
I am wondering what are the alternatives to power up this simply circuit, in particular I am looking for this possibilities: Complete external power supply (by using AC to DC adapters), Complete internal power supply (Using just batteries) and a mix of those two (Using AC to DC and batteries). I have no access to a external DC power supply generator other than batteries.

How was your Arduino powered when this accident happened? USB or power plug?

If you have another Uno then your best bet is either:
1) Swap the suspect processor into the known good board, test it.
2) to buy a replacement chip (ATMega 328-PU), use this link to flash it, if it works you win, if not you can at least use the new processor again.
I have done this myself & it worked well, it isn't easy to be sure any other way as the chip needn't fail in a predictable manner. The chances are it will take a large current if it's dead, until it burns out & goes open circuit. Once the magic smoke has come out you know it's dead... the Arduino power supply is reasonably capable of looking after itself so your chances are good.

Before replacing the target processor, it's also important to verify that the USB-serial chip still works - can the computer recognize the device as connected?  Can the serial port be opened without error (even though no data will be received in return).  If not, the interface chip (FTDI, ATmega6u2 or whatever) may be dead, and while replaceable it is a bit more tricky to do so.


text:
Problems stacking Arduino Shields
I'm trying to stack the Adafruit Data Logger Shield https://learn.adafruit.com/adafruit-data-logger-shield/overview onto a CuteDigi Sim900 GPRS Shield so that I can upload data (collected eventually by a GPS breakout) to a server at certain intervals.
The problem is that I can't seem to get the two shields to play nicely together. I'm a beginner with the Arduino and electronics in general, so hopefully this is just a noob issue.
When I power on the GPRS Shield, the data logger stops outputting the Date/Time to the serial monitor. And when I turn the GPRS Shield off, the serial monitor continues again and shows the Date/Time from the data logger.
They don't share any pins that I'm aware of, and I've tried connecting a 7.4V li-po for external power with no success.
Any help is greatly appreciated!

Make sure you are using a software serial port for the GPRS shield.
If you aren't using the software serial port, then you are probably running into an issue with trying to read data over the only UART (serial) port while two devices are tryiing to use it.
It looks like there are two jumpers next to D0/D1 on the GPRS shield, I can't tell but I think if you remove those, the shield will use software serial over D7/D8.  If you do this, you'll have to code your program to use a software serial.  This wiki page on the GPRS shield if you need help with that.


text:
How to send data from a smartphone to Arduino
My goal is to build an extremely low cost quadcopter, by using the sensors of my smartphone (it will be mounted on the quadcopter). The arduino will only control the speed of each motor, as received from the smartphone. What methods exist to transfer data from a smartphone to arduino?
My first idea was to simply use USB, but it turns out that my smartphone doesn't support the USB host mode. Is it possible to send data over USB without USB host mode? What alternatives do I have? I thought of using the audio port: Can I directly connect an audio channel to analog in?

"Extremely low cost" and the lift capacity to carry a smartphone sound mutually exclusive. I reckon by the time you get that lift power it would have been significantly cheaper to buy a gyro shield

Hmm that is true. But sending data would also be interesting for other robot projects.

I have been using a bluetooth module - they can be had for just a few dollars (depending on which country you're in). I've got an HC-06 which works great : http://www.dx.com/s/hc-05
It has 4 pins: VCC (connect to +5V on Arduino), GND, RX and TX (connected to RX and TX, digital pins 0 and 1 on the Arduino).
You will probably not be able to use Bluetooth and USB at the same time - both will be sending to the Arduino at the same time, and the communications will get garbled.
I have an app called "Bluetooth Serial Controller", which lets me send commands over bluetooth.
If using this, think carefully about what will happen if your phone goes out of range of your arduino.


text:
Simple word translator, return error: invalid array assignment
I know this is not a good question. But I am clueless with this error : invalid array assignment (at function convert). For extra information, I involved a lot of copying/pasting programs I haven't exactly understand from internet in the convert function (the strncpy ones) so.. yeah.
This is the program I've done (the menu/mn button currently not used):
#include <LiquidCrystal.h>
#define WORD 11
#define LETTER 15
LiquidCrystal lcd(7,6,5,4,3,2);
int i=0;
char input[] = "a";
char output[15];
const int dw = 8;
const int ri = 9;
const int le = 10;
const int up = 11;
const int ok = 12;
const int mn = 13;
int checker = 0;
int bounceCk = 0;

int bdw=0, bri=0, ble=0, beu=0, beo=0, bem=0;

void setup()
{
  pinMode(dw, INPUT);
  pinMode(ri, INPUT);
  pinMode(le, INPUT);
  pinMode(up, INPUT);
  pinMode(ok, INPUT);
  pinMode(mn, INPUT);
}
void intext()
{
  int lim=16;
  lcd.setCursor(0,1);
  lcd.print(input);
  for(i=0; i<lim ; )
  {
    lcd.setCursor(0,1);
    lcd.print(input);
    if(digitalRead(dw)==HIGH)
    {
      checker=digitalRead(dw);
      delay(100);
      bounceCk=digitalRead(dw);
      if(checker==bounceCk)
      {
        if(input[i]>'z')
          input[i]='a';
        input[i]=input[i]+1;
      }
    }
    if(digitalRead(up)==HIGH)
    {
      checker=digitalRead(up);
      delay(100);
      bounceCk=digitalRead(up);
      if(checker==bounceCk)
      {
        if(input[i]<'a')
          input[i]='z';
        input[i]=input[i]-1;
      }
    }
    if(digitalRead(ri)==HIGH && i<16)
    {
      checker=digitalRead(ri);
      delay(100);
      bounceCk=digitalRead(ri);
      if(checker==bounceCk)
      {
        i=i+1;
      }
    }
    if(digitalRead(le)==HIGH && i>0)
    {
      checker=digitalRead(le);
      delay(100);
      bounceCk=digitalRead(le);
      if(checker==bounceCk)
      {
        i=i-1;
      }
    }
    if(digitalRead(ok)==HIGH)
    {
      checker=digitalRead(ok);
      delay(100);
      bounceCk=digitalRead(ok);
      if(checker==bounceCk)
      {
        lim=i;
      }
    }
  }
}
void convert()
{
   char sumber[WORD][LETTER] = {{0}};  /* declare a progmem unsigned static array of kata x huruf */
   char dasar[WORD][LETTER] = {{0}};  /* declare a progmem unsigned static array of kata x huruf */

  /* copy various strings to statically declared storage SUMBER */
  strncpy (sumber[0],"memakan", strlen("memakan")+1);
  strncpy (sumber[1],"makanan", strlen("makanan")+1);
  strncpy (sumber[2],"menyuci", strlen("menyuci")+1);
  strncpy (sumber[3],"perubahan", strlen("perubahan")+1);
  strncpy (sumber[4],"penulisan", strlen("penulisan")+1);
  strncpy (sumber[5],"tercampurkan", strlen("tercampurkan")+1);
  strncpy (sumber[6],"pengelompokan", strlen("pengelompokan")+1);
  strncpy (sumber[7],"pengembangan", strlen("pengembangan")+1);
  strncpy (sumber[8],"kehebatan", strlen("kehebatan")+1);
  strncpy (sumber[9],"memotret", strlen("memotret")+1);
  strncpy (sumber[10],"melakukan", strlen("melakukan")+1);

  /* copy various strings to statically declared storage DASAR*/
  strncpy (dasar[0],"makan", strlen("makan")+1);
  strncpy (dasar[1],"makan", strlen("makan")+1);
  strncpy (dasar[2],"cuci", strlen("cuci")+1);
  strncpy (dasar[3],"ubah", strlen("ubah")+1);
  strncpy (dasar[4],"tulis", strlen("tulis")+1);
  strncpy (dasar[5],"campur", strlen("campur")+1);
  strncpy (dasar[6],"kelompok", strlen("kelompok")+1);
  strncpy (dasar[7],"kembang", strlen("kembang")+1);
  strncpy (dasar[8],"hebat", strlen("hebat")+1);
  strncpy (dasar[9],"potret", strlen("potret")+1);
  strncpy (dasar[10],"laku", strlen("laku")+1);

    /* mencari input pada sumber */
  int k=0, search=0, sel=9;

  while(search==0)
  {
    sel=strcmp(input, sumber[k]);
    if(sel==0)
    {
      output[]=dasar[k]; //!!!!THE ERROR IS HERE!!! happen to either this or output=dasar[k]
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Base Word:");
      lcd.setCursor(0,1);
      lcd.print(output);
      search=1;
    }
    else
    {
      k=k+1;
      if(k>=11)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Error:NF");
        lcd.setCursor(0,1);
        lcd.print("word n found");
        search=1;
      }
    }
  }
    /*
    //print the values
    while (*sumber[i])
        printf ("  %s\n", sumber[i++]);
    */

}
void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Type your word:");
  intext();
  convert();
  delay(15000);
}

I found more errors before, I've fixed those, but can't fix this one. I think this problem is caused by the wrong instruction or wrong format. But can't found solution...yet.
The program is converting words to its basic word in Bahasa, you can compare it to English like this. You type "eaten" and it will return "eat". You type "understood" it will return "understand". When you type "stunk" it will return "stink". Or something like that.
Example in bahasa :
"memakan" (eating) -> "makan" (eat)
"makanan" (food) -> "makan" (eat)
"pengembangan" (development) -> "kembang" (becoming bigger/better)
etc
I hope someone will give me a clear hint or two (I'm not too bright, but I still need to learn how not just copying things around),
Thank you very much!

It looks like you're trying to copy the contents of a particular sub-array in dasar across to the output array. However, this isn't valid in C/C++:
output[]=dasar[k];

To copy data from one array to another, you either need to copy each element one-by-one (e.g. in a loop), or use a block memory operation like memcpy.
Here's how I would do it:
memcpy(output, dasar[k], sizeof(output));

This should work because arrays are basically just pointers in C/C++. It uses the start of output as the destination of the copy, and uses the start of dasar[k] as the source. The number of bytes it copies is taken from the total size of the output array.

So the sizeof(output) means we can use it like this sizeof(strlen(output)) ?
Thank you!

No, sizeof(strlen(output)) doesn't make any sense. It would give you the size (in bytes) of the value returned by strlen(), which has nothing to do with the contents of output. Assuming the string stored in output is properly null-terminated, simply strlen(output) should tell you how many characters it actually uses.

The program above (at the question) will not make any null characters (I guess?)... and after some reading I think I got that sizeof is kind of like strlen, except it's counting any type of data? So it is interchangeable (as those string isn't null terminated?) with strlen? But now I got it clearly about memcpy. Thank you, thank you very much for your help. really thank you.

Your strncpy operations are adding the null terminators by copying them out of the string literals (string literals are implicitly null-terminated in C/C++). sizeof isn't equivalent to strlen though. sizeof gives you the size of any object, variable, or static array in bytes. strlen is only for strings, and it keeps counting characters until it reaches a null character (even if that means it goes past the end of an array).

Just replace the line in error with:
strcpy(output, dasar[k]);


text:
Reading the audio signal from a smartphone
i want to read the audio signal from my smartphone.
Can i just cut a headphonewire and connect it to the analog in? (Arduino uno)
I sadly dont know much about electronics.
greetings

Similar existing question on EE: http://electronics.stackexchange.com/questions/28404/what-is-the-voltage-range-of-a-standard-headphone-jack-from-a-phone

My question is just, if sth bad can happen, when i directly connect the devices. I don't have the electronics for amplification and i don't need a stronger signal.

No. It partly depends on the phone, but most put out a low voltage AC signal. This would drive the Arduino inputs negative. You can do this by biassing the input at the mid point (+2.5V) and feeding audio in via a capacitor. There are many projects which use similar to record audio.
PS I would not recommend cutting a headphone cord. The wires are very fine, and almost impossible to solder. If you want to do this make a custom cable.

What do you mean with "This would drive the Arduino inputs negative"? (Sorry not native english)

@gorilla: signal transmission in electronic systems usually use voltage as the thing transporting the information. Usually the voltage is generated and measured relatively to a potential called ground, which often is also connected to casings and earthing facilities. AC signals which are always used to drive speakers reach negative voltages relatively to ground in (roughly) 50% of the time. The ardino has only inputs capable of measuring and detecting positive voltage levels. Milliways refers to the trickery needed to "convert" AC signals to readable signals on the arduino.


text:
How can Arduino source code be tested automatically (continuous integration)?
I'd like manage my Arduino source code (projects and libraries) under source control with continuous testing. How can I automatically compile the code with continuous integration tools, to make sure each version compiles cleanly? In the best case one should be able to configure builds for multiple processors, optionally run unit tests and check for maximum binary size.

Other than passing it through Ino and avr-size?

@IgnacioVazquez-Abrams I don't mind which tools to use, but it should run automatically on some cloud hosting or continuous integration service.

Compiling binary size isn't that hard, but to do unit tests, you would have to structure your code in such a way that it is unit-testable, which is hard enough if you want to keep size small. Besides, you will need to run those test on a chip or in an emulator to get a test that is more or less reliable.

I found https://github.com/kyab/travis-test-arduino but its experimental and a comprehensive answer/tutorial as answer would be better.

The issue with this is it goes against the original purpose of continuous integration: it's meant to push changes and then have it automatically build and deploy within minutes. This allows your customers to get the latest features and fixes as they happen, instead of every two months. For Arduino it's just "cloud making sure it builds." For unit tests you might have to bypass the Arduino libraries to build functions and send example data over the "pins."

Multiple use cases behind this question + different answers for each. If use case functional unit tests, as already suggested you modify your code's function returns, but this isn't foolproof: and downsides if that's embedded into your deliverable.   If your use case is you want to measure integration w/HW, ex: "does Arduino light a LED in response to stimuli, i.e. temperature?"  Be creative. You will need additional hardware and software which can observe what the Arduino under test does, then have a way to pass messages to the test runner (PySerial, etc).

@AnonymousPenguin "bypass the Arduino libraries to build functions and send example data over the "pins." is what I did in the library discussed in my answer here.  It enables testing things like does Arduino light a LED in response to stimuli, i.e. temperature purely in software.  In other words, it's doing more than just "make sure it builds".

Newest version of Arduino ide has a command line interface to build and upload code. But you can obviously do it by makefile and avrdude.
Now, you have compiled your code BUT you need testing.
As simulator are complex,incomplete, expansive and.. Just a simulation, and because the chip are relatively cheap, building a board witch will make HW interaction AND check the results its the fastest and easiest way.
On that "special" board you may upload something like an interpreter witch take a test from the PC and execute it, something similar to firmata for arduino.
At least that is how I would build it.
And as far as I know there are no know implementation of this, even if I'm quite sure many industries should and probably do that.

As the creator of PlatformIO I would recommend you to look into it. It's a cross-platform code builder and missing library manager. It can build the same code for the many popular embedded development platforms and boards.
PlatformIO can be be integrated with many popular Continuous Integration (CI) systems (or your own). See documentation with examples.
Let's look into .travis.yml config/template for Travis CI:
language: python
python:
    - "2.7"

env:
    - PLATFORMIO_CI_SRC=path/to/source/file.c
    - PLATFORMIO_CI_SRC=path/to/source/file.ino
    - PLATFORMIO_CI_SRC=path/to/source/directory

install:
    - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

script:
    - platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N

Example
Integration for USB_Host_Shield_2.0 project. The .travis.yml configuration file:
language: python
python:
    - "2.7"

env:
    - PLATFORMIO_CI_SRC=examples/acm/acm_terminal
    - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA"
    - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback
    - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB
    # - ...

install:
    - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

    # Libraries from PlatformIO Library Registry
    # http://platformio.org/#!/lib/show/416/TinyGPS
    # http://platformio.org/#!/lib/show/417/SPI4Teensy3
    - platformio lib install 416 417

script:
    - platformio ci --board=uno --board=teensy31 --board=due --lib="."

Configuration file: https://github.com/felis/USB_Host_Shield_2.0/blob/master/.travis.yml
Build History: https://travis-ci.org/felis/USB_Host_Shield_2.0

If you are affiliated or associated with PlatformIO you should disclose this in your answer, or it may be flagged and removed as spam. Thanks!

One example of setting up Jenkins continuous integration for Arduino project can be found here: Continuous integration for embedded systems
The example shows how to build and upload image to Arduino and execute Selenium web tests (the system under test is Arduino-based web-server).

nice because it use some existing software witch is feature rich. but it seems to do only web testing; can you please expand the answer? also link-based answer are bad.

I wrote this test unittest framework for Arduino, since i could not find proper existing. While i did not write it for CI, it would be good fit for CI job, since it requires no hardware but can be ran on PC.
Running the CI jobs without the hardware has good sides and bad sides, good sides beeing that

No flashing, no hardware needed -> can be runned in parallel -> fast to check for example for every commit
No hardware issues influencing the tests -> no need to worry did this test just fail because my XYZ-hardware component is not stable

On the downside there is:

Its not testing the actual target code, for example your 'int' is 32 bits in your PC and 16bits in AVR.

“your 'int' is 64 bits in your PC”: you probably mean “32 bits”, or you are using some exotic OS.

You are right of course, thanks. I edited my answer to fix that.

note you can set up an in-home CI server with a cheap pc like a raspberry hooked up to an HW board and thus have a piece of the CI infrastructure running on real HW (while maybe keeping the default cloud CI for all that is software)

I've just put together a decent size writeup as an answer to this related question about an Arduino CI/unit testing framework I wrote that's finally mature enough to start talking publicly about.
The arduino_ci ruby gem supports both local testing and Travis CI integration (e.g. this build job for the Adafruit FONA library).
Some examples of how it integrates:

The DoSomething example library shown above, used to test arduino_ci itself
A practical example, testing a Queue implementation
A complex example, simulating a library that controls an interactive device over a SoftwareSerial connection as part of the Adafruit FONA library

I have an issue created for reporting sketch size but no work has been done on that.  It's also possible that I could parallelize the builds someday, but at the moment I'm not precisely sure how I'd do that.  Right now, the  most time consuming build step on Travis CI is downloading the Arduino IDE... parallel testing won't put much of a dent in that if every job needs to do that step.

I would advice to use the arduino eclipse plugin named sloeber sloeber.io of which I'm the project lead.
It integrates with version control and allows building on multiple platforms as it supports multiple configurations.
Though it is not yet idiot proof I have documented and demonstrated using unit testing of arduino code on the local pc using the google test framework.
Here is a link to a blog containing a presentation of how you can do it. http://blog.baeyens.it/#post25

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


text:
Op Amp Understanding + Holiday Lights Tutorial
I am following Jeremy Blum's tutorial for Holiday Lights: http://www.jeremyblum.com/2011/12/25/tutorial-14-for-arduino-holiday-lights-and-sounds
I am just trying to set up the circuit for one of the audio channels. I believe I followed the breadboard schematic. However, when I connect the Arduino the power, but without any audio input, the LED lights up. I would've thought that would not be the case.
Can someone help me correct my understanding here? Thanks.
Image of my breadboard: http://postimg.org/image/ibqfvezqp/

Did you try adjusting the trim pot to reduce the gain?

Per Jeremy Blum:

If the input doesn’t have a audio input plugged in, then it’s said to be “floating” and you >can’t really count on the circuit to do what you would expect. The audio input connection >introduces a known voltage (0 when no sound is playing) connection between the positive op->amp input and GND that we then amplify. Try connecting the input to GND and you should see >the LED turn off.

Source: http://www.jeremyblum.com/2011/12/25/tutorial-14-for-arduino-holiday-lights-and-sounds/comment-page-2/#comment-1373392


text:
Question about viability of building a Bill Counter machine
I have a need for a bill counter at my current job, but besides counting bills we also could use a machine to count admission cards.
The idea is to either buy a bill counter machine (like those that the Banks have), or make one from scratch by buying the parts.
Besides the bill counting feature i wanted to make it so that it also counts the certain number of cards, and check if they are either stamped or not.
My question is:
Is this possible?
If so, is it easier to just buy a arduino and use it with other parts (sensors, moving gears etc etc), or to buy a bill counter and just "crack" the OS?
Any insight would be appreciated!
PS: I am a 1st year Computer Science student, but i have 0 experience in programming in Arduino

I suppose an Arduino could be used as the brain of a currency counter.   Since you can buy a currency counter with UV counterfeit detection for under $250 (the model I picked for the link wasn't even the least expensive) I'm not sure this is a viable project.  It would cost way to much unless you are able to custom fabricate every metal piece needed in your own machine shop.

It's hard to think of a particularly good reason for chosing an Arduino for this task.  The classic ATmega-based boards are a bit short on memory for the kind of image comparison you would probably want to do, and the ARM-based boards are fairly pricey compared to the alternatives.  You could I suppose use one as a USB-connected paper-path motion delegate for something PC-based, but realistically projects where your design is going to be actively attacked aren't a great place to start, unless you are doing them only for learning purposes without envisioning real-world deployment.

There are many more things to consider than just put some parts together if you try to build a counter from scratch. Automated currency handling has come a long way to today's bill counters or any vending machines. You may perfectly handle the computing part of task with an embedded system like the arduino, but paper handling is an art of itself.
If you think of this task as a challenge to acquire and hone engineering skills, go ahead. It may be one of the best training tasks one can think of. But while you may learn a lot from this conundrum, you will propably end up without an usabale device. :)
You have to consider, there are subtasks in

mechanics
electronics
programming

which may include

paper handling (separation, traction, alignment)
pattern recognition
motor control
high speed sensors
signal detection and processing
error and fault processing and handling
motor and gear connection
bearings and mechanical substructure
user interface

and many more.
To modify an existing device solves a lot of mechanical problems in advance. But it may still be difficult to change the firmware of a bill counter to your needs.
You will have to

break into the system (may be impossible)
reverse engineer the firmware
understand the mechanical constraints
find a way to adapt the system to your needs.

A third way, which in my eyes is rather intriguing, is to take an existing bill counter, rip out the controller and try to plug in your own controller, e.g. an arduino. This gives you a real chance to reach your goal while still having the opportunity to learn a lot.

First of all thanks for the reply.
I really liked the idea of replacing the controller, but i have no idea where to start, could you link some sites where i can learn how to do it or maybe explain a little further ?

Hmmm, as I stated in my answer, this task touches various fields of science and engineering. So it is difficult to say, what you should learn first. Generally said: I don't have any clues about bill counters besides having seen one in action recently. So I don't have a link to a resource where you can get information about let's say: roughness of used dollar bills, or paper thickness detection with infrared. So I suggest: make a plan first. I'm going to add some further notes to my answer.


text:
Serial Data through Pin 13 LED
I am looking to utilize Pin 13 and an external LED to flicker as either the Rx or Tx LEDs do when Serial data is transferred through the Arduino. The existing code is all in real time to function with external buttons, so there can't be any delay.
I came across this link which seems useful, but I can't quite get it to read from Serial:
http://arduino.cc/en/Tutorial/BlinkWithoutDelay
Thanks in Advance

Software fundamentally does not do things without one or more clock cycles of delay, and the ATmega is not an FPGA which allows you to route signals to desired pins electrically.  If you want exactly the same data without delay, then don't use pin 13, but rather use the Tx or Rx pin.  If you merely want similar functionality, then either use a software serial on the pin to which your LED is connected, or write a custom Serial output routine which twiddles an LED pin every time it writes a character to the UART peripheral or services the UART Rx interrupt.

when you say "there can't be any delay" you are referring to the use of delay(ms); and other blocking code, and not "must happen the exact same moment" correct?

I think that pins 0/1 should blink similar to the TX/RX LEDs but not entirely sure. Might be worth it to see if that works and then let us know.

BrettM, your are assuming correct. When i connect and LED to 0 or 1, it's constantly lit, no change with data transfer, even though data is indeed flowing.

If you are going to use an external LED, then using software to make the LED blink when the RX or TX line is busy is a waste of your CPU.
Instead, simply connect the LED to the RX or TX line using a transistor as a buffer to prevent the current draw from messing with the serial signal.
To borrow an image from this answer to a similar question:

You can try omitting the transistor buffer, but the serial waveform will be altered, possibly to the point where data becomes corrupted. The transistor prevents the current draw of the LED and resistor from loading down the RX or TX lines.


text:
Serial.write and Serial.println return different values? Cannot use correct ones
I have a text file on an SD card, and I am trying to print the lines to the serial monitor.
This Code Works:
#include <SPI.h>
#include <SD.h>

File myFile;

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

  Serial.print("Initializing SD card...");

  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("c.txt");
  if (myFile) {
    Serial.println("c.txt:");

    while (myFile.available()) {
      Serial.write(myFile.read());  //THIS LINE RIGHT HERE
    }
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening c.txt");
  }
}

void loop()
{
}

However, if I replace the line Serial.write(myFile.read()); with Serial.println(myFile.read());, then the code doesn't return the correct lines.
It should return numbers similar to this (albeit 3000 of them):
564
564
564
564
564
564
564
464
564
664
564

If I use Serial.println it returns numbers like this (and it doesn't stop at 3000 lines):
13
10
54
54
52
13
10
53
54
52

And if I try to do int(myFile.read()) then the integer becomes the wrong numbers (returned by println), not the right ones (returned by write).\
How do I get a number returned by Serial.write(myFile.read()); to be an integer?

The text file contains the sequential ascii values that spell out the data, not binary data. println in printing the numerical value of each byte. For example, the 10's println prints are '\n' characters. write is printing the ascii character associated with the binary value (the new line). You need to parse the ascii characters into numbers.
Luckily for you the SD library inherits from the Stream class, so it will have the same parseInt function most often used to parse ints from the serial monitor.
You probably want to set myFile.setTimeout(0) first because the file isn't slowly getting characters from the serial bus, so the timeout would just slow you down.
Then you should be able to parse and print out the ascii integers with something like this:
int val = myFile.parseInt();
Serial.println(val);

I couldn't ask for a better answer!


text:
Where can I find a better pinout diagram for "Arduino Ethernet" board?
I'm looking for a complete pinout of the Arduino Ethernet R3.
I've found one here which is low quality, and seems not complete (where are the digital I/O pins?).

BTW, it was not a good idea for Arduino to name this board "Arduino Ethernet", as this is pretty useless for searching online :-(

... What? The digital I/O pins are the cyan ones...

The pinout is Arduino Uno compatible, except for pins 10-13

Clicking on the image on Arduino's site reveals a much higher resolution version.

@AnnonomusPenguin: Not sure what you mean. The low quality I 'complain about' is for the image in the question (board with pinout, not an image of the board itself), which is not on the Arduino site. Thanks anyway.

That's a better one from :
https://pinoutguide.com/images/arduino/ethernet.png
This one also presents the Arduino Ethernet R3 board and
has the extra I2C pins (SCK=A5,SDA=A4) next to the AREF pin.

The formal Arduino.cc website mentions, somewhat obscurely, that the Arduino Ethernet is pin compatible with Arduino Uno:

The Revision 3 of the board introduces the standardized 1.0 pinout

Except for pins 10-13:

Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet
  module and should not be used otherwise. This reduces the number of
  available pins to 9, with 4 available as PWM outputs.

The other difference is the onboard LED is connected to pin 9 rather than the Uno's pin 13:

On most other arduino boards, this LED is found on pin 13. It is on pin 9 on the Ethernet board because pin 13 is used as part of the SPI connection.

You can use any Arduino Uno pinout diagram as a reference, the one you have found seems to be pretty elaborated.

Except that it does: "The Revision 3 of the board introduces the standardized 1.0 pinout..."


text:
Can I replace Atmega8 with Atmega328 in my freeduino board?
Can I replace Atmega8 with Atmega328 in my freeduino board?
If so, let me know the steps needed.

Shouldn't be a problem. Some later versions already have a ATMega168 instead of the ATMega8. All three are pin-compatible.
In the arduino IDE you should however select a different board (one with a 328, like the UNO). That way the compiler knows the target MCU is the 328, and not the 8.

Not all registers are the same though. But the arduino platform takes care of these difference for you.


text:
data type error on sensor data to ethernet client
I'm having a hard time debugging this piece of code, and i'm hoping someone can point out where i am making the mistake.

My serial output is:
connected
GetData()
got data...
next stage...

I've tested with a simple network client that loops sending a hello world, and it works fine. Every time this code halts after attempting to send a value to the client. I know that  getData() is causing the issue, but i cannot work out why, or how to best resolve it.
(apologies for the code dump, i want to be thorough)
#include <LiquidCrystal.h>
#include <dht11.h>
#include <SPI.h>
#include <Ethernet.h>
dht11 DHT11;
#define DHT11PIN 8

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server(192,168,1,100);
IPAddress ip(192,168,1,50);
EthernetClient client;

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

const int trigPin = 6;
const int echoPinOne = 7;
const int echoPinTwo = 8;
const int echoPinThree = 9;
const int echoPinFour = 10;

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

  //Network
 if (Ethernet.begin(mac) == 0) {
    Serial.println("DHCP FAIL");
    Ethernet.begin(mac, ip);
  }
  delay(1000);
  Serial.println("connecting...");
  lcd.setCursor(0, 0);
  lcd.print("connecting");
  connect();
}

void connect(){

    if (client.connect(server, 8080)) {
    Serial.println("connected");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("connected");

    client.println("hello server");
    client.println();
    delay(500);
    lcd.clear();
  }
  else {
    Serial.println("connection failed");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Connection Failure");
  }
  delay(500);
}

void loop() {

   //network
  if(!client.available()){
    Serial.println("lost connection!-restart");
    lcd.println("Disconnection");
    client.stop();
    connect();
  }
  else {

    int inp[5];
    getData(inp);
    Serial.println("next stage...");
    char *output = (char *) &inp[0];
    client.println(output);

    client.println("first");

    Serial.println("sent first...");

    //here repeats the same process for the other sensors - omitted for clear reading

  }
   //end network

   delay(500);
}

void getData(){

Serial.println("GetData()");
long durationThree, inchesThree, cmThree = 0;
long durationOne, inchesOne, cmOne = 0;
long durationTwo, inchesTwo, cmTwo = 0;
long durationFour, inchesFour, cmFour = 0;

//SENSOR ONE
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPinOne, INPUT);
durationOne = pulseIn(echoPinOne, HIGH);

delay(100);

//SENSOR TWO
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPinTwo, INPUT);
durationTwo = pulseIn(echoPinTwo, HIGH);

delay(100);

//SENSOR THREE
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPinThree, INPUT);
durationThree = pulseIn(echoPinThree, HIGH);

delay(100);

//SENSOR FOUR
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPinFour, INPUT);
durationFour = pulseIn(echoPinFour, HIGH);

//DISTANCE CALCULATION
cmOne = microsecondsToCentimeters(durationOne);
cmTwo = microsecondsToCentimeters(durationTwo);
cmThree = microsecondsToCentimeters(durationThree);
cmFour = microsecondsToCentimeters(durationFour);
//Serial.println("sending...");
//char *out = (char *) &cmOne;
//Serial.println(out);
//client.println(out);
//Serial.println("sent!");      used this to test - same issue

Serial.println("got data...");
inputBuf[0] = cmOne;
inputBuf[1] = cmTwo;
inputBuf[2] = cmThree;
inputBuf[3] = cmFour;

}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

The code you posted is performing incompatible casts and by thus is sending garbage to client.println.
There is no automatic conversion in C/C++ from an array of integers (int inp[]) or longs, to a C style string char *. A C Style string should end with null terminator \0, and the one in your code doesn't. For example, in this line:
char *output = (char *) &inp[0];

The inp[0] contains the first integer. The expression &inp[0] contains the address of that integer in memory.
Thus the cast to (char *) will yield a malformed C style string, since it will not end with a null terminator, and more important, will not contain the data you expect it would (this cast is saying - "hey, compiler, note that the address of that int is actually the address of a C style string").
You can, however, utilize the String type constructor that receives int/long, and send the duration in order, something similar to:
        void getData()
        {
            ... // rest of the code here
            client.println(String(cmOne));
            client.println(String(cmTwo));
            ... // etc.
        }

I believe this is what i've been looking for! i'll test later tonight when i get to the project but i'm 95% sure this is correct :) thank you!


text:
Multiple upload/ Synchronization problem
I am trying to do an experiment with Arduino Uno r3 board plus a 2-channel relay shield. What I need to do is to alternatively turn on and off the relay shields. So, it requires multiple compile and upload of the program to assign values to corresponding pins. What I have seen by now is that uploading the program to Arduino is a kind of painful process and it requires nothing to be connected to pins 0 and 1 to prevent synchronization errors. So, I was wondering how I can do my experiment without having to mount/unmount relay shield each time I want to upload a new program into it.
Thanks in advance

Would it be possible to just add some other kind of input to change what your sketch does while it is running without re-uploading?

Well, you can write a program that takes numbers out of Serial input.
int pin1 = Serial.parseInt();
int pin2 = Serial.parseInt();
// etc., etc.

Simple.


text:
Why doesn't this motor turn?
When I upload the code, the DC motor makes a humming noise, but doesn't turn.
//2-Way motor control

int motorPin1 =  5;    // One motor wire connected to digital pin 5
int motorPin2 =  6;    // One motor wire connected to digital pin 6

// The setup() method runs once, when the sketch starts

void setup()   {
  // initialize the digital pins as an output:
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
  rotateLeft(150, 500);
  rotateRight(50, 1000);
  rotateRight(150, 1000);
  rotateRight(200, 1000);
  rotateLeft(255, 500);
  rotateRight(10, 1500);
}

void rotateLeft(int speedOfRotate, int length){
  analogWrite(motorPin1, speedOfRotate); //rotates motor
  digitalWrite(motorPin2, LOW);    // set the Pin motorPin2 LOW
  delay(length); //waits
  digitalWrite(motorPin1, LOW);    // set the Pin motorPin1 LOW
}

void rotateRight(int speedOfRotate, int length){
  analogWrite(motorPin2, speedOfRotate); //rotates motor
  digitalWrite(motorPin1, LOW);    // set the Pin motorPin1 LOW
  delay(length); //waits
  digitalWrite(motorPin2, LOW);    // set the Pin motorPin2 LOW
}

void rotateLeftFull(int length){
  digitalWrite(motorPin1, HIGH); //rotates motor
  digitalWrite(motorPin2, LOW);    // set the Pin motorPin2 LOW
  delay(length); //waits
  digitalWrite(motorPin1, LOW);    // set the Pin motorPin1 LOW
}

void rotateRightFull(int length){
  digitalWrite(motorPin2, HIGH); //rotates motor
  digitalWrite(motorPin1, LOW);    // set the Pin motorPin1 LOW
  delay(length); //waits
  digitalWrite(motorPin2, LOW);    // set the Pin motorPin2 LOW
}

Why doesn't this work?
Update:
I plugged it into a different port (5v) as it is a 5v motor, but now it only turns left, not right. It just hums when it goes right.

If you want to close this, close it is a duplicate of something.  It is anything but "unclear" - in fact, the question is rather admirably complete in presentation compared to the relatively beginner technical mistake being made.  And while no specifications have been provided for the motor, the fact of the matter is that there are very few which would work directly connected like this, so that's almost irrelevant to understanding the problem.

This question does not belong on the Arduino site.  It should be sent back to EE stack exchange (where it was quite properly asked in the first place), as the issue of motor drive electronics would be exactly the same with any small microcontroller, Arduino or otherwise.  Politically motivated question dumping needs to stop.

NEVER directly connect a DC motor to an Arduino Pin! I am surprised you did not burn your Arduino yet...

@jfpoilpret why not?

For the reason, just check the first 2 answers to your question!

@ChrisStratton yes, this does seem like EE could keep it. However, just because it could be on topic there doesn't make it off topic here. Bash scripts are all OK on Super User, Stack Overflow, Ask Ubuntu, and Unix and Linux.

When a poster asks something on a site where it is entirely appropriate, the mere fact that it could be allowed else where if originally asked there is no justification for moving it - this question has been dumped purely based on the bias of many EE users against beginner questions.  Being a dumping ground for EESE bias is not the purpose of the Arduino site - it is an abuse you need to firmly stop.

Although the question may provide the beginning of an answer on EE.SE, an answer here may be better fitted, e.g. using the right components, according to Arduino max pin current, which is specific. Personally I don't see much issue with moving this question here.

The problem with moving the question here is that it becomes divorced from primary technical expertise and so receives poorer answers.  Similarly, any good answers it might receive fail to contribute to the pool of knowledge on the site intended to handle questions of this type (there's nothing relevantly unique about an ATmega used as an arduino)  But mostly, the problem is that it was moved out of political bias.

The IO drivers of most common logic chips or microprocessors such as the ATmega on your Arduino are nowhere near strong enough to drive typical electromagnetic motors.
To drive a motor, you should use a higher current switching device - a standard solution for bidirectional control being an H bridge part such as a TB6612FNG, L293D, L298, etc.
These are commonly sold on "motor shields" which you can plug into your Arduino, if you want to experiment with the concept before building something (and if you do want to build something, reviewing such a working schematic first would be a good idea).
You can in theory put an L293D or its DIP-packaged work-alikes on your breadboard, but you will need some care to get it right, especially if you use one of the other parts which requires external catch diodes.
Finally, you should not be powering most motors from the Arduino's onboard regulator or a USB port, but rather should use an external power supply.
=============
Responding to your edit, by  changing connections to place the the motor between one pin and the 5v supply, you have done two things:
1) You have made it so that the voltage difference across the motor can be applied in one direction only, therefore it can only rotate in one direction.
2) You have made it so that only the N-channel MOSFET in an output driver is involved in powering the motor.  That change is almost a useful idea, as N-channel devices are in fact much more capable than P-channel devices of similar dimension (and practical capacitance, voltage rating, and other tradeoffs) due to the greater mobility of negative charger carriers.
But this is still not really a solution, as it is unlikely that your motor's current rating is within even the current sink rating of the N-channel side of the ATmega output.
If you want a simple, unidirectional motor control, you could pursue this idea using one external N-channel MOSFET (or even a biploar NPN power transistor, which will be less efficient but also less delicate) to connect the unpowered side of the motor to ground.
If you want bidirectional control, you will need either + and - power supplies, or four external switching devices taking the roles of the low current N-FET and P-FET totem poles inside each of the two on-chip IO pin drivers you started with.

This is a huge simplification of @Chris Stratton's post, for beginners.
To put it simply, the power that runs your motor is going through your arduino. Your arduino is not made to carry that sort of power.
What you want is an H-Bridge - see https://itp.nyu.edu/physcomp/labs/motors-and-transistors/dc-motor-control-using-an-h-bridge/ - the H Bridge is specially made to carry the power needed.
Note that this page is for a 9v motor, not a 5v motor like yours - you will need to find a more appropriate power supply than a 9v battery (or, you need to find a 9v motor). If you try to power it through USB, you will be drawing the power through your computer - you may damage it!


text:
Powering Infrared and Sonar sensors using BEC
I'm new to Arduino. I'm using Arduino Mega 2560 board & MATLAB Simulink-Arduino support package and trying to integrate Maxbotix Sonar and Sharp IR sensor for my class project. When I powered single US sensor from Arduino 5V output, the readings are fine. However, when I tried to power IR sensor in parallel with US sensor, IR readings are fine but US readings fluctuate.
So, I tried powering the sensors using BEC (5V-3A). The readings for both sensors are fluctuating(extremely noisy). From the specification mentioned by manufacturers, Maxbotix US sensor draws 2mA of current, whereas IR sensor averagely draws 20mA. Is there any way to solve this problem?
Thank you.

I've managed to solve the problem. When external power supply is used to power multiple sensors, connect the GND of that supply with that of the Arduino GND input. For more details, refer to the link below.
http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html


text:
What do these pins on the Uno do?
I've been wondering for a long time what these pins, labeled ICSP and blank, do.

I can't seem to find a diagram that explains them, so I've been wondering:

What are they for?
Are they GPIO, or do they do something special?
How can you use them?

Thanks for the help.

They're for programming, as well as carrying the non-select signals for SPI. The right one is for programming the main MCU, the left for the USB communication MCU. You should almost never need to use them unless you need to write a bootloader to a new chip or change the fuse or lock settings on them.

I'd like to add that the pins on the right header are VCC, GND, RESET, and Digital pins 11, 12, 13. So it's not like you can use them if you run out of digital pins.

There is a case where a "normal" user use the once at the back. That is when you use a shield that connects to those pins. An example of such a shield is the ethernetshield. The tag (that is what these 6 pins are called) at the end is actually added to fix a compatibility issue between the mega and uno.


text:
object with multiple instances with internal data store separate for each instance
I'm trying to keep track of a timer, and the internal variables seem to be overrun by one another.
I just want two instances of the Output class, which can keep track of the _elapsed_time so I can check if the time elapsed. It's a poor-man's real-time for a game. I know there are libraries available and I'm planning to use them, but I would really appreciate knowing what's going on here: I want a buzzer pin, and status led pin to 'blink' at different intervals. They both work individually, but when I have them both uncommented they work somewhat serially...
#include "Arduino.h"

#include "MTC.h"

#include <SoftwareSerial.h>   //Software Serial Port

//HARDWARE SETTINGS
#define PIN_STATUS                  13
#define PIN_BUZZER                  A2

Output *STATUS(0);
Output *BUZZER;

void setup()
{
    Serial.begin(9600);
    STATUS = new Output();
    STATUS->Begin(PIN_STATUS, STATE_OFF);
    BUZZER = new (Output) Output(3);
    BUZZER->Begin(PIN_BUZZER, STATE_OFF);
}

void loop()
{
    static bool run_once = true;

    if (run_once == true)
    {
        run_once = false;
        Serial.print("Running");
        Serial.flush();
    }
    delay(250);

    //Serial.println("still running");

    STATUS->SetStrobe(3000);

    //BUZZER->SetStrobe(4000);

}

and class:
#ifndef MTC_h
#define MTC_H

typedef int OUTPUT_STATE;
OUTPUT_STATE STATE_OFF = 0;
OUTPUT_STATE STATE_ON = 1;
OUTPUT_STATE STATE_STROBE = 2;

class Output
{
private:
    int _pin;
    OUTPUT_STATE _last_state;
    unsigned long _cycle_duration;
        unsigned long _last_elapsed;

public:
    Output();                                           //constructor: set pin data store
    void Begin(int pin, OUTPUT_STATE state);                                //set hardware to output and defaul state
    void Set(OUTPUT_STATE state);                               //toggle operability
    void SetStrobe(unsigned long duration);                     //strobe operability
};

Output::Output()                                    //constructor: set pin data store
{

}

void Output::Begin(int pin, OUTPUT_STATE state)
{
    _pin = pin;
        _last_elapsed = millis();
    pinMode(_pin, OUTPUT);
    digitalWrite(_pin, state);
    _last_state = state;
}

void Output::Set(OUTPUT_STATE state)
{
    if (_last_state != state)
    {
        digitalWrite(_pin, state);
        _last_state = state;
    }
}

void Output::SetStrobe(unsigned long duration)
{
    static OUTPUT_STATE _last_strobe_state = STATE_OFF;

    unsigned long elapsed = millis() - _last_elapsed;
    if (elapsed >= duration)
    {
        if (_last_strobe_state == STATE_OFF)
        {
            digitalWrite(_pin, STATE_ON);
            _last_strobe_state = STATE_ON;
        }
        else
        {
            digitalWrite(_pin, STATE_OFF);
            _last_strobe_state = STATE_OFF;
        }
        _last_state = STATE_STROBE;
        _last_elapsed = millis();
    }
}
#endif

Your Output::SetStrobe() is wrong, it uses a static variable (_lasr_strobe_state) that is thus shared between all instances of OUTPUT, which is NOT what you want.
You have to change it into a non-static member of class Output instead:
class Output
{
private:
    int _pin;
    OUTPUT_STATE _last_state;
    // NEW member here!!!
    OUTPUT_STATE _last_strobe_state;
    unsigned long _cycle_duration;
        unsigned long _last_elapsed;

public:
    Output();     //constructor: set pin data store
    void Begin(int pin, OUTPUT_STATE state);//set hardware to output and defaul state
    void Set(OUTPUT_STATE state);            //toggle operability
    void SetStrobe(unsigned long duration);  //strobe operability
};

Then you initialize it in the constructor:
Output::Output():_last_strobe_state(STATE_OFF)
{

}

And you remove it (static declaration) from method SetProbe (the rest of the method does not change):
void Output::SetStrobe(unsigned long duration)
{
    unsigned long elapsed = millis() - _last_elapsed;
    if (elapsed >= duration)
    {
        if (_last_strobe_state == STATE_OFF)
        {
            digitalWrite(_pin, STATE_ON);
            _last_strobe_state = STATE_ON;
        }
        else
        {
            digitalWrite(_pin, STATE_OFF);
            _last_strobe_state = STATE_OFF;
        }
        _last_state = STATE_STROBE;
        _last_elapsed = millis();
    }
}

This is not a real answer, as @jfpoilpret already gave a perfectly valid
one. Just a few observations and suggestions from looking at your code.
I write is as an answer only because it is too long to fit in a comment.

The member variable _cycle_duration is not used. You could remove
it and save a couple of bytes per Output instance.
if (run_once == true) is equivalent to if ((run_once == true) ==
true). They are both considered bad style. Preferred style is to
just write if (run_once).
On the Arduino, it is generally good practice to avoid dynamic
allocation whenever possible. Of course, it is not always possible,
but in this instance it is quite easy: declare STATUS and BUZZER as
objects instead of pointers (as in Output STATUS;), then replace
-> by a single dot (.).


text:
Arduino Serial Hex Values
Apologies if I have missed a relevant post somewhere, but have search for days to try figure this out...
I have written some C# code to send a Byte Array over Serial from my PC to an Arduino Nano board (Through a USB to Serial Converter)
Why would I not receive the same HEX Values (in the Arduino serial monitor) as the Values I sent?
(The Values should be the HEX for numbers 0 - 9)
C# Code:
if(!serialPort1.IsOpen)
    {
        serialPort1.BaudRate = 9600;
        serialPort1.DataBits = 8;
        serialPort1.StopBits = System.IO.Ports.StopBits.One;
        serialPort1.Parity = System.IO.Ports.Parity.None;
        serialPort1.PortName = "COM" + cbCOMPort.Text;

        serialPort1.Open();
    }

    byte[] ByteArr = new byte[10];
    ByteArr[0] = 0x30;
    ByteArr[1] = 0x31;
    ByteArr[2] = 0x32;
    ByteArr[3] = 0x33;
    ByteArr[4] = 0x34;
    ByteArr[5] = 0x35;
    ByteArr[6] = 0x36;
    ByteArr[7] = 0x37;
    ByteArr[8] = 0x38;
    ByteArr[9] = 0x39;

    serialPort1.Write(ByteArr, 0, ByteArr.Length);
    serialPort1.Close();

Arduino Code:
void loop()
{
while (Serial.available()) {
delay(250);

byte thisByte = Serial.read();

Serial.print(thisByte,HEX);
Serial.print(" | ");
}
}

Values received in Arduino Serial Monitor:
D6 | B6 | 96 | 76 | 56 | 36 | 16 | F6 | 8D | 0 |

COMPLETE ARDUINO CODE WITH BLINKING LED TEST CODE
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
while (Serial.available()) {
delay(250);
// get the new byte:
byte thisByte = Serial.read();
// add it to the inputString:
//inputString += char(intChar);

if(thisByte == 0x30 || thisByte == 0x39)
{
digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(50);             // wait for a second
digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
}
Serial.print(thisByte,HEX);
Serial.print(" | ");
}
}

Because you have a serial baud rate mismatch? Because you have a pointless delay() in your serial receiving code? Try showing all your Arduino code - it might help us diagnose it.

@Majenko, I have Tripple Checked the baud rate, and the "pointless delay()" is there from testing in frustration - But surely has no effect on the comms.
The C# code is everything, below is the complete Arduino code, with a little added, to show you the reason for the delay - I added a blinking LED out of frustration, thiking that maybe because I was talking to the Serial PINs and had the USB connected for the Serial Monitor at the same time, it could cause an Issue (I need to add here that I am a Newbie to Arduino)

Added Code mentioned to the Original (Edited) post

@Majenko The examples above work if I send from C# to Arduino through the COM3 usb port (USB on PC to USB on Arduino) but does not work when sending to the Arduino Nano through the Serial PINs from the PC's USB to Serial converter.

Ah, we may be getting somewhere now.  What USB to serial converter?

Standard cable type from PC store.. USB one side, DB9 other side (Have tried two different ones), I then wired the pins 2,3,5 (TX,RX,GND) to my breadboard.

Ah well, there you go then.  Firstly, you may have killed the Arduino's serial pins, and secondly that cable is not suitable for direct connection to a microcontroller. You need an RS-232 to TTL converter chip like a MAX232, or the right kind of cable (USB to TTL UART), like an FT232 or PL2303 cable.


text:
Driving conveyor belts using Arduino Unos
We are planning to drive conveyor belts with Arduino Unos using stepper motors. We are planning to use easy drivers, so that we control at least 3 motors with one Uno. Currently we are still at an initial stage, we are designing and planning the setup of conveyor belts. But what I wanted to ask was, regarding the coding.
How would I code so that say the belt moves forward for x seconds, and then after time it moves backwards for y seconds. Any basic idea on the code would be great thank you. I could do the basic code, but I just need help with timers part.

Steppers may not really be the best motor technology for that, but they are conceptually simple.  Time based control is extremely simple, but often poorly suited to the real world. However, if you wanted to do it, and are using stepper motors, a possible way would be to figure out your steps per unit time, and issue that many steps.  In reality, stepper systems with mass will need acceleration and deceleration, so you'd have to work that in too - maybe instead of time, you could work in terms of a desired total number of steps.  Don't forget operator safety!

Have you checked this out 1 link & 2 link

The clocks of the Unos have only ~ 0.5% accuracy. This may be an issue if you need several of them working in unison.

In regards to time control use the mills() function.  You start by creating an:
unsigned long lastTime = millis();

Then later in the program create another variable:
unsigned long currentTime = millis();

Next Compare the two:
unsigned long elapsedTime = currentTime - lastTime;

For the most part I normally just shorten the last two lines into one:
unsigned long elapsedTime = millis() - lastTime;

Stepper motors are not needed if you are just doing timed control, but the advantage of stepper motors are you can move them with pin point accuracy based on the number of steps per rotation.  If there are 60 steps per rotation then 360 degrees per rotation/ 60 steps per rotation and you get that each step is 6 degrees.  So in order to turn the motor 6 degrees you would turn it 6 steps.  This also allows you to keep track of angular velocity.
When I control motors I normally create an array of the different parts of the cycle then loop through the array.

yeah we are going for stepper motors because in some cases we need the conveyor to oscillate back and forth, so we would need to play with time ofcourse and also accuracy of steps also, that it needs to oscillate x steps forward for y seconds then reverse x' steps backwords for y' seconds. So I think stepper motors would be a good choice here. We will not be using an external sensor to detech the change motor speed or steps. It will all be done in coding only. Also with stepper motors we can utilize full 360 degree angle, which would be required, unlike servo motors which only go upto 180.

Did my answer answer your question? If so please mark it as the answer.  If not, how can I improve it to help you best?

@Joel..yes I was replying to you. we are still in process of developing the basic automation idea. The electronics part of driving motors etc comes later on. So I will surely refer to you..once we start electronics part. I hope you read my comment, you reckon stepper motors would be a good choice??? Thanks

Steppers motors will work well with a conveyor.  In order to get accurate position data you will need to convert steps to distance moved which is centered around your gearing.  Make sure to check there torque specs, depending on the conveyor size you will need larger stepper motors which require larger hardware to control them.

@joel...yeah ok, let us see how it goes, I will contact you once the prototype is ready. I reckon I posted a bit early, but anyways stepper motors then it shall be...mind you for prototyping we will be using arduinos unos just to check the feasibility and the results..for the original setup we will probably use PLC..


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

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

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

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

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

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

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

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

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

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


text:
H-Bridge vs Motor shield for the arduino
Assuming we wish to control a small toy car with an arduino - meaning spinning the right and left wheels forward and backward and being able to break and control the speed, where each wheel has it's own engine (but of course two engines on the same side will run on the same speed and direction).
We saw we have two main options - Buying and wiring up a H-Bridge or buying a motor shield (which is based on one).
Are there any advantages for using a motor shield?
Thanks in advance.

The shield is just plug and play. The bare H-bridge requires a bit more work. E.g. you'd have to add some capacitors. You can look at the schematic of the motor shield to see what other components you need (not much).

If I were a beginner, I'd go with the Motor shield.
I'm even personaly using the one from DfRobot, which as @Gerben said, is just plug and play.
It also allows you to select the input power for the motors, which can be either from the 5V Arduino pin or from an external battery. This is pretty convenient if you need more than 5V to power up your motors. It can also support 2A of current draw, which is more than enough for small arduino toy cards.
Here is the shield: https://www.dfrobot.com/index.php?route=product/product&product_id=1180&search=2A&description=true

Thank you (and Gerben), I've decided to go for the motor shield, also because it allows me to see the current the motor is using so I can easilly detect whether it's stuck or blocked by something.

Glad I could help :)

While not unworkable, an L298 based board like that, or any with a bipolar bridge, is a relatively poor choice for a battery powered device as there will be substantial loss across the transistors (essentially one of your cells will go just to that).  MOSFET based bridges such as the TB6612FNG work much better with low voltage supplies, and are sold on modules as well.


text:
where to syphon off voltage from a 25 pin serial?
I have a mircocontroller that's looking to be powered by a 5v source.
I am trying to 'cypher off' some of this power from a 25 pin serial port, which is being powered by a constant power source.
Are there any pins that could give me that sort of voltage, or enough to power the board?

Please note, I'm not an electrical person at all, and so hope this is actually possible (otherwise my 3 months + program's work doesn't really add to anything).
I've tried a 9v battery, but it didn't seem to hold its charge?
I'm reading these labels going "what the ..." so you can probably tell coding the board wasn't the easiest, either.
Edit History

I would like to clarify this is an existing serial lead
I understand this may be deemed verging off topic, but due to the need to 'power' a microcontroller, I thought this could be answered here
If this isn't possible, (as an alternative, possibly) would a 9V/battery be able to power this board reliably for around 2-3 weeks?

Pins 11/18 might be NC so you could add your own adapter on the other side to send power through unused lines. If not, the only real thing I can see is using pin 9 and a regulator. I'm not sure how much that pin is rated for, though. I probably won't damage anything with 100 mA though....

@AnnonomusPenguin: Sorry if this is a stupid question, but what'd you mean by a 'regulator'. Like, i know what it means in English, but physically what?

I meant using the onboard linear regulator. When you connect a power supply to VIN or the black power jack that's over ~7.5V the Arduino converts that to a 5V for it to use. In this case, you might be able to connect pin 9 on the serial wire to the VIN pin on the Arduino and the ground wire on the cable to the GND pin on the Arduino and it would convert it to 5V for it to use.

You need 5 volts; A serial port uses higher voltages (usually 12v but apparently there is some latitude). A voltage regulator is a circuit that provides a stable 5 volts (in this case) from a higher and not necessarily constant voltage. (For completeness, there are also regulators that provide a higher voltage than their source, but that isn't what you need here).

It is unclear from your question whether you are trying to get power from an existing serial port, or merely use it for transport. The diagram you posted MAY have been relevant 40 years ago, but NO  current microcomputer equipment would support this - indeed this is why most equipment uses a 9 pin connector, and even these are rare. One thing that is clear is that you do not understand the interface. Even in the good old days you COULD NOT derive power from serial. Equipment no longer supports the voltages in the standard, which was meant to operate over 1000m.

@Milliways - no, the person who does not understand the interface is you.  Drawing small amounts of power from serial interfaces was quite normal.  It's a moot point though, as this question is not on topic for the Arduino site.

@ChrisStratton: It's in that grey area of topicality, since it's about powering the board from serial. So, i personally would agree there is an iffy point. But I hope this could be solved?

This is off topic because it is not asked about an Arduino, and because nothing sold as an "arduino" would be particularly suitable for this use.  Your question belongs on EESE.

You should be able to use pin 7 for negative, 9 as positive, this gives you 12 volts.
YOU MUST NOT HOOK THIS UP DIRECTLY to the arduino, connect it to a plug for the power jack (right of the USB connection).
If you are using a USB -> serial adapter, then the voltage may be 5v, but don't count on it.
Of course, USB is always going to be better!
PS - if you draw more power than the serial port is rated for, you will probably destroy the card. In most cases, this will be the motherboard. You are unlikely to be able to find out what it is rated for (look for Amps or A, or milliAmps  mA, or microAmps uA). The Arduino (with NO inputs or outputs, and idle) running from a 9v battery will draw about 50 milliAmps.

No.  You are quite unlike to "destroy the card" by drawing more power, as the port drivers simply can't supply much power to begin with, and I/O drivers are typically designed to be robust, because people do silly things like wire up mistaken cables, using straight cables where they should use null modems, or null modems where they should use straight cables.  The 1488 data sheet says "current limited" and the MAX232 says output short circuit duration unlimited.

That makes a lot of sense :) I thought it better to err on the side of caution. It also encourages checking specs, which is a good habit to get into.

@AMADANONInc.: I can't seem to 'get' a voltage from pin 9... I'm guessing the 'other end' either doesn't connect to anything, or doesn't carry a voltage?

A 25 pin serial cable doesn't have to be connected to anything standard.  I often used 25 pin serial cables that only had 3 wired pins (2, 3, and 7).  That is sufficient for software flowcontrol serial communications.  If the equipment on the other end doesn't wire up pin 9, then you can't use it.

In a lot of further research, I have discovered that 'It doesn't really matter' what the serial port diagram says, since in 25 pin serials (and 9 pin D-subs), it all depends on the circuit at the other end, showing which wires are actually 'connected', or 'used'.

I managed to get some current from +pin 6 -pin 5 in which allowed me to draw some current, but have chosen to go with a (PP3?) 9v battery instead due to its reliability.

So, in conclusion to this question, there isn't a specific answer, since it all depends on how the serial at the other end is wired.
It seems to me that in my case, there were minimal wires actually connected, so I was forced to look for other means of connecting to a 'reliable' power source.


text:
Arduino Uno synthesizer - Line Level (audio) output to mixer/amplifier
Is using PWM tones from Arduino amplified by a HiFi amplifier safe? Can I damage the amplifier or speakers because the PWM signal is not a "real" audio signal? Taken in consideration that I do not clip the signal and using a RC Low Pass Filter to filter out inaudible frequencies and using a LM386 amplifier chip to amplify and control the volume?
I am developing a synth/sampler project based on the Arduino Uno r3. This is my first electronics project ever and because of that reason I have some questions which I can't find a definite answer for on internet.
The synth has two function. It has a tone generator using the ToneAC library. With code I have mimicked LFO and VCO functions, using potentiometers I can adjust the frequency and LFO speed realtime. The other function is that I can trigger samples stored on a SD card using the TMRpcm library. The lowest frequency which can be played is 100hz and the highest 3100hz.
The device will be used in nightclubs on high end sound-systems and PA. I am afraid I will damage the equipment with my device because I do not send a pure audio (AC?) signal.
Currently the flow is like this:
PWM output (pin 9, 10) -> voltage divider to 2.5v -> RC Low Pass Filter 15Khz -> LM386 amp with volume control -> mono jack output -> mixing desk -> amplifier -> speakers
(the TMRpcm and ToneAC library share the same pin (9), I have fixed this by disabling the TMRpcm when the ToneAC is playing and vice versa. The mono jack is wired as follow. pin 9 goes to plus side of mono jack output, pin 10 to negative side. The TMRpcm pin 9 also needs to go to plus side of mono jack output, and mono jack negative needs to go to ground. Because I disable the ToneAC at that time I consider port 10 grounded because it not generating any sound so there is no signal/voltage running out of it, aka the IO pin is set to LOW)
I am hoping that using the voltage divider I am within range of the Audio Line levels of a default mixers Line-IN (like Pioneer, Behringer, etc). The RC Low Pass Filter is used to filter of inaudible frequencies and clean up the sound a bit, the LM386 audio amp is used to amplify the signal and (hopefully) make it a real audio signal.
Because I lack a lot of knowledge in this field and because I do not own a oscilloscope I can't say for sure if my output signal is harmful for the equipment and was hoping to get some guidance on my project on this forum.

Questions on stack exchange forums get better answers, the more specific you can make your question. Asking for guidance doesn't help someone know how to help you and the responses are likely not to be well focused. Also, this question sounds more about audio electronics than Arduinos, even though you're using an Arduino host. If so, it may be a better fit for the Electrical Engineering stack exchange site.

Point taken, I've redefined the question

In theory, the peak signal accepted from your amplifier should be 0.894V p2p if you want to rescpect the common -10dB signal strength/level. I don't know why you would want to have a 5V to 2.5V "voltage divider" in the first place, but in any case if you use that you already limit the current probably enough, it all depends on the resistor values used.
Using the LM386 amplifier is also simply not required at all, since the Arduino is already providing more than enough power. If you want to tune the volume at that stage, simply combine all functions (volume, low pass and current limit) by connecting the 5V PWM output thru a resistor (eg. 4k7) to a POT (eg. 1k) in parallel with the capacitor (eg.2n2) would give you approximately what you want. Then to remove de DC component, add a series capacitor (eg. 1uF) and you're all set. You may still hear a "click" when you connect it to the amplifier though, so keep the faders low when connecting.
Of course you can adapt the values quite liberally, but these values are both safe and should be close to what is needed (cutoff 15kHz, Vpp 0.88V max).

Thanks for the detailed answer. I already found out that I need to pass the signal through a 10uF capacitor so it looks like the +/-2.5V AC signal. Send that through a resistor divider and bring it down to +/- 1V (line level) for feeding into audio amplifier. LM386 is indeed not necessary. This should do the trick :)

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


text:
Connect Arduino to Galaxy S2 using USB OTG
I want to connect an Android Galaxy S2 phone to my UNO Arduino using USB OTG functionality.
I can upgrade/root the android to any version I want. My goal is to be able to communicate between the devices (send/receive data).
I've tried to search for whether that's possible but found conflicting answers whether Galaxy S2 and the Arduino UNO would be able to be connected this way.
Anyone knows whether this is possible? If yes - Do I need to do anything special - such as rooting the device, flashing it to a certain rom or something like that?
Thanks in advance!

This is off topic here, as it hinges on Android capabilities and development, not Arduino.  The proper site is stackoverflow itself, where you will find it has essentially already been answered.

@ChrisStratton I disagree about this being off-topic here. While it may be primarily an issue for the Android side of things, I think it's still a relevant question about the practicalities of using Arduino.

No.  Given how the SE system works, it's off topic here because as fundamentally an android question it is already answered many times on SO.

If you use a bluetooth serial module - e.g. google hc 06 - you can do it wirelessly. I have a had good results with this - you can hook it up to pins 0 & 1, then use the stock arduino serial code. Probably not a good idea to hook up to both the bluetooth module and the USB (e.g. for programming) at the same time, they may interfere with each other.

Method 1. Basically you do not need root permission to communicate over USB. I am making app for Android for my project and using this FTDriver
Method 2. If you are not programming in JAVA then you can try third party apps like:

Arduino Uno Communicator

Uno doesn't have FT232 chip so I found it a bit harder. So instead I have FT232 chip and use SoftwareSerial.
Method 3. To communicate with Arduino you can use Bluetooth with HC-06 module. There are lots of third party apps to connect and send/receive data. Bluetooth Terminal

In my opinion, you have to use this shield to do this: http://arduino.cc/en/Main/ArduinoUSBHostShield
We can't plug in to use Flash Memorys into Android Phones micro USB via OTG Cable. I guess, tablets and maybe phablets can do that because these devices have USB Host Circuits inside. On the link, there is USB Host library for examples. This shield can attach onto your Arduino Uno.
Edit: I have already tried to do this by doing right like you. I couldn't find any solution then I get the shield, but I still can not do to make any control from both Arduino Uno and my Android phone. Anyway, I know this is about our phones not to have USB Host Component

That distinction is untrue.  Many phones have USB host, while many tablets do not.


text:
OSC parsing code. Can it be optimised?
I'm using this OSC library and TouchOSC to controls some motors.
Right now I'm receiving those two kind of messages:
/u/1       // move motor 1 of default steps
/u/2       // move motor 2 of default steps

/u/1/5     // move motor 1 of 5 steps
/u/3/25    // move motor 1 of 25 steps

and so on.
Right now I have this piece of code:
void loop() {
  OSCMsgReceive();
}

void OSCMsgReceive() {

  OSCMessage msgIN;
  int size;
  if ((size = Udp.parsePacket()) > 0) {
    //Serial.println("incoming message.. ");
    while (size--) {
      byte n = Udp.read();
      msgIN.fill(n);
      Serial.print((char)n);
    }
    Serial.println();
    if (!msgIN.hasError()) {
      msgIN.route("/u", up);
    }
  }
}

void upValueExtraction(char *ca, int &num_motor, int &num_step) {
    String s = String(ca);
    String num_motor_s = "";
    String num_step_s = "-1";
    int n = 0;
    for(int i=0; i<s.length(); i++) {
      char c = s[i];
      if(c=='\\') {
        n++;
      }
      if(n==0) num_motor_s += c;
      if(n==1) num_step_s += c;
    }
    Serial.print("num motor: "); Serial.println(num_motor_s.toInt());
    Serial.print("num step: "); Serial.println(num_step_s.toInt());

    num_motor = num_motor_s.toInt();
    num_step = num_step_s.toInt();
}

void up(OSCMessage &msg, int addrOffset) {
  static boolean flag = false;
  if (!flag) {
    Serial.print("route: up "); Serial.println(addrOffset);

    char ca[200];
    msg.getAddress(ca, addrOffset+1);

    int num_motor, num_step;
    upValueExtraction(ca, num_motor, num_step);

    if(num_step==-1) {
      num_step = defaul_steps;
    }

    Serial.print("Have to move motor n ");
    Serial.print(num_motor);
    Serial.print(" of step ");
    Serial.println(num_step);
  }
  flag = !flag;
}

Even if it is working and even if I'm using an Arduino DUE (much more memory then the UNO) I think it can be optimised.
Does it contains some leeks? How can I better use the OSC matching part of the library? Any kind of "embedded c++" guidelines? Can I do everything inline without a ca char array and s String variables? Is better to use Arduino Lib String class or plain old C str* functions? Any kind of comment?
Thanks in advance.

OSC is such a simple format that I ended up ditching libraries entirely, and just parsing the UDP packets directly with a state machine.  Just learn the wire format of the bytes and parse the state machine explicitly.
It's just a trivial function calling format.  The message starts with a 32-bit padded zero terminated string (important!) for the method name.  I am not sure if the type tag is mandatory but it was always being sent (ie: ",iff"), then the binary values corresponding to what type tag says - like bigendian int32,float32,float32.
This was related to OSC generated by ChucK, SuperCollider, and CSound.
Real optimizations would come just from the design of the protocol itself.  You will need to assume that any UDP packet can be dropped.
You are sending motor changes as diffs from current position, so you need to handle packet drops somehow.  (ie: Do you have a TCP-like mechanism?  Do you change the design to send absolute motor positions so that position reports are idempotent and subject to re-broadcast?  Do you ack message receipt individually, or do you periodically poll the device for its current state?)


text:
Program/Read 93LC46B with an Arduino with bit-banging
I'm Tom. I'm pretty new to electronics and programming but I've been getting better. So, recently I bought a 93lC46B EEPROM from Element 14 (It was $0.28! Why not!). I've been doing some research and reading the datasheet VERY carefully. But I still can't get the EEPROM to work right. I'm using an Arduino Uno to program the chip by using the Bit-Banging method. So what I've understood is that I need to cycle the clock, then pull the CS (Chip select) to high and then cycle the clock after each bit like this:
digitalWrite(CLK, LOW);
digitalWrite(DATAIN, VALUE);
digitalWrite(CLK, High);

But so far, that method hasn't been working right. I can't seem to read or write to the device properly. I'm using this set of bits to write 1 and 2 to the first address of the ROM: 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0.
Here's my code so far (Sorry in advance on how bad it is):
#define DATAOUT 11//Comes from DO on chip MISO
#define DATAIN 13 //Goes to DI on chip    MOSI
#define CLK 10
#define CS 9

int data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int inst1[] = {1,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0};
int inst2[] = {1,1,0,0,0,0,0,0,0};

void setup(){
  Serial.begin(9600); //Start serial coms

  pinMode(CS, OUTPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(CLK, OUTPUT);
  digitalWrite(CS, LOW);

  //Write 12 to address 1
  digitalWrite(CS, HIGH); //Enable device
  //Write to memory
  for(int i=0;i<25;i++){
    Write(inst1[i]);
  }
  digitalWrite(CS, LOW); //Disable device
  delay(250); //TCSL Delay
  Serial.print("Memory sucessfully written\n");

  //Read memory
  digitalWrite(CS,HIGH); //Enable device
  for(int i=0;i<9;i++){
    Write(inst2[i]);
  }
  Serial.print("Read instruction written\n");
  for(int i=0;i<16;i++){
    saveBit(i);
  }
  for(int i=0;i<16;i++){
    Serial.print(data[i]+"\n");
  }
  digitalWrite(CS,LOW);
  delay(250);
  Serial.print("Read successful!\n");
}

void Write(int Bit){
  digitalWrite(CLK, LOW);
  if(Bit==0){
    digitalWrite(DATAIN, LOW);
  }
  if(Bit==1){
    digitalWrite(DATAIN, HIGH);
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void saveBit(int outbit){
  digitalWrite(CLK, LOW);
  if(digitalRead(DATAOUT) == HIGH){
    data[outbit] = 1;
  }
  if(digitalRead(DATAOUT) == LOW){
    data[outbit] = 0;
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void loop(){

}

Where have you connected your 93LC46's ORG pin?

@brhans This chip does not have an ORG pin. Read the data sheet before asking please.

Try access it with hardware SPI first. Mybe that can help.

I wanted the experience of running it with big-banging but I could try the SPI. I've found lots of posts for SPI.

Yet another improper migration from EESE.  The problem here is not with Arduino, but rather with lacking understanding of the peripheral's interface.  Send it back!


text:
How to program your Arduino Due while its connected to a display?
Im trying to program my Arduino Due and it seems that I have to disconnect the display from it every time. Is there a work around for this?
Im using a 7" TFT with a CTE TFT LCD/SD Shield with a arduino due board.

Which arduino pins are wired up to the display?

You need to connect the ChipSelect/Enable pin connected to the Arduino, not just tied to ground


text:
how to know which pin is being used, change pin?
i am having an issue where i am unsure how my device knows what pins its using. Version #1 is a timeclock which is simply declared with no pin numbers. Version #2 is a simple loop with a device on pin A0;
So how can i set / change the pins for the clock to use. Currently it is on A4 & A5.
If i wanted to move the clock to say pins.. A1 and A2, how would i do that?
Thanks
Version #1-------------------------------------------------
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

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

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
 //   RTC.adjust(DateTime(__DATE__, __TIME__));
  }

}

void loop () {

    DateTime now = RTC.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(3000);
}

Version #2---------------------------------------------------------
int powerswitch1 = A0;
void setup()
{
pinMode(powerswitch1, OUTPUT);
}

void loop ()
{

digitalWrite(powerswitch1, HIGH);
delay(500);
digitalWrite(powerswitch1, LOW);
delay(500);
digitalWrite(powerswitch1, HIGH);
delay(500);
}

Your confusion is over the multiple functions of analog pins A4 and A5.
In addition to being analog pins, they are also the pins configured internally for I2C/TWI serial, which is interfaced with using the Wire library on arduino. Since those are the only two pins Wire can use, there is no need to specify them, the sketch just calls Wire.begin() to set everything up.
If you need a second I2C device you can simply connect them both up to A4 and A5 at the same time, the protocol is designed to support that kind of thing. If you need to use A4 and A5 for something else besides I2C, you can't continue to use the hardware I2C library.
It is possible to use a software implementation of I2C/TWI serial on other pins, but usually soft-serial implementation have some drawbacks compared to the hardware version. There is an implementation on the arduino playground here: http://playground.arduino.cc/Main/SoftwareI2CLibrary
That said, the RTC library you are using seems to internally use the Wire library, so it would take some hacking to switch it to a different I2C implementation.