text:
What's wrong with my undetected, unresponsive Arduino Robot?
I was wondering if someone could try and solve a major problem I've been having with a brand new Arduino Robot (similar to an Arduino Leonardo). Any input would be very much appreciated!
I've been working with an Arduino Robot on a summer internship for the last week with no major problems. However, a couple of days ago, it stopped running programs and couldn't be detected when being plugged into the computer.
When plugged in or turned on, the LCD turns on with nothing displayed on the screen and the power LED also switches on. However, no program is run (I had a working program involving the LCD uploaded at the time it stopped functioning, which would normally run). Also when plugged in, the Arduino is completely undetected by the computer, with the 'Serial Port' option under Tools grayed out, the device not showing up in device manager, and no signs that a device has been plugged-in. I've tried 3 different USB cables - one of which I tested on another device - and 3 different computers (with Windows 7, 8.1 and Linux Ubuntu installed). On the Linux computer, I ran lsusb before and after plugging in the device and saw no change. I've also tried various solutions such as re-installing the drivers and the Arduino software, using MProg and various rebooting/unplugging-replugging variations.
So I think the problem is almost definitely with the Arduino Robot itself. I'll give a little information about the problems I encountered previously, to see whether something I did affected it or not.
Problem 1:
The first problem I had with the robot was entirely by my own fault and was pretty foolish of me (I'm new to electronics - this being my first project involving it). I ran code from this website (the first set of coding on the page) to try and see whether I could get the LCD to work - not realizing that it wouldn't work for a different type of LCD. After uploading the code, the speaker made a loud constant buzzing noise. Fortunately after uploading a different code, the problem was resolved. I'm doubtful that this could have affected the robot, but since I'm so new to this I'll leave it to one of you to decide.
Problem 2:
The next problem was one to do with uploading. The robot worked fine for a couple of days after the first problem until I came across this one:
When uploading programs, there would be a 'device disconnecting' sound from the computer and the program would fail to upload (I can give details on the error messages if you need them). I managed to solve the issue using an odd solution involving hitting the reset button at just the right time while a program was uploading.
After this, the robot worked for a few hours. In this time I tried to play with the 'turn' function, which didn't seem to work very well at all (the robot would turn angles very different to the ones given) and started creating programs playing around with the LCD. It was at this point the robot stopped functioning properly.
So does anyone have any idea what might be wrong? I have no idea how to fix this problem and I've been trying to find a solution for almost 2 full days now. Any input at all would be greatly appreciated.

Have you checked that the power supply is good?  When there isn't enough power the mcu will reset and the USB device will disconnect.

I'm pretty sure and sadly to announce you that the usb communication of your Arduino Leonardo Compatible is dead and the arduino is connecting to the computer just like an alimentation Source no more.
And since Arduino Leonardo based on The ATmega32U4 which has built-in USB communication ,so the Atmedga32U4 is dead(u-processor) too.
It's not a software matter but hardware one.

Okay, so is there anything I can do?

if the arduino doesn't communicate or does not run any program,so the micro-processor is dead,SO no you can't do anything if you don't replace the Atmedga32U4

There is a vague possibility that a reflash in DFU mode might fix it; it would at least be worth figuring out what you need to do to put the chip in DFU mode and see if it is recognized as a valid USB device then.

You should try to connect to the board using an in-system-programmer. If you have another Arduino lying around, you can upload the ArduinoISP sketch to and use it as a programmer. Alternatively you can buy a cheap programmer on ebay for a few dollars, just search for "avr programmer". You should look up the placement of the MOSI, MISO,SCK, and RESET pins on your board and connect them appropriately(GND connection is also needed and VCC unless you have another power source).
For ArduinoISP you can run avrdude like this:
avrdude -c avrisp -p atmega32u4 -b 19200 -P [serial port, eg. /dev/ttyUSB0 in Linux]

If avrdude can read the chip signature, then at least part of the chip is probably OK. Try to upload a sketch. If it works, you should locate the Leonardo bootloader and flash it to the board. See if it brings back the USB connection.
If you don't have any luck with these methods you might want to look into high voltage programming.

Reflashing the bootloader would be my suggestion too. There's to little information to definitively say the atmega is bricked.

This incident exactly happened for me just now.
I solved it by upload simple sketch and double click on the reset button (the board will be detected for around 8 seconds. once the sketch uploaded successfully, the board should be fixed that time.

Try this:

Bring up a very simple sketch like blink or bare-minimum.
Select the right board and serial port from the tools menu.
Then click upload
As soon as the IDE says 'Uploading' double tap the reset button on the board that you are
programming.
Hopefully the sketch should upload.
You should then be able to upload any other sketch to the Robot like wheel calibration or
line follow.

It works for me (since I had the same problem) for a few days until it stops working again. It's Just a design flaw with the ATMega32u4.

No, this will not work for the poster.  Please read where in the question they explained that the board is not detected as a USB device at all.  No USB device means no serial port to select from the tools menu.


text:
Simple IR sensor
I had an infrared 38khz sensor that I used to read my TV remote control commands. It worked fine but I burned it. I had not another 38khz IR sensor so I tried to use my infrared reflective optic sensor like the one below:

I press my TV remote control button and when I try to read the HIGHs and LOWs it does not work. The sensor shows in my Serial that it received the infrared light but it does not sense the lows/high.
As far as I know, this sensor is not 38khz, it listens in all frequencies that are infrared. So why it does not work? It should work cause it listens in all frequencies. Why it can detect the HIGHs/LOWs that the remote control sends?

Just get one out of an old VCR or other electronic device. Manually detecting the 38kHz carrying frequency and filtering out ambient noise is a pain.

You didn't post the code that used to work with the standard 38Khz IR sensor, but I believe you used digitalRead to determine a HIGH or LOW value, by thus determine if there is an IR emitting in place.
The reflective optic sensor works differently, the output is analog, and changes according to the amount of IR light it sens. In addition, it has a built-in IR led next to the IR sensor, so if you want to use this as the IR detection sensor you had, first you need to disable the IR led to prevent interference.
The second step would be to use analogRead, and compare the result to a pre-defined threshold. For example, since analogRead returns result in the range of 0...1023, you can treat everything from, say, 512 and above as logic 'HIGH'. If you are working with libraries that detects the IR signal, you will need to alter them accordingly.

digitalRead works perfectly. I use it with TCRT1000, but external light like sun or luminescent lamp can interfere.

Good to know. I always used it along with analogRead. It kind of make sense when I think about it, since the MCU might interpret top half values as digital HIGH.

I didnt use digitalRead cause people say it's slow. I used -->> while (irSensor_PIN & (1 << pino_sensor_infravermelho)) { <<--. I think my TCRT1000 is with problem. I will buy another one cause  Martynas said it is gonna work. NOTE: I disabled the infrared LED emitter from the component, of course :)

Samul :)))) You made my day. Because i said it won't work perfectly. As i said, the sun and other light will interfere. The voltage may rise that MCU will think its 1. You would probable easier get simple IR sensor :) and it would be more reliable. Something like this http://www.adafruit.com/product/157

source: Stack Exchange

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

sort: votes


text:
What project design tools are available?
What do you guys use for project designing?
I just found out about AutoDesk's 123D Circuits, which is nice but I wonder if there is something with more components, tools, etc?
For example, I can add an accelerometer to my project there but no signs of a LCD. I have been learning hardware recently and I feel there should be more complete tools out there.
I know this question may be opinion based but I could not find anywhere to ask. Thanks,

If the tool you're using doesn't allow you to create custom parts then, as they say, drop it like it's hot.

ok but do you suggest something? What do you use?

I currently use EAGLE, but I'll probably be jumping to CircuitMaker once it reaches open beta.

http://electronics.stackexchange.com/questions/1222/what-are-low-cost-circuit-and-pcb-design-software/1228#1228

I am using KiCad. It's a full EDA/PCB design suite that is free. It's a really nice multi-platform package. It doesn't do circuit simulation(to my knowledge). It's relatively easy to learn via some youtube tutorials and there's a healthy development community and discussion board as well. It outputs industry standard gerber files so you can quote out your designs to pcb manufacturers.
link:
http://www.kicad.org/

I use this and am fond of it

So, as the other users said, tou can use FRITZING, it is totally free and it does have LCD and a lot of other Shields. But the thing is, if you want a more complete design tool, PROTEUS 8.1 is a very used tool and by far more easy to use than any other design tool (as a complete designer solution). You can even simulate your lcd in software to test if everything is ok before start mounting your Circuit.
Proteus Site: http://www.labcenter.com/index.cfm
Proteus is not free but you can use a lot it.
Here's some images of arduinos in Proteus (The site in portuguese but you just need to see the pictures):
http://microcontrolandos.blogspot.com.br/2013/04/proteus-8-professional.html

I think Fritzing is used quite a lot. I have used it myself a couple of times, and I felt it was quite comprehensive. But I haven't used it enough to say whether this is the tool to choose.

Fritzing is actually very basic once you go beyond the breadboard.

I use ExpressSCH for doing schematics, usually for posting on web sites like this. It is free, runs on Windows only, and is simple enough to use that I picked it up quite quickly. :)
Example schematic:

The red arrows I added later in the GIMP.
It comes with quite a few symbols pre-defined. You can make others from scratch (using boxes, lines, etc.) or take an existing one, "break it apart", and then re-assemble to your desires. Once you have something the way you want it you "group as symbol" and it can be used again in the future.
The program has a sister program ExpressPCB for PCB layouts, however I haven't used that much.

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

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


text:
How to access Attiny84 port B in Arduino IDE code?
Referring to guide at High-low tech, I were able to flash ATTiny84 via UNO through Arduino IDE 1.6.7.
I loaded a simple blink LED program on IDE pin 0 (physical Attiny84 pin 13, PA0) and everything works fine for pin 0 till 7 at Port A.
But what if I want to access or blink a LED at one of the pins at Port B? Example, PB0 (physical pin 2)
The following is my current code to blink PA7
int led=7; //PA7

void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led,LOW);
  delay(100);
}

Refer to url link by @Mikael, this is the answer I'm looking for.
Arduino IDE & Pin Mapping
// ATMEL ATTINY84 / ARDUINO
//
//                           +-\/-+
//                     VCC  1|    |14  GND
//             (D 10)  PB0  2|    |13  AREF (D  0)
//             (D  9)  PB1  3|    |12  PA1  (D  1)
//                     PB3  4|    |11  PA2  (D  2)
//  PWM  INT0  (D  8)  PB2  5|    |10  PA3  (D  3)
//  PWM        (D  7)  PA7  6|    |9   PA4  (D  4)
//  PWM        (D  6)  PA6  7|    |8   PA5  (D  5)        PWM
//                           +----+

IDE Attiny84 Physical Pin
  0      PA0           13
  1      PA1           12
  2      PA2           11
  3      PA3           10
  4      PA4            9
  5      PA5            8
  6      PA6            7
  7      PA7            6
  8      PB2            5
  9      PB1            3
 10      PB0            2

In order to blink PB0, I would need to replace my code with int led=2; //PB0

Should it not be:
int led=10; //PB0

According to the ATtiny web-page the pin/ports are numbered as below:

The physical pin 2 is the Arduino ATtiny core pin 10. You can also find this well documented in the pins_arduino.h file.
Cheers!

the picture is not what i looking for but the pins_arduino.h does help a lot


text:
Arduino UNO R3 possibility
Can I use an ultrasonic sensor, ir sensor, serial communication with MATLAB on computer and i2c communication with a D6T MEMS thermal sensor simultaneously in Arduino UNO ?

Yes, it is possible for the arduino handle communicating over serial and I2C in real time, I've done it frequently. The IR sensor should not pose a problem either.
The ultrasonic sensor might use a timed pulse to send its information that can take a relatively long time, and the basic ultrasound code will just wait for it to finish without doing anything else. The delay itself will not cause you problems but if a lot of data is being sent to the arduino very quickly over serial it might miss some. These delays can be worked around with interrupts/some clever coding but I doubt it will ever be a problem.


text:
Arduino Yun. Write to XML file problem
I am trying to write to a XML file.
I can write some values but limited. When I add an extra line or value the xml file stop updating and all commands I have after the xml.close(); aren't executed
  File xml = FileSystem.open("/mnt/sda1/Data/data.xml", FILE_WRITE); // open the file
  if(xml){
    Serial.println("XML Opened");
    xml.println("<?xml version=\'1.0\' encoding=\'UTF-8\'?> ");
    xml.println("<sea>");
      xml.println("\t<temperatures>"); //ASCII control codes (TAB)
        xml.print("\t\t<water>");
          xml.print(waterTmp);
        xml.println("</water>");
      xml.println("\t</temperatures>");
    xml.println("</sea>");

    xml.close();
  }
  else{
    Serial.print("XML Error");
  }

For e.g if I add
xml.print("\t\t<air>");
xml.print(airTMP);
xml.println("</air>");

If this lines of code are alone in a sketch everything is good.
Another strange thing is if I add the same line twice or more times it can write them to the file.
Do you have any idea how this problem could be solved?

It's a workaround, but have you considered offloading this logic to a python script? Python has excellent XML handling built in (xml.etree.ElementTree)

Yes, my solution was giving this job to the php side.


text:
Now at IDE 1.0.5, should I upgrade to 1.0.6 or 1.5.7 Beta for Pro mini and ATMega2560 use?
Do I need to re-install many libraries (or similar 'house keeping' works)? Is the upgrade straight forward?
Apparently, from Arduino web, one need 1.5 BETA series for use with Due. For Pro Mini, UNO and ATMega2560, should one use 1.5 BETA or 1.0.6 (no beta, presumable stable)?
I am running out of code space. Wonder if the upgrade will install a newer gcc compiler and smaller code size?

Old libraries will work with 1.5 Beta, but you will most likely need to copy any of your own libraries over to the new beta installation, depending on if they were installed to the sketchbook location or inserted into the installation before. That should be about all you need to do after installing the beta for it to work.
The Beta supports all the regular boards as well as the Due and Yun. I doubt you will see any change in binary size if you update. I've been using the beta for some time now and it has been quite stable.
Which version you should use is up to you, the differences are relatively minor. I think the beta adds a few convenient features, but there are no changes to the code or functionality like the switch to v1.0 made.

gcc version 4.3.2, dated as WinAVR Dec 2008, was used inside IDE 1.0.5. From https://gcc.gnu.org/releases.html, latest is 4.9.2 dated July 2014. Any idea what is the 'practical' improvement that one can see, after upgrading to 1.0.6 or 1.5Beta, within the Arduino context, especially in code size optimization,  code size reduction and dead code/data elimination.

4.3.2 is deployed with and up to 1.5.6r2. Where it was updated to 4.8.1 IDE 1.5.7. Where the core libraries have been updated as to compile and work with the newer 4.8.1. Mostly the newer GCC was much more strict and produced errors, that were warnings of bad coding style.

if you have your downloaded libraries in your home or user directory e.g. "C:\Users\mflaga\Documents\Arduino\libraries" than the are compatible and work seamlessly. There is a new path format for the libraries as to support multiple platform. But it is optional. And the same goes for sketch's they can be in the same old location. e.g. C:\Users\mflaga\Documents\Arduino. I readily change IDE's. Where I prefer 1.5.6r2. 1.5.7 has a IDE bug on windows that does a full compile every time. 1.5.6r2 does a fast compile.

@mpflaga where can I download selective older version (like 1.5.6r2) you mentioned? The web only has link to the latest version 1.5.7

http://arduino.cc/en/Main/OldSoftwareReleases

@BrettM since 1.5.x uses gcc 4.8.1, final .hex size is a bit smaller. LTO (link time optimization) has been disabled due to a corner case bug: enabling it further reduces size of .hex

I have had trouble with 1.5.7 (Beta), so I would stick with 1.0.6. As for code space, you might want to look into Atmel Studio (Free), which uses a Visual Studio shell as the IDE. It blows the Arduino IDE out-of-water. Atmel is the maker of all the AT chips, so the Atmel Studio IDE is a great IDE for writing AVR code. Lots of tutorials online and there is a Arduino plug in called Visual Micro (Free also).

Is it right that Atmel studio means programming bare chip, without the benefit of library, which is very useful for interfacing to hardware modules without reading hardware data sheet and register level programming?  What Visual Micro actually does, as their web states, "New Arduino users are guided to work within the normal Arduino framework, in a similar manner to the Arduino IDE. Advanced Arduino users have a range of options that allow the simple (but restricting) Arduino rules to be broken." What extra control (like gcc switches) and other convenience can I get from Visual Micro?

You get the extra control via the Atmel Studio. The Micro Plugin allows you to use the arduino libraies, Serial monitor and upload feature.


text:
What is arduino_debug.exe for IDE 1.5.6r2?
After installing IDE 1.5.6r2, there are two .exe files, arduino_debug.exe and arduino.exe (which is same name as previously installed IDE 1.0.5).

Pretty sure it's the debug build...

Windows binaries can either be Window or Console applications. A Window application can NOT produce text output. Text output is the easiest way to gather error messages related to bugs.
Hence, arduino_debug.exe should be used by Windows users that have found a bug in the Arduino IDE and wish to contribute submitting an issue on github.


text:
LCD display under power saving mode
To make LCD display, Pro Mini and ATMega2560 to run on one set of battery for months, appreciate idea and comment.
Which LCD to use?
Which LCD chip controller chip (hide inside the LCD) has better power saving mode?
Which library with functions of power saving and also can put out VERY beautiful per-programmed display, like multiple fonts, different fonts size, some graphics like circle, rectangles, color fills, gradual-color-changing background with text and graphic at 'foreground' (as in PC power point style)?
Under context of

Small Mono chrome 2 lines text display
3 inches mono chrome graphic 128 x 64 or similar
3 inches color graphic, 320 x240 or similar

Many thanks in advance

I think that is impossible. You'd have to look into only turning the lcd on when needed to save power.

So far no reply, Context 2 and 3 may be impossible, so, I re-do a new question focusing on getting a good Arduino library matching a LCD chip. Will see if conetext 1 will receive can-do reply.

Use a huge battery, or somehow re-charge the battery (solar?).

Use an eInk/ePaper style display, which uses no power while the display is not changing.  These come in monochrome greyscale, and have excellent readability.
This solves only part of your problem as you still need to power the CPU.

Agree, eInk can do. However, supply is hard to get than LCD


text:
Debugger with Breakpoint and Variable read/set capability
Is there any free/open or commercial/paid Arduino IDE Sketch Debugger (not Atmel chip factory standard tool set) with Breakpoint and Variable read/set capability?
I read about VM on web. Is there any similar product?

have you looking into using simavr and gdb?

Wonder if simavr and gdb work at Arduino sketch language or Atmel factory tools (Atmel Studio) C language?

All it does is simulate an avr chip; It is tool agnostic. You will need to be able to compile with debugging data to use gdb, and I'm not sure how to make arduino do that.

There is an on-target debugger in Cosa and a port of the library for Arduino/AVR. It allows conditional and unconditional break- and observation points, simple call back-trace, variable read, memory status check, memory dump, etc.

The debugger is implemented as a small command handler that is executed on the target (Arduino). A set of macros are used to mark break-points, variables to observe, etc.
Please see the debugger demo sketch for more details.

There is something quite close to what you are asking.
You need either the (more expensive) ICEMKII (iirc) or the (cheaper) AVRDragon.
Then it's possible to use it with gdb.
In practice the AVR supports only one breakpoint, so what happens is that the binary in flash will be dynamically patched.
This will slightly reduce the life of the AVR, but I think it's fairly acceptable. One can always use Arduino UNO with the original DIP package for AVR, mounted on a socket. Then it's sufficient to replace the burnt microcontroller and keep the rest (but it's hundreds of thousands of programming cycles before the AVR fails).


text:
GPS Module not catching signal

I am making a gps tracker with neo6m gps module and esp32 dev board.
I checked wiring and coding but still my module isn't catching a signal
I am already on roof of my house in case it require clear sky to connect
This is my code
#include <WiFi.h>//for connecting esp32 to a wifi

#include <TinyGPS++.h>//to obtain gps data from neo-6m gps module

#define WIFI_SSID "Airtel_pawa_4182"//wifi name in simple words
#define WIFI_PWD "Ahuja6230"//wifi password

TinyGPSPlus GPS;//creating a gps object from tinygps++ library

void setup() {
 Serial.begin(9600);
  //wifi setup{
  WiFi.begin(WIFI_SSID, WIFI_PWD);
  Serial.println("connecting to wifi");
  while(WiFi.status() != WL_CONNECTED){
   Serial.println(".");
   delay(100);
  }
  Serial.print("Successfully connected to ");
  Serial.println(WIFI_SSID);
  //}

  //gps setup{
  Serial2.begin(9600);
  delay(1000);
  Serial.println(".");
  Serial.println("ESP32-GPS Tracker");
  Serial.println("Initializing...");
  //}
}

void loop() {
  if(Serial2.available() > 0) {
    if(GPS.encode(Serial2.read())) {
      if(GPS.location.isValid()) {
        double latitude = GPS.location.lat();
        double longitude = GPS.location.lng();

        Serial.print(F("- latitude: "));
        Serial.println(latitude);

        Serial.print(F("- longitude: "));
        Serial.println(longitude);
      }
      else{
        Serial.println(F("- location: INVALID"));
      }
      Serial.println();
    }
  }
  if (millis() > 5000 && GPS.charsProcessed() < 10) {
    Serial.println(F("No GPS data received: check wiring"));
  }
}

The connection is simple
VCC(gps)--->3V3(esp32)

Gnd--->Gnd

Rx---->GPIO17(Tx)

Tx---->GPIO16(Rx)

This is what serial monitor reads:
connecting to wifi
.
.
.
.
.
Successfully connected to Airtel_pawa_4182
.
ESP32-GPS Tracker
Initializing...
No GPS data received: check wiring
No GPS data received: check wiring
No GPS data received: check wiring
No GPS data received: check wiring

How to resolve this issue?
Edit: the breadboard was initially wired wrong but later this was fixed.thanks to Starcat for correcting mistake
But still the gps module is taking very much time to catch signal. When it starts, it first print that no gps data recived for some time then it says location is invalid. Only then it prints the lat. and long.Also, the lat and long are not being updated on serial moniter on time. The delay is just one second but it is taking much more time...
If anybody has a solution then pls answer..

Could you include a picture or a schematic of how your ESP32 and GPS are connected and powered?

@StarCat added picture. I am currently powering it with my laptop

You're using the breadboard wrong. The parts on either side of the center bar of of the breadboard are not connected to each other (see here) so the white and orange wires and the black yellow and wires are not making a connection. Put the wires on the same side of the breadboard and you have a higher change of a working GPS.

@StarCat It worked... It was my first time using mini bread board. I have always used normal sized breadboard that are connected vertically (when placed as landscape), so didn't know that it didn't had connection across the middle bar....

But still the location is showing INVALID for some reason

Nevermind it worked after some tries. Thank you @StarCat but how can I mark your comment as answer?

I've posted my comment as an answer, so you can accept it.

The breadboard is wired wrong. The parts on either side of the center bar of of the breadboard are not connected to each other (see here), so the white and orange wires and the black yellow and wires are not making a connection.
Solution: Put the wires on the same side of the breadboard and you have a higher change of a working GPS.
You should now at least receive output from the GPS, even if it is just reporting the fact that it has not yet received a valid position. It may take some time (especially when using it for the first time) to get a fix. I would give it at least 30 minutes for the first fix.

It is working but every time I start it, It says no gps data recieved for some time then then the location is invalid and only then it output the latitude and longitude. Also the latitudes and longitudes are updated to serial moniter with much delay even I just added a delay of 1 second in my program... Do you have solution to this?

The "No GPS detected" message means that 5 seconds have passed and less than 10 valid characters have arrived at the GPS serial port. Could be a baud rate mismatch.

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


text:
Arduino W5100 AVR
I'm trying to use a W5100 Arduino Ethernet Shield on a ATMega2560 using avr code.
There exists a library written in C, which should work http://www.seanet.com/~karllunt/w5100_webserv.zip from http://www.seanet.com/~karllunt/w5100_library.html
The w5100_webserv.c should be a working example for an ATmega644p. He mentions that the four callback functions should be modified, namely my_select(), my_deselect(), my_xchg() and my_reset()
The w5100_webserv.c also contains the following definitions for SPI_PORT/DDR CS_PORT/DDR/BIT and RESET_PORT/DDR/SPI:
/*
*  Define the SPI port, used to exchange data with a W5100 chip.
*/
#define SPI_PORT     PORTB                /* target-specific port containing the SPI lines */
#define SPI_DDR      DDRB                /* target-specific DDR for the SPI port lines */

#define CS_DDR        DDRD                /* target-specific DDR for chip-select */
#define CS_PORT     PORTD                /* target-specific port used as chip-select */
#define CS_BIT        2                    /* target-specific port line used as chip-select */

#define RESET_DDR   DDRD                /* target-specific DDR for reset */
#define RESET_PORT    PORTD                /* target-specific port used for reset */
#define RESET_BIT    3                    /* target-specific port line used as reset */

I've changed it to the following according to what i think the ATmega2560's datasheet specifies
/*
 *  Define the SPI port, used to exchange data with a W5100 chip.
 */
#define SPI_PORT     PORTB                /* target-specific port containing the SPI lines */
#define SPI_DDR      DDRB                /* target-specific DDR for the SPI port lines */

#define CS_DDR        DDRB                /* target-specific DDR for chip-select */
#define CS_PORT     PORTB                /* target-specific port used as chip-select */
#define CS_BIT        10                  /* target-specific port line used as chip-select */

#define RESET_DDR   DDRB                /* target-specific DDR for reset */
#define RESET_PORT    PORTB                /* target-specific port used for reset */
#define RESET_BIT    20                   /* target-specific port line used as reset */

Furthermore, in the main(), there are also specific code for the AT644p:
/*  * Initialize the ATmega644p SPI subsystem */
CS_PORT |= (1<<CS_BIT);                                    // pull CS pin high
CS_DDR |= (1<<CS_BIT);                                    // now make it an output

SPI_PORT = SPI_PORT | (1<<PORTB4);                        // make sure SS is high
SPI_DDR = (1<<PORTB4)|(1<<PORTB5)|(1<<PORTB7);            // set MOSI, SCK and SS as output, others as input
SPCR = (1<<SPE)|(1<<MSTR);                                // enable SPI, master mode 0
SPSR |= (1<<SPI2X);                                        // set the clock rate fck/2

I've changed it to the following according to what i think the ATmega2560's datasheet specifies
/*
 *  Initialize the ATmega2560 SPI subsystem
 */
CS_PORT |= CS_BIT;                                    // pull CS pin high
CS_DDR |= CS_BIT;                                    // now make it an output

SPI_PORT = SPI_PORT | (1<<PORTB0);                        // make sure SS is high
SPI_DDR = (1<<PORTB0)|(1<<PORTB2)|(1<<PORTB1);            // set MOSI, SCK and SS as output, others as input
SPCR = (1<<SPE)|(1<<MSTR);                                // enable SPI, master mode 0
SPSR |= (1<<SPI2X);                                        // set the clock rate fck/2

Lastly i've changed the my_reset() function:
    void  my_reset(void)
    {
        RESET_PORT |= RESET_BIT;                            // pull reset line high
        RESET_DDR |= RESET_BIT;                            // now make it an output
        RESET_PORT &=~RESET_BIT;                            // pull the line low
        _delay_ms(5);                                            // let the device reset
        RESET_PORT |= RESET_BIT;                            // done with reset, pull the line high
        _delay_ms(10);                                            // let the chip wake up
    }
I am not sure whether my changes are 100 % correct and i don't know what changes needs to be done to my_select() my_deselect and my_xchg. I hope someone can suggest som corrections.
Thanks in advance.

Have you actually tried it? Does it work?

Yes. I've compiled it several times using avr-gcc and afterwards used avrdude to transfer it to the atmega2560.
To ensure that there isn't anything wrong with the board, i've tested with a simpel blinking example.

And what did your tests reveal? So far you have told us everything except if it actually worked or not, and if not, in what way did it not work?

None of my tests revealed anything. I haven't been able to connect to the specified IP-address at all.
So well it did not work in anyway. It compiles without problems, it can be transfered without problem. But the webserver is not running on the Atmega2560.

If you have any idea what i need to change in the PORTS and DDR registers, please say so :).

I've managed to specify the correct ports and bits in order to make the library function on the Arduino ATmega2560 using their Ethernet Shield.
The SPI port definitions has to be changed to the following:
#define SPI_PORT    PORTB               /* target-specific port containing the SPI lines */
#define SPI_DDR     DDRB                /* target-specific DDR for the SPI port lines */

#define CS_DDR      DDRB                /* target-specific DDR for chip-select */
#define CS_PORT     PORTB               /* target-specific port used as chip-select */
#define CS_BIT      4                   /* target-specific port line used as chip-select */

#define RESET_DDR   DDRB                /* target-specific DDR for reset */
#define RESET_PORT  PORTB               /* target-specific port used for reset */
#define RESET_BIT   8                   /* target-specific port line used as reset */

The section about the AT644p in the main() function has to be changed to the following:
/*
 *  Initialize the ATmega2560 SPI subsystem
 */
// Initial SPI Peripheral
SPI_DDR = (1<<PORTB2)|(1<<PORTB1)|(1<<PORTB0);

// CS pin is not active
SPI_PORT |= (1<<CS_BIT);

    // Enable SPI, Master Mode 0, set the clock rate fck/2
SPCR = (1<<SPE)|(1<<MSTR);
SPSR |= (1<<SPI2X);

//Disable the SD card
DDRB |= (1<<CS_BIT);


text:
Connect HX711 to a three wire load cell
I have the following load cells:

I'm using the following HX711 amplifier
Every guide i can find on the internet describes how to connect a load cell with four wires to the amplifier. How can i connect a load cell with three wires to the amplifier?
Thanks in advance.

How many three-wire load cells do you have?

how can I get data from the 4 loadcell circuit??

A datasheet for the HX711 is https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf  (On your board, it looks like E+ is AVDD and E- is AGND.)
Each of your two load cells could be a half-bridge of a wheatstone bridge, with excitation on the white and black, and sensing on the red like:
I have a similar loadcell with the colors as Blue-Red-Black, (instead of White-Red-Black as above, or the Red-White-Black in your image) with my red sensing wire in the middle.  The positive strain resistance (increasing resistance with increasing load) is between the Blue and Red, while the negative strain (decreasing resistance with decreasing load) is between the Red and the Black. The ~1000 ohm resistance in each leg changes by tenths of an ohm with hand pressure on the button, when the outer portion is supported, but the inner portion is not supported.  Your cells do not have the bridge-button part that create a balanced twist along the center portion, so it might be hard to reliably apply a load your cell.
To make positive deflections of the cells combine to unbalance the Wheatstone bridge, wire one cell's white and black opposite to the other cell, and attach them to E+ and E-, with the reds connected to A+ and A- like this:
   HX711.E+ : Cell1.White + Cell2.Black
   HX711.E- : Cell1.Black + Cell2.White
   HX711.A+ : Cell1.Red
   Hx711.A- : Cell2.Red

The labelling on the schematic isn't quite right-- the "Reference 1K" are actually the negative-strain portions of the cells, and might be better labelled as "-Active 1k Ohm".
If it moves in the wrong direction/wrong sign with increasing force, switch the reds or multiply by -1.
If you have only one three-wire cell, use a couple 1K resistors, or a 2K potentiometer to balance the existing cell as the other half of the Wheatstone bridge.  One issue with using discrete (10%, 5%, 1%?) resistors is that the precision and tolerances when configured as a voltage divider may produce a significantly different result as compared with the balance in a lead cell and its full-scale signal (+/-0.1%) in a loadcell.  A the center tap of a potentiometer can provide for tuning to match the load cell voltage.  For the HX711's 32x, 64x, or 128x gain, you need to keep the voltage differences between the sense terminals  between +/-80mV, +/-40mV, or +/-20mV to stay within the limits of the HX711.
Per @wirewrap's comment, the colors on the wire could be different than the picture I posted.  You can make certain by measuring the resistances between the wires and exciting on the pair with the greatest resistance, and sensing on the middle terminal.

In the picture of the OP's loadcell it looks like the common of the resistors is the white lead, not the red.

You are right.  One could measure the resistances and determine the center terminal to be certain.

When you have four half bridges I think that you will need to read them separately as pairs and then sum the result in software.  I would be interested in hearing how multiple hx711 modules should be best handled by a Nano.
Update.  I have discovered that sparkfun produce a load cell combinator board that assists wiring four half bridge load cells to appear as a full bridge.  I have still not understood how that works yet.

It seems like that module is used to connect the 4 wire load cell, but on the internet I found other schematics that might help you out how to wire it up.
This is one way (http://i46.tinypic.com/30j0d2t.jpg):

Otherwise try this way:

I am not an expert on load cells but it seems like you just need to give it a try and see if it works.

How can i connect a load cell with three wires to the amplifier?

it is one-side of the bridge.
the other side can be another load cell or a resistor bridge.


text:
External (pin change) interrupt and power consumption
I want to write a lipoly powered arduino device that can be launched from sleep mode by pressing a certain key that is connected to ground. Usually, when no in sleep mode I enable the internal pull-up resistor for a definite level. But when in sleep mode, I assume this would drain to much power and hence I want to avoid it. Is it sufficient to just wait for a pin-change interrupt on the same port pin without the internal or an additional external pull-up resistor?

The rule for micropower sleep mode is not that you can't have pulling resistors, it's that you can't have anything such as a switch holding a signal against it's pulling resistor, as that would put a voltage difference across the resistor and cause measurable current to flow.

You must not leave CMOS inputs floating. This will increase power consumption, and as a worst result may damage the device. Use an external pull-up if you feel that the internal pull-up passes too much current.

It doesn't matter what internal or external value you use for a pullup resistor unless something is creating a current path to ground.  Hopefully the button is not being held down while the device is trying to sleep, so that is a non-issue.  The other possible path would be leakage through the input structure itself, but if that is present you are going to have to put current through it if you want the input to be high, and there isn't going to be a drastic difference between the current necessary to be reliably high and the current which would be supplied holding the input even closer to Vdd.

Yes, was a thinking error about the pull-up resistor draining to much current. The push-down button of my rotary encoder usually is open, but for the two rotary channels I'll set the outputs to low - in case the rotary encoder has a connection to GND which would result in the pull-up resistor draining current. BTW, IIRC, the default port state is input by default. For unused port pins, should I always enable the pull-up resistors or make them to output? Or does the massive default code produced by Arduino already does it?

Tutorial from University of South Florida
https://www.youtube.com/watch?v=HiAbxSO_9nU
Internal pull-up resistor does not drain too much current. Only leakage in nA range. It is correct to use pull up, in your case, as this is what it is designed to do. As Ignacio Vazquez-Abrams, do not leave input pin open.
MCU are designed to do the precise action you mentioned, to wake up on pin change as in mass produced wrist watch and TV remote controller. On remote, MCU sleeps until key pressed. On watch, it wake on timer 1 second) and key change.


text:
Delay function without using a timer
Is there a delay function available that does not use millis() which itself makes use of a timer? Does not need to be hyper-exact.

delayMicroseconds(1000);// maximum delay is 65535 uS

or
#include <util/delay.h>
_delay_ms(1);

delayMicroseconds() does not accept long int (32-bits) but only unsigned int (16-bits), hence the maximum you can pass it is 65535.


text:
Olimexino (32u4): power down
I want to power down my Olimexino as much as possible and only wakeup on a pin-change interrupt. I removed the 3.3V/5V jumper (so the processor does not get power) and 3µA were displayed, so the voltage regulator is really a low power variant. What I have done:
#include <avr/power.h>

power_all_disable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();

This resulted in still using 220µA. Now I disable the ADC, too:
ADCSRA = 0;

which reduces it to 100µA. I've tried to disable further ADC-stuff using
ACSR = 0;
ADMUX = 0;

and tried to disable (?) the Watchdog Timer using
WDTCSR = 1 << WDP3;

but without any further improvements. The datasheet for the 32u4 suggests to disable the Brown-Out-Detector, too, but I don't seem to be able to do that using code, but only by setting some fuses which is not possible directly using the Arduino IDE. Any further ideas?

Did you use the PRRx registers? Did you disable JTAG? Why can't you use ISP?

PRRx registers are set using power_all_disable(). JTAG? I don't use ISP, because that doesn't work with the Arduino IDE.

ISP works fine with the Arduino IDE. It just doesn't work with the USB connection. Besides, you wouldn't set the fuse through the IDE regardless.

The timing for setting the registers to disable the brown-out-detection is pretty strict. You'll have to set the registers right before sleep_cpu()

Gerben, what registers to set for the 32u4?


text:
How to tap my thermostat's serial line
This is a home heating system hack.
I want to add an arduino in-line between my thermostat and air handler; and possibly between the air handler and outdoor compressor. The long-term goal is to post long-term statistics to an RRD web page (run time, power consumption, temp, etc.) and control the blower (without the heat) automatically when we are burning our wood stove.
The product is a Nordyne IQDrive (notable in that the equipment comes with 5 separate brand logos to adhere to the equipment: Tappan, Frigidaire, Westinghouse, Nutone, and Broan).
At this stage, all I want to attempt to do is to tap the serial links and record the conversations. I would prefer not to shoot myself in the foot.
The "System Field Wiring Instructions" describe both links as "serial." The wiring diagrams label the connection points as:
air handler interface board --> [description] --> thermostat
      G --> GND --> C
      - --> DX- --> B-
      + --> DX+ --> A+
      R --> R   --> R

Googl'ing these might indicate that this is an RS485 (never heard of it).
How do I tap and record the communication?

It does indeed look like RS485. Maybe this is helpful: http://owlsan.blogspot.nl/2012/09/connecting-urm04-v20-ultrasonic-sensor.html

Although this chip doesn't look designed for packet sniffing, this Sparkfun product looks like it may be helpful...

You don't need anything special for sniffing - just don't wire a driver to the bus, or if it is internally wired in parallel with the receiver, tie its enable signal disabled.

@ChrisStratton I apologize... I'm too n00b'ish to understand (I even asked a friend). Can you please expand on your response a bit?

I does sound like RS-485.
You can get cheap RS-485 transceivers from the usual sources.  These take the 0..5v TX line and convert it to RS-485 voltages, or RS-485 voltages and convert to the 0..5v RX expected by your Arduino.  You would normally enable only one direction at a time - sending RS-485 from the Arduino TX or receiving RS-485 to the Arduino.
In your case, you just want to receive, so keep the transmit side (TX to RS-485) disabled, while enabling the receive side (RS-485 to RX).
RS-485 is just an electrical standard, and they could be sending any pattern of on and off signals they want, but often they will be sending asynchronous data with one start bit, 7-8 data bits, and one stop bit per character - which the Arduino's Serial port can handle.  So it's worth testing to see if that works.
The next thing you need to know is the clock rate, or "baud rate", which is how many bits per second (including start and stop bits) it is sending.  Often you can figure this out by trying some standard rates like 1200,2400,4800,9600,19200,38400,57600,115200 (there are others) and printing the results to your screen - when you are at the wrong rate you will get nothing, or some odd garbage.  When you get the right rate, it will look more reasonable.
If no speed works, you may need to reverse A and B.
You might temporarily hook up an LED and a resistor (say 2.2K or higher) between the RX from the RS-485 and your 5v power.  This will give you an idea of when there are transmissions from or to the thermostat.  If it only transmits once a minute, say, you might have to wait a while for each speed test.  Or changing the set temperature may trigger a send.
You may be able to test the lower speeds at least using Software Serial, and then echo the received data to the hardware serial port which goes to the Serial Terminal in the Arduino IDE.
From there, you may need to figure out the protocol - the structure of the data.  Protocols vary widely.  It may be text or it may be binary; if it's binary you may want to have the arduino convert each character (values 0..255) into hexadecimal (00..FF) for printing.
Most protocols for this kind of control send data in a burst, or packet.  You will likely be able to detect the start and end by the timing (ie: a long pause between the end and the start of the next).  Of course, some protocols might send several packets continuously, but still the first character (or binary value) after a long pause will often be the packet header.
Remember that there may be packets from the themostat, and packets to the thermostat, and you will see both without knowing which is which (so long as you are just passively tapping the line).
I hope this is enough of a pointer to get you started.  Decoding protocols is a more extended subject.

I read the WikiPedia article on RS485 (http://en.wikipedia.org/wiki/RS-485). The more I learn about RS485, the more likely it seems this is the right track. RS485 is typically wired in a bus with as many as 32 nodes. It's noise tolerant and more than fast enough for a heating/cooling system. At slower data speeds, it can run as far as 4000 feet.
The next step appears to be trying to record some traffic. I found this question on the EE Stack Exchange about tapping RS485: https://electronics.stackexchange.com/questions/30511/hijack-observe-rs485-communication-data-by-wire-tapping
A USB widget appears to be affordable. Inserting the widget between the two ends (I'll try and test to see whether the ends both have termination resisters) should be some easy wiring.


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!

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.

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


text:
Source Code for strcpy and strcat
Does anyone know the location of the assembler file for strcpy and strcat for the Arduino?  I wish to modify it.

I don't think these functions are written in assembler, but just in pure C. I am not sure it would be agood idea to modify them (but you could copy them into new functions and adapt the way you want it). Honestly, these functions are quite easy to write with just 1 or 2 lines of code. What are you trying to achieve?

The Arduino IDE doesn't ship with the source/assembly for a lot of the core functionality. It comes pre-compiled in object/library files.
However, you could download the source code for AVR Libc from this site:

http://www.nongnu.org/avr-libc

Obviously there's no guarantee that the files you download will exactly match what comes with the Arduino IDE, but it's useful if you're interested in how they're implemented.
When you've downloaded and extracted the source code, look in the libc/string folder. you should find assembly files called strcat.S and strcpy.S.
As jfpoilpret says in the comments, attempting to modify core library functions is generally not a good idea. They may be getting called by other parts of the core, so any changes you make could break something else.


text:
Why my RTC module doesn't return the right date/time?
I have a RTC module DS1307 (MR005-001.2) on my Arduino Uno.
I use the Wire.h / Time.h / DS1307RTC.h libraries.
The date and time returned is completely wrong ("17:18:9 2 4 2036") ... What do I do wrong ??
Thanks !
Here is my partial code for setup() :
    setSyncProvider(RTC.get);
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");

This writes "RTC has set the system time", so I guess something is happening right...
Here is my partial code for loop() :
    Serial.print(hour());
  Serial.print(":");
  Serial.print(minute());
  Serial.print(":");
  Serial.print(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();

Just as in the example ... and the date/time returned is "17:18:9 2 4 2036"

Have you ever set the time?

I guess if TimeStatus() returns TimeSet, it's because the time has been set ? Documentation says for "TimeSet"  as a return value : "The time is set and is synced. Time and Date values are not valid if the status is timeNotSet. Otherwise values can be used but the returned time may have drifted if the status is TimeNeedsSync. ". Am I misunderstanding something ? I thought the point of an RTC clock was to sync with computer's clock, so why set the time ?

It's doesn't sync by magic. You have to add code to do that (at least once). The timeNotSet is only if the library can't access the RTC module. The RTC module thinks it's 2036, and just keep incrementing the time, every second.

Can you at least confirm that the clock runs as expected, i.e. current time increases as expected?

You setup interpretation should be more like:
 setSyncProvider(RTC.get);
 if(timeStatus()!= timeSet)
   Serial.println("RTC has never been set");
 else
    Serial.println("RTC has a time");

To conditionally sync the clock to the compilation time if the clock is not running:
if (! RTC.isrunning()) {
   Serial.println("RTC is NOT running!");
   // following line sets the RTC to the date & time this sketch was compiled
   // uncomment it & upload to set the time, date and start run the RTC!
   RTC.adjust(DateTime(__DATE__, __TIME__));
}
// following line unconditionally resets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
// RTC.adjust(DateTime(__DATE__, __TIME__));

To unconditionally sync it to the compilation time, uncomment the last line and reload for one cycle, then re-comment it and reload to let the clock run itself.


text:
RTC MCP7940M not counting up
I'm able to set a time and to read it back without any problems but it doesn’t tick up. It stays the same. Even if I restart the serial monitor and thereby resets the buffer(?). So it seems to me that I'm able to set the registers but somehow the oscillator isn't working, do I have to tell it to use the external oscillator? Datasheet.
Using Uno Rev3.
I've connected it like this:
Never mind the BAT54 diode and the "RTC+MCU_VCC" node, its all just backup power from a capacitor. The supply voltage is alright.
The code I've been using is a modified version of this.
// SDA analog pin 4
// SCL analog pin 5

#include <Wire.h>
const int MCP7940 = 0x6F; // Address of MCP7940 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December"};

// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  delay(2000); // This delay allows the MCU to read the current date and time.

  Serial.print("The current date and time is: ");
  printTime();
  Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
  Serial.println("Would you like to set the date and time now? Y/N");

  while (!Serial.available()) delay(10);
  if (Serial.read() == 'y' || Serial.read() == 'Y')

  // This set of functions allows the user to change the date and time
  {
    Serial.read();
    setTime();
    Serial.print("The current date and time is now: ");
    printTime();
  }

  Serial.println("Thank you.");
}

// Continuous function for converting bytes to decimals and vice versa
void loop() {
}
byte decToBcd(byte val) {
  return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
  return ((val/16*10) + (val%16));
}

// This set of codes is allows input of data
void setTime() {
  Serial.print("Please enter the current year, 00-99. - ");
  year = readByte();
  Serial.println(year);
  Serial.print("Please enter the current month, 1-12. - ");
  month = readByte();
  Serial.println(months[month-1]);
  Serial.print("Please enter the current day of the month, 1-31. - ");
  monthday = readByte();
  Serial.println(monthday);
  Serial.println("Please enter the current day of the week, 1-7.");
  Serial.print("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
  weekday = readByte();
  Serial.println(days[weekday-1]);
  Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
  hour = readByte();
  Serial.println(hour);
  Serial.print("Please enter the current minute, 0-59. - ");
  minute = readByte();
  Serial.println(minute);
  second = 0;
  Serial.println("The data has been entered.");

  // The following codes transmits the data to the RTC
  Wire.beginTransmission(MCP7940);
  Wire.write(byte(0));
  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekday));
  Wire.write(decToBcd(monthday));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.write(byte(0));
  Wire.endTransmission();
  // Ends transmission of data
}

byte readByte() {
  while (!Serial.available()) delay(10);
  byte reading = 0;
  byte incomingByte = Serial.read();
  while (incomingByte != '\n') {
    if (incomingByte >= '0' && incomingByte <= '9')
      reading = reading * 10 + (incomingByte - '0');
    else;
    incomingByte = Serial.read();
  }
  Serial.flush();
  return reading;
}

void printTime() {
  char buffer[3];
  const char* AMPM = 0;
  readTime();
  Serial.print(days[weekday-1]);
  Serial.print(" ");
  Serial.print(months[month-1]);
  Serial.print(" ");
  Serial.print(monthday);
  Serial.print(", 20");
  Serial.print(year);
  Serial.print(" ");

  Serial.print(hour);
  Serial.print(":");

 Serial.print(minute);
 Serial.println();
}

void readTime() {
  Wire.beginTransmission(MCP7940);
  Wire.write(byte(0));
  Wire.endTransmission();
  Wire.requestFrom(MCP7940, 7);
  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read());
  weekday = bcdToDec(Wire.read());
  monthday = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

Okey, I've been very tired when doing this but I think the problem was with bit 7 at adress 00h. The "seconds byte". That bit is called ST and turns on or off the oscillator. Doing a bitwise OR like this: Wire.write(decToBcd(second) | 128); sets it to "1" (128 = B10000000) and it's running now.

Most external RTCs have a bit that must be set in order to activate the oscillator. In the MCP7940M this is ST.

you have a small flaw in your readTime function. If you don't want very strange seconds from the device you should combine the two nibbles packed into the seconds byte. Like this:
void readTime() {
  Wire.beginTransmission(MCP7940);
  Wire.write(byte(0));
  Wire.endTransmission();
  Wire.requestFrom(MCP7940, 7);

  int rawsecond = Wire.read();
  second = bcdToDec( rawsecond & 112) + bcdToDec(rawsecond & 15);
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read());
  weekday = bcdToDec(Wire.read());
  monthday = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

Thanks for the sample - helped me quite a bit.

found another one. When accessing the weekday you also need to cut the correct bits out of the byte like this: weekday = bcdToDec(Wire.read() & 7);


text:
Help connecting an Arduino and an electronic speed controller
We have this controller that we are planning to use with this motor. How do we plug it to the Arduino to make it work?
This is a totally new subject for our school team, since we are mostly programmers, so your help will be really appreciated.

The operational connection will be trivial; what may be more challenging is if the controller is supposed to be programmed by moving transmitter sticks in a particular sequence.  You might need to have an alternate sketch which controls the PWM signal with a potentiometer to emulate that.

HobbyKing, which sells Arduinos and is a great source for motors and controllers, has an instructable on this at http://www.instructables.com/id/ESC-Programming-on-Arduino-Hobbyking-ESC/
I found another on the OpenROV site, at http://community.openrov.com/forum/topics/how-do-i-activate-electric-speed-controller-with-arduino
Did you actually try googling "arduino electronic speed control" before coming here?

Link-only answers are discouraged. Please add some detail to your post that can help answer the question. You can quote text from the links.

As the controller and motor are from the same vendor, they can help you with specific questions.
That motor controller is designed to emulate a servo motor. So it takes a servo-motor signal:
Ground
Power
PPM signal
The Arduino servo library will drive the PPM signal. Power and ground for the controller need to come from a separate power supply. The Arduino can't power it.


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:
Is the supply voltage made available anywhere on the Arduino Uno Board?
I need to power an OpAmp based circuit that will be connected to my Arduino Uno input. Since I have a 12V adapter for the Arduino board, I want to draw power from it for this opamp(LM358).
Does anybody know if there is any way I can do this from the Arduino board(pins?)is as opposed to having to solder wires directly to the bottom of the DC jack?

The Vin pin is available (next to Gnd) pins.

The voltage on Vin is after a protection diode. It will be around 0.7 V less than the supply voltage.


text:
Using displays with Arduino Uno
Does anybody know if there is any documentation available online on basic information about using displays with Arduino Uno? I've never used displays before and would very much appreciate some basic information on the different types etc..
Any information that can help me choose what display I want to buy for my next project will be helpful.
for ex: Right now I don't even know what a shield is in context to a display and whether or not I should look for one in my purchasing my display.

A shield is just an Arduino-shaped horse that holds electronics, and is not related to using a display per se.

The Arduino website has a list of LCD displays and link with more information about each one. For controlling the display you may want to look at Arduino's LiquidCrystal Library.
If you are looking for a step by step guide for using a lcd display with the Arduino, there is a nice guide on Adafruit.


text:
What is the capability of AVRISP and USBASP on ATMega48, 328, 2560?
For use with ATMega 48 (old Arduino?), 328 (UNO, Pro Mini) and 2560 (Mega2560) chips, what is the capability for the AVRISP and USBASP programmers on:

Can it read, write fuse?
Can it read, write Program Flash?
Can it work 3.3 and 5 volts?
What workable clock frequency range on the MCU?
Can it be used under Arduino ISP to write to board so as to erase the bootloader and use the FULL flash space for big user program (eliminate boot loader saves 0.5 to 8KB space on above Arduino boards)?
Can it be used with ATMel factory software development tools (Atmel studio and associated tools) to use MCU on chip hardware based breakpoint (Debug wire, JTag, or other names, as on different MCU)?

Many thanks in advance

Keep in mind that these are getting to get you little capability compared to the Arduino-as-ISP solution - and in some configurations, limited flexibility too.

#4. Using USBASP on AVR running at 1Mhz doesn't work using the arduino IDE. You can instruct avr-dude to program at lower speeds using the -B parameter. I've had no problem using USBASP from the IDE on boards running 8Mhz and above.

Yes.
Yes.
Depends on the specific hardware. See the documentation for the exact variant you have.
See 3.
No. They have their own protocol that you must use instead. They are selectable from the Programmer menu in the IDE though. However, you must unprogram the fuse bits outside of the IDE.
No. They are low-cost tools meant to be used for programming only. You will need an Atmel-supplied debugger in order to use Atmel Studio's debugging features.


text:
Controlling Arduino from Raspberry Pi
I am trying to simply send a digital output from the Raspberry Pi to trigger some code on an Arduino. I have setup the Pi with the digital output working fine (tested using LED) however, I cant seem to get the Arduino (Leonardo) to read this output. I mean, all the details about the Pull Up resistor and logic having to be low to be high is confusing me and I really dont want to use any other electronic components (ie transistors or switches, etc).
Is there a simple way of just reading the output and triggering the code on the Arduino?


text:
Can I use the setup() function inside the loop() function
In the normal case the setup() function will be run once automatically and and then the loop() function will run many times.
I want to initialize several modules in the setup() function and then in the loop() I want to read values from them periodically. But if the period between usage is long I want to power off the modules. After defined time the modules will be powered on again and need to be initialized. Can I use the already existing setup() function inside the loop() to initialize the modules or I have to write another similar function? Is there any other better way to power off/on sensors and modules during the execution of code.

Sorry if I have not defined the question the right way, maybe somebody can help me edit it so that it can be properly formed

It could be possible, since it is going simply to call the same function BUT it is really a very bad design*.
Usually the main purpose for a microcontroller is just sitting there and run a procedure or main function repeatedly until the end of the world. And during one loop just to check if some conditions are met.
You should never stop or influence your loop() function and never mess up the default design of the arduino.
In you case (but it depends on your code and your application), you just want to run the loop() once all sensors have been already started (in the setup() function).
In your run, you check periodically the sensor and start a timer (better if interrupted). If an amount of time has expired and the sensor should be turned off, then the timer will call another function, which has the only target to switch sensors off.
The loop() runs again and again and if the original condition is met, then you can start your sensors again.
To save up time and code typing, I suggest you write only ONE function for switching on the sensors and call this function in setup() and in your loop(), something like this:
void startSensors();
void stopSensors();

void setup() {
  startSensors();  // I start all sensors here
}

void loop() {
  if( condition?!?! )
     {
       ...
       stopSensors();
       ...
     } else {
       ...
       startSensors();  // I call the same function here
       ...
     }
}

*: for istance you define in your setup() the connection through serial port. This means that your object "serial port" is going to be recreated each time you call setup() whit undefeined behavior in case it is outputting datas or has same data in the FIFO Buffer. Simply...setup() has that name because needs to setup things once. Everything that must be done more than once, then must be called from run() too.

Thank you very much for all people that corrected my English. English is not my native language and it is really difficult (impossible) to get better without correction.

What you recommend is a good habit for beginners. But for calling it a "very bad design" you should have some stronger arguments. I agree, it is not a good design.

I updated my answer

I agree, given the very good example, it is very bad design :)

I don't disagree with your conclusion, but starting serial a second time will not cause that undefined behavior. The serial ports are global objects defined in HardwareSerial.h, the user code on arduino never creates new instances.


text:
Serial debug output looking messy
I've got this quite basic code running on an Arduino Mega 2560, and the output is looking like I have the serial settings wrong, though I can't work out what to change.
void setup()
{
  Serial.begin(9600);
  Serial.println("test123");
}

void loop()
{
  Serial.println("test" + millis());
}

The output looks like this:
ð¦·Z©÷
×ï¾üÿ7ß^|ïüûÿVÏuØëo~ìÿÓûzëýÿ{ßþ©×xñ×¤¿ïßûÏûýoÏ¿îãõI
õfwi÷`p¬½Ïª»QáÀª»¦·ð¦·Z©÷
test123
D

4ñjü¯÷~µÞMz¹Ý~¼
Ûþ}iû}ÒÖ¦Ç¿÷ÿÂï½Õ¾;îö

I'm using the inbuilt "Serial Monitor" in the Arduino suite with settings 9600 baud and no line endings.
I see that the first println in setup() is sending the data as expected but all other comms are coming through as nonsense.
Any suggestions of what to do?

This is unfortunately not valid in C++:
"test" + millis()

Rather than concatenating two strings, it's actually doing pointer arithmetic. It's taking the memory address where "test" is stored, and offsetting by the value retrieved from millis(). The result is a totally arbitrary memory location which gets treated like a string.
Generally speaking, it's arguably best to avoid string concatenation on Arduino anyway unless absolutely necessary. The reason is that it can use more memory than you might expect.
A simpler approach would simply be to do the serial output as a sequence of individual operations, e.g.:
Serial.print( "test" );
Serial.println( millis() );

Note the difference between print() and println(). The first one doesn't add a line break at the end, but the second one does.

Great, thank you. Can you also explain why string concatenation per http://arduino.cc/en/Tutorial/StringAdditionOperator isn't working how I expected it would in this instance, when one of their examples on the page is specifically stringThree = stringOne + millis();?

@bdx You can concatenate String objects like that because they overload the plus (+) operator. String literals in C/C++ (anything in double quotation marks "like this") work differently. You can read more about the difference here: http://arduino.cc/en/Reference/String

I see. My assumption that a string literal would create a String object was false, it creates a null-terminated character array, and the String type also has an overload on the = operator to coerce a char[] to a String.

You can explicitly construct a String object by doing this: String("test"). It uses more memory than a string literal alone though, so it's important to be careful how you use it.

Just as a minor addition to Peter's excellent answer and comments on concatenation and implicit typecasting with String objects:
Alternatives to construct the message (as a char[]) to be send might be:

use sprintf()

char buffer[80];  // for the complete output
char value[4];    // for millis(), which returns an unsigned long

sprintf(buffer, "I'm running for %u ms now", millis());
Serial.println(buffer);

Note that sprintf() uses quite some memory!

build the message 'manually':

 char buffer[80] = "I'm running for ";

 itoa(millis(), value, 10);
 strcat(buffer, value);
 strcat(buffer, " ms");
 Serial.println(buffer);


text:
How to attach interrupts to Arduino UNO timers?
I understand there are 3 timers on the Arduino UNO.  What specific registers do I need to use to access them?
My goal is to use these timers to poll different sensors I am using with a ms period. Are there any pre-made libraries out there to do this?

Have you had a chance to look at the datasheet yet?

The datasheet for the ATMEL SOC, or the Arduino breakout board itself?

For the MCU (not SoC).

For the UNO, use Timer1.
An example of the way you can use it is as follows:
Download the TimerOne library: https://code.google.com/p/arduino-timerone/downloads/list
/*
 *  Timer1 library example
 */

#include "TimerOne.h"

void setup()
{
  pinMode(10, OUTPUT);
  Timer1.initialize(500000);         // initialize timer1, and set a 1/2 second period
  Timer1.pwm(9, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
}

void callback()
{
  digitalWrite(10, digitalRead(10) ^ 1);
}

void loop()
{
  // your program here...
}

Timer 0 is use'd by the arduino core libraries for functions like millis(). It is best left alone. Leaving timer1 and 3 are available for general use. Both 1 and 3 have well established libraries, for simple implementation, without the need to know the mechanics under the hood, about the registers and such.
You can find links and general explanations at timer1. I always recommend the github versions.
And if you are still wanting to know the details the source is quite readible.

Note you don't need 3 timers to read 3 sensors. One timer on a multiple of the the 3, should suffice which can then implement a statemachine to sample at the correct periods.

I think you mean timer2, not timer3.


text:
What's the smallest Arduino board with wifi capabilities?
The Photon from Spark IO looks super small. Are there smaller wifi enabled microcontrollers available that can be programmed with the Arduino IDE?

It's impossible to answer this kind of question and that the answer will stay relevant for a substantial amount of time. Today it's chip X, tomorrow chip Y...

For a tiny arduino with wifi look at tiny-circuits. Not the cheapest option or easiest for prototyping. But quick and easy to get up. https://tiny-circuits.com/tiny-shield-wifi.html

From your question it implies that the Spark IO use the Arduino IDE - it's not. It has two different IDE's, one is web based and the other is downloadable. In addition, it's not an Arduino per-se. It is based on the Wiring library, which is similar to the Arduino library but not exactly the same. And of course the MCU is not Atmel, but that is also the case with Intel's Galileo board.
As to the size question in hand - my believe is that the Arduino products are designed for prototyping, so the size of the product is less important. This is the case for several reasons:

Costs -  the different Arduino products are pretty expensive for mass production.
Peripherals - the Arduino boards come with different peripherals (such as the FTDI chip) which will probably be omitted in an end-user product, and which makes its size larger.
Pins - almost every (official?) Arduino product comes with pre-built male/female header pins, which are excellent for prototyping but not for production, because of the large vertical space they take.

There are many more reasons, but you get the point.
When moving to production with an Internet of Things product, it makes sense to fabricate your own PCB, and design it with a small Atmel chip you used for prototyping (such as ATtiny85) and small Wifi chip, such as the ESP8266. This is an example for such fabricated PCB, although the size is not the 'smallest' possible.
However, for beginners, or a one-time project, it would absolutely make sense to use a pre-fabricated Arduino product, in a small scale that could provide both easy coding capabilities, various libraries and a WiFi included. For that purpose, the Spark IO seems to be at the bleeding edge at the moment - but you never know what will be there tomorrow...

thanks for the detailed answer and the great example, very helpful!

Hi Omer thanks for this useful post - I am looking at making a prototype and it's useful to understand that the production hardware will be different - I was worried about the height of those vertical pins and if they were necessary. I would like to prototype something where the software made is not throw-away so I guess spark (now particle) looks like a good way to go


text:
Reading keyboard input
I'm using Serial.read(); to read keyboard input from the serial monitor.
It only sends the characters after hitting enter or clicking the "send" button.
Is there a way to read keyboard input without having to use "enter"?

Not with the Serial Monitor built into the Arduino IDE. It is possible to use an external terminal program with buffering disabled though.


text:
Atmega328 component library for Protel 99 SE
Any one know a component library for Arduino UNO (Atmega328, etc) for Protel 99 SE PCB design software?

Found it here with 94 chips.
The author states, "I have made a little library for Protel 99SE with schematic sybols of AVR chips."
http://www.avrfreaks.net/forum/avr-8bit-microcontrollers-protel-99-library

All arduino design schematics are available from the Arduino website, e.g. for the Uno. However, these are in EAGLE format, I don't know if it's possible to convert.


text:
How to switch a low-voltage (1.5V) toy motor with an arduino?
I would like to add an Arduino to control a toy with a 1.5V battery and motor in it.  The toy is currently controlled by a SPST switch in series with a single 1.5V AA battery and a cheap motor.
I could put in a transistor like How to switch an external circuit with Arduino? or To connect a simple toy circuit and trigger with an arduino?  but I would think the voltage drop of the transistor would be significant in the 1.5V circuit.
What would you recommend for switching a 1.5V circuit?

You would be better off using a MOSFET which, when on, has quite a low resistance. For example the RFP30N06LE datasheet shows a RDS(on) of 0.047 Ω at 30A and 5V.
Using Ohm's Law we therefore expect a voltage drop of:
V = IR
V = 0.5 x 0.047
V = 0.0235

Thus, only 23 mV drop if you are drawing half an amp. I measured using a toy that drew 200 mA and found a 5 mV drop at 1.5V (compared to the theoretical 9 mV).
I have a page about driving motors that illustrates how you might wire up such a device.

The 12V on that schematic could just as easily be 1.5V.
The diode on the schematic is a snubber diode which protects the transistor from flyback voltages from the motor.

Comparison to transistor
BJT transistors will have a higher voltage drop between collector and emitter. For example the 2N3904 has a 200 mV drop (0.2V) (called VCE(sat)) when conducting 50 mA. This is a somewhat larger drop than the 5 mV drop that I got with the MOSFET, and a somewhat larger percentage of the 1.5V that you are starting with.

Cool, so if I snub the motor, I could jumper the Drain and Source terminals to my switch terminals.

Yes, the MOSFET will act as a switch. As per the schematic you want the Drain to be on the positive side. The Source would be the lead connected to the negative side of the battery.

Note that it is an N-channel MOSFET. Check the specs for the MOSFET you choose to make sure it can handle the current of whatever device it is that you are controlling. You could work that out by using a multimeter to bridge the switch connection (in amps mode) and get a current reading.

I'd always been a little shy of MOS devices because of static sensitivity from way back when my dad wouldn't let me solder a 4K dynamic memory board, but the device you linked looks like it has plenty of internal protection.

Those were the days! These days however I am careful but not obsessive about handling MOS devices. I mean, you don't dance around on a nylon carpet and then pick up a MOSFET, but if you calmly handle them after discharging any stray voltages by touching something which is grounded, you should be OK.


text:
Arduino Uno with SD, Cardinfo sketch how to list only visible files
There are two files (that can be seen on my computer) on my sd card, 6.bmp and example.txt (the latter written from my arduino). I have them connected to my arduino via LCSTUDIO breakout board (which surprisingly caused me no trouble at all).
When I run the example "cardinfo" sketch, the files it lists includes those two files along with tons of others, which I assume are just invisible from a personal computer.
How would I list only the files that can be seen from my computer (i.e. aren't inside any directory, but are just plain in the SD card)?
Using arduino UNO

Simple Answer: Don't think you can
Long Answer: Dont think you can, because, unlike an OS like windows, mac, linux, etc. The arduino just tales all the files. You could save those two files and format it as FAT16 though, then add the 2 files back on the sd and there you go.

Ok, I'm gonna go ahead and accept this,

Probably the best answer I can get for something thats apparently impossible,


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:
Android <-> HC-05 <-> Arduino communication issue
My project involves Android (Samsung Galaxy 2) to Arduino (Uno) communication via HC-05.
HC-05 is connected to Arduino on pins 10,11 using SoftwareSerial lib.
I got this setup running for a while and was satisfied by the outcome - my bi-directional communication worked fine.
Issue:
I made a change to the communication protocol and now messages sent from Android to Arduino get corrupted. It happens under particular circumstances - when Arduino writes (streams) packets of data to Android and, at the same time, monitors the input from Android for a particular message which signals the end of communication. This message, when read from SoftwareSerial buffer, gets corrupted. This corruption is not consistent - it corrupts the packet in (seemingly) random way.
I've already run many tests and am pretty sure that this message is not corrupted on the Android side.
Questions:

Is there anything about HC-05 or SoftwareSerial lib which prevents
simultaneous bi-directional communication?
Can it be that input/output buffers interfere in some way?
How can I achieve reliable communication using the aforementioned HW and comm scheme?

P.S. I got pretty much code and am not sure what parts of it might be relevant to this issue. Will provide relevant parts per your request.
Thx

As mentioned by @alex.forencich, SoftwareSerial is not designed to support simultaneous bi-directional communication.
I found a link to AltSoftSerial library on Arduino site, and this lib seems to work properly in my setup.
To convert from SoftwareSerial to AltSoftSerial you need to change the pins that HC-05 is connected to (on Arduino Uno these are pins 8,9), and to make this minor change in the code:
//#include <SoftwareSerial.h>
//SoftwareSerial swSerial(10, 11);

#include <AltSoftSerial.h>
AltSoftSerial swSerial;

Another option is to use a separate chip to send and receive. An Attiny87 (picking a random example) has a UART and an SPI interface - it could receive the data via UART, send via SPI to the Arduino; then receive the data from the Arduino and send it via UART. Since the whole chain now has hardware support, you're going to have reliable communications. The data could be buffered on the AtTiny, and raise a signal to the Arduino to say when data is ready.
ATTiny chips are cut-down versions of the ATMega chips used on Arduinos, and they can be programmed over ISP. They can be had for a few dollars.
Yes, this is a lot of extra work.

Software serial ports are a hack and this is the result - random corruption, missed bytes, etc. The reason is that very precise timing is needed for both receive and transmit and it is very difficult to achieve this with the CPU, especially if you want to simultaneously receive and transmit. The problem is that the CPU has to either read the pin or update the pin at exactly the right moment, and the CPU can't do more than one thing at the same time. You can use interrupts, but it is still possible for the TX and the RX to conflict, and there is nothing you can do about it.
The solution is to either never run RX and TX at the same time, use a different serial protocol where this is not an issue (e.g. I2C), or use a hardware serial port. I would suggest using an Atmel XMEGA microcontroller - you can get these with 6 or more independent hardware serial ports.

Got your point - SoftwareSerial is not reliable in these circumstances. It led me to look for an alternative (I can't switch to other micro right now), and it seems that AltSoftSerial lib resolves my issues. Thanks!

Software serial isn't necessarily a "hack" in the microcontroller world; it's a perfectly fine way of doing things if you're careful with your programming. Nor does the timing need to be all the precise, especially for reads, and especially at lower data rates. A 16 MHz ATmega has plenty of horsepower to run several simultaneous 115,200 Kbps software serial links and do some other stuff at the same time, when programmed properly. The main issue here is really more that the Arduino libraries are focused on ease of use for hobbyists, rather being able to put together efficient code.

An alternative to software serial is to use hardware serial.
You can use hardware serial (i.e. supported in hardware by the chip) using pins 0 & 1. You will NOT! be able to do serial communications (e.g. programming your arduino) at the same time - I always make sure I have EITHER usb OR bluetooth serial connected at any given time. USB for power is ok.

This means that I won't be able to send "debug" messages into Arduino IDE when communicating, right? This makes this approach very restrictive (at least for Arduino Uno), since one of the reasons I use Arduino is for debugging the communication protocol and its implementation.

Yes and no - the "debug" messages would come in over Bluetooth. This may be enough. Yes, it is a tradeoff.

Actually, they'd go both over bluetooth and to a connected PC, in the later case mixed with whatever commands and framing keep the BT module happy.

Hey thought I'd pitch in.
I was having quite a few issues in trying to control an led using hc 05 from an android phone.
I was using SoftwareSerial. It didn't work.
The board is an arduino mega 2560.
Finally, I got it. SoftwareSerial turns digital pins to tx and rx com pins.
Make sure to use digital pins on the board to communicate when your using SoftwareSerial.
Hope it helps...


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.