text:
Sense Whether Circuit is Closed
How can you sense a closed circuit? I want to have 4 pins with disconnected wires and when touched with a fifth wire play a specific note on a piezo buzzer until disconnected again.
This project loops through several keys and checks whether they are being touched using the Capactive Sensor library. I want to do something similar, but not with capacitive sensing. Alternatively, it may work to have the buzzer always trying to play a note, but only sounds when one of the 4 circuits is close. I'm just not sure how that would work in the code.
Here is their code that uses capactive sensing:
#include <CapacitiveSensor.h>
#include "pitches.h"

#define COMMON_PIN      2    // The common 'send' pin for all keys
#define BUZZER_PIN      A4   // The output pin for the piezo buzzer
#define NUM_OF_SAMPLES  10   // Higher number whens more delay but more consistent readings
#define CAP_THRESHOLD   150  // Capactive reading that triggers a note (adjust to fit your needs)
#define NUM_OF_KEYS     8    // Number of keys that are on the keyboard

// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:
#define CS(Y) CapacitiveSensor(2, Y)

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:
int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale

// Defines the pins that the keys are connected to:
CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};

void setup() {
  // Turn off autocalibrate on all channels:
  for(int i=0; i<8; ++i) {
    keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
  }
  // Set the buzzer as an output:
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  // Loop through each key:
  for (int i = 0; i < 8; ++i) {
    // If the capacitance reading is greater than the threshold, play a note:
    if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {
      tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed
    }
  }
}

Connect your fifth wire to ground. Set the four inputs to INPUT_PULLUP. The four inputs will default HIGH, and be pulled LOW when connected to the ground wire.

Inversely, you can also set the inputs to INPUT_PULLDOWN and have the fifth wire connected to +5v, which will pull the pin HIGH when connected, and LOW when not.

Assuming you're not using a AVR of course, since those only have pullups.


text:
Arduino Yun - not enough i2c & interrupt pins?
I'm trying to build a small personal weather station. The rain sensor, and wind speed sensor use interrupts. The barometric sensor uses i2c SDA and SCL.
Reading the Arduino Yun manual, it says there are 5 interrupt pins, but 2 of them are SCL/SDA (pins D2 and D3), and 2 of them are serial comms between Linio and the 32U4 (pins 0 and 1).
This leaves me with 1 interrupt pin left (pin 7).
Is there a work around to get my 2 digital sensors AND SDA SCL pins connected?
If I do use pins 0 and 1 (Linux serial), what do I risk? I will need to use the Bridge to relay information to the internet.

Any of the port B pins on the ATmega32u4 can interrupt on pin change. Unlike the external interrupts however, these pin change interrupts share the same interrupt vector. So in the interrupt routine you have to work out which one fired.
The port B pin change interrupt is not support by the Arduino core library so you have to download a third-party library. This one seems fairly recent:
https://code.google.com/p/arduino-pinchangeint/
Then you connect your two interrupt lines to spare Port B pins and monitor for pin changes.

Worked effortlessly after installing the library. Thanks!

OR the interrupt lines together so that you only need 1 external interrupt. Then when an interrupt is triggered, poll the devices until you find the one that triggered the interrupt. If the interrupt outputs are open-drain then you can wired-OR them together, otherwise you will need something like the 74LVC32 to OR the push-pull outputs together.

And I was going to show you how to do it here, but there's no schematic button in the editor.

source: Stack Exchange

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

sort: votes


text:
Ultrasonic PING: multiple trig on single dig. pin
This may seem a little stupid, i apologize  if so as i'm new to electronics/arduino.
I have 4, 4-pin ping sensors. I'm running out of available pins on my UNO.
I had a ponder & wondered if it was possible to link all 4 sensor's trig pins to a single digital pin, with the echo pins assigned to their own pin. In my head, on each sensor call (sorry i'm used to programming terms) all 4 sensors would send a pulse, then only the sensor (or echo pin) in question would be read. Is that plausible? each ping sensor is about 20-30 cm separated, but facing internally, in a spiral downwards.

I don't see a problem. Should work.

The problem with this wiring is that you won't be able to use pulseIn method to get the echo pins durations.

well, pulseIn will not stop working, but it can only  measure one of the sensor's results at a time so the others signals are wasted. It is possible to write something that could measure all the pulses simultaneously, although it is not the easiest thing in the world to do.

I was able to achieve the result using my suggested method in the question.
As BrettAM stated, the signals are wasted on the other 3 pins when checking 1.
This solution was suitable as a proof of concept

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


text:
How to copy files from Yun to local computer?
I would like to copy a file that is in the root folder of my Yun, to my Macbook. They are connected with an ethernet cable and I am logged into the Yun through ssh.
The Yun's IP is 192.168.2.16 while the Mac's is 192.168.2.1.
How can I copy a file from the Yun?
Once I tried to copy a file from the Macbook to the Yun using "scp" and it worked, but now I don't know how to do for the other direction

You simply reverse the arguments.  Whatever you used to copy a file to the Yun you just do the opposite to copy from the Yun.
For instance, if you copied to the Yun using:
scp /my/local/file root@192.168.2.16:/where/you/want/it

Then you would change it around to copy from the Yun thus:
scp root@192.168.2.16:/path/to/file /where/you/want/it/to/go


text:
Low power + Logging motion detection
Scenario: I would like to monitor my closet's door as I highly suspect a family member is opening and using my items without permission. To respect privacy and also because my closet is nowhere near a power mains, I don't need video nor audio recording. I also do not need indicator lights etc because I intend to turn it on when I go to work and check the logs on the SD card when I return home. A typical day would require the device to run for 12 hours minimally.
Aim: Is it possible for Arduino to achieve the following,

Run on batteries for at least 1 month
Detect motion
Logging the detection motion onto a text file in a SD card

Or do I have to look elsewhere for this functionality?
Current understanding: I am aware Arduino can run on batteries though I've never been able to get it to last more than 3 hours. Probably has to do with me not using the low power mode or something and that my batteries were being stepped up. I also know that Arduino has some PIR motion sensors though I don't quite remember how power hungry these sensors are. I have NEVER tried logging onto an SD card using Arduino. This sums up my experience with Arduino.
Any advice would be much appreciated. Thank you.

You would be better off with a bare ATmega chip than an Arduino - you want to eliminate extraneous circuitry like a USB converter, regulators with quiescent current draw, and any resistors pulling signals against their usual state.  Fortunately the ATmega chip has a fairly wide voltage range, especially at 8 MHz or below, so you can use something like 3 cells, alkaline or rechargeable, over most of their range.
An SDcard is neither necessary, nor a good idea.  If your circuit won't be discovered you can probably hold the data in static ram while the ATmega sleeps; if not, the quantity of data would probably not exceed the on-chip EEprom and would certainly not exceed that of a 4 megabyte SPI flash. Either of these will be far more robust (and low power) in a battery powered situation than an SD card.  They will also be simpler to support in software.  Either an SPI flash or an SDcard will probably have a narrower supply range the the ATmega and require a regulator - you may be able to enable that only when you need to access the memory.
Your main power consumption win however will be sensors.  If you can use a contact sensor - either a direct switch, or a magnetic reed one, that will result in the lowest power consumption.  Your next option might well be an accelerometer chip, specifically if you choose one which can run in a micropower mode and fire a wakeup interrupt to the MCU when it detects that a door it is mounted on is being opened.  Anything with light is likely to have much higher power consumption and could well be impractical, unless you figure out how to operate it in short bursts with a lengthy inactive time in between.

ok so i could do without a SD card but how do i go about retrieving the data if i store it on the on-chip EEPROM or static RAM? RAM is fine actually since i don't need persistent data, just the mere fact that someone opened the door i.e. i want to track the number of times the door is opened in the period that i am gone so that i can go hammering around to find out who actually opened my door.
a contact sensor....i might consider that...just need to factor debouncing as my door isn't exactly tight so a kick or a nudge may set off the program to count as an event occurrence.

Probably have it upload the data over the serial port.  That does mean that for ram you would need to either disable auto reset or stop the utilized part of ram from being intitialized on reset.

hmmms...it is going to be a standalone though so having a serial port doesn't sound feasible. trying to find a way to stop ram from being initialized on reset..is that even doable?

RAM is cleared by software.  Removing the module for serial download should be possible if removing an sdcard is.  Having a button and LED to flash the open count might be easiest, and can mean no issues with trying to stop a USB serial from consuming power...

hmmms so a button and LED huhs. that sounds like a good idea...if i go for purely the chip alone, the USB serial is only needed when i flash in the program right? after that I can take it out which should hopefully help with reducing power consumption

It is possible to modify an Arduino Pro Mini (clone or original) to less than 1 mA and give at least a month on standard batteries (1000 mAh). Basically you need to remove the Power indicator LED and use low power mode in the sketch.
You could start simple by just lighting a LED when motion is detected and add the SD log later.
There are several techniques to detect motion. Advanced accelerometers such as ADXL345 but also simple wire sensing. The standby power requirements for these have a large variation.

Hmmms thanks for the prompt suggestion. WIll have to read up more on what a clone Aaarduino is.
Preferably i would like my device to function somewhat like a motion sensor that is installed in a lot of toilets and offices where lights turn on upon detecting motion. in that sense, a simple PIR sensor would do well. I will look into wire sensing though but an accelerometer seems overkill =)

PIR will work great. Advantage is that you can connect it to an interrupt pin on the arduino, to make it wake from sleep, when motion is detected. But since the arduino is sleeping, it will have no sense of how much time has passes. So you probably would want to add a RTC module, so you can log the exact time and date of the motion event to the SD card. Another option for motion sensor, is a vibration sensor

yup im looking around for a reliable PIR sensor but it doesn't seem there are much choices on Sparkfun...
i don't need exact time though. just the mere fact that someone opened my cupboard during the time that i am away is sufficieint. so a RTC might not be necessary =)

For low-power, just some tips (link references)
https://github.com/petervojtek/diy/wiki/Arduino-with-Very-Low-Power-Consumption
claim the below results,
LED off, without the JeeLib library: 6.7 mA
LED on, without the JeeLib library: 8.8 mA
LED off, with the JeeLib library: 43 uA (!)
LED on, with the JeeLib library: 2.2mA

https://github.com/petervojtek/diy/wiki/Arduino-with-Very-Low-Power-Consumption
Detailed step by step tutorial.
For sensing PIR will depend on exact components; using SMD low-leakage components will do the trick but cost would increase. There are very-low-power RTC on the market and maybe SD logging will be more difficult as can consume up to 200 mA per reading/writing operations.

Hmm...I see...thanks for the reference and the info on SD logging. didn't know it was so power hungry. do you have other suggestions for logging? the data only needs to be present for 1 day as i will do daily checks.

well, if you encode your time-stamp in two bytes you can store 128 events on 256 bytes.

You have 32,256 of total program space in Arduino UNO and supposing using a 95% of that space for your program it will leave approx. 1,612 bytes, but who will open the door more than 806 times per day???

hahahahaha good point! i just need the occurrence of the event being logged. time is not important so i guess i can probably do with the existing program space then.

The PIR sensors are actually pretty cheap: http://www.ebay.com/itm/like/171338717482?ul_noapp=true&chn=ps&lpid=82

thanks ^^ still thinking of what sensors to use since power is a major concern. i didn't think about light based sensors being power hungry but after Chris Stratton mentioned it, i might drop the idea of using PIR even though it is freaking convenient!


text:
How to setup Arduino Wifi Shield with Red Bear Lab BLE Shield?
I'm new to Arduino shields.
I'm trying to stack these two shields on an arduino uno for a home automation project.
1 - Arduino Wifi Shield:
2 - Red Bear Lab BLE shield: http://redbearlab.com/bleshield/
I have pin contention, between the two shields:
The WiFi shield uses pins: 4, 7, 10, 11, 12, 13.
The BLE shield uses pins: 10, 11, 12, 13.
Is there a hardware or software way to allow the two shields to work together?
I saw in a similar thread, someone reccomended a go-between shield: https://www.sparkfun.com/products/11002, would this be something that I could use in this case?
If it's not possible, are there other shields that will work together?
Thanks

I'm trying to do the same thing.  Did you ever get this to work?

Not exactly...
I was able to switch around some pins in the library to compile and get past the setup for BLE and WIFI. It works running on the BLE shield doing all the normal stuff, but as soon as I tried to use the WIFI shield to send an email, it crashed.
Haven't had time to look into a proper fix yet.

Hey I just saw this: gonna wait to buy one once it's released: https://www.kickstarter.com/projects/1991736672/redbear-duo-a-small-and-powerful-wi-fi-ble-iot-boa?ref=category
I have their BLE board, really like it. Super excited for this.

The way the Arduino talks to each of the shields is by first telling the device that it wants to communicate with it, and then by exchanging information with that device. The Arduino uses 3 pins, 11, 12, and 13, to communicate to both the shields, and a 4th pin which it uses to select which of the devices it wants to use. This way the Arduino can use connect to two shields at once, by just selecting one at a time
I did some research, and found that the selection pin on the WiFi shield (which I believe is the same as yours: https://www.arduino.cc/en/Main/ArduinoWiFiShield) are pins 10 and 4; pin 4 for the SD card selection, and pin 10 for the WiFi selection. Now since pin 10 is used as a selection pin for both the WiFi shield and the BLE shield, you run into some problems: both the boards will be selected at the same time when pin 10 is used. In this case, you can use the Sparkfun go-between board you linked.
I've never used it myself, but it appears to be able to change what pin is attached where on the shield it's attached to. In this case, you want to put the WiFi shield on the bottom, then the Sparkfun go-between shield, then the BLE on the top. You want to set up the go-between shield to change pin numver 10 to another pin that's not being used (any pin but 11, 12, 13, 7, 4, or 10).
In the Arduino code you will at some point declare which pin is being used to select which board. In this case, set the WiFi selection to 10 (default), the SD card selection to 4 (default), and the BLE selection to whatever pin you changed pin 10 from with the go-between shield. This way, when you select the shield on pin 10, it will only select one shield, rather than two.


text:
powering RF on GPIO
I have been running a simple RF link between 2 arduini uno recently and everything went faily well. I am now trying a new project with an arduino mini pro (5V/16MHz) and the seeeduino RF link (@315MHz), and I see very odd results : when the transmitter is on USB cable, the link runs ok, but when on a 9V battery (as raw voltage input), I get very very limiter range (a few inches).
Because the setup works on USB, I'm assuming that the current limitation on the GPIO that powers the RF transmitter is not the issue here. It therefore has to be the battery itself or the regulator.
Somehow I need to use a GPIO to shut down the radio during power saving phases. My current design is very basic, I should probably add a transistor to enable power on the RF. I was also thinking maybe the RD oscilliator needs to settle down a bit, I may need to add some delays before starting to send data. I can see on the oscilloscope that the data and power PINs seem to behave correctly, although I have noticed a voltage drop on the power pin which is similar in pattern to the data transmitted (but again this is no issue unless using the 9V battery).

9V batteries can't provide that much current. You should measure the current consumption of the RF module. You could try adding a electrolytic capacitor, parallel to the battery. You could also power the RF module directly from 9v, to increase the range (higher voltage; better range). But I'd just use a battery pack, instead of a 9v battery.

You should never power anything from an GPIO pin except incredibly low powered things (<20mA), and an RF transmitter certainly does not fit into that category. Google "High Side Switch MOSFET" for a circuit that can help you

Thanks all, I appreciate that I need to use a power switch in a proper design, maybe then I can use the 9V directly. I'll be looking out for these high side switch.

As established in the comments, the issues here are powering the module directly from a GPIO pin, which are limited to 20 mA, and potentially the limited current of a 9V battery.
Personally I avoid using 9V batteries in projects, as they are comparatively expensive for the lifetime they provide. There are various boost/step-up converters that make a steady 5V supply from two AA batteries.


text:
Uploading Marlin Firmware To Melzi-ATmega1284p
I'm trying to flash the Marlin Firmware to my Prusa i3 3D Printer, which uses Melzi 2.0 board. Melzi is a variation of Sanguino, and Sanguino is a variation of the Arduino.
The problem is that the version I'm using of Marlin (this one, development branch) only works with Arduino Mega. I saw that the file pins_RAMPS_13.h says the following (line 15-17):
#if !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__)
   #error Oops!  Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu.
#endif

So I tried to make this part to look like this:
#if !defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__) && !defined(__AVR_Melzi_ATmega1284p16mhz__)
   #error Oops!  Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu.
#endif

Does anybody know if there's another repository made for the Melzi board?
Or if I should use another firmware, like Repetier (I tried, fail)?
Thanks for any help.

You can't add arbitrary devices to a conditional check and expect the code to work. The code needs to be ported to the device.

It looks like the Marlin firmware supports two versions of the Melzi board, although it isn't clear if it specifically includes the 2.0 version. The best thing to do is just try it. In the Configuration.h file find the section where it says:
#ifndef MOTHERBOARD
  #define MOTHERBOARD BOARD_ULTIMAKER
#endif

Now replace BOARD_ULTIMAKER with BOARD_MELZI_1284 and try that. If that doesn't work you can try just BOARD_MELZI. If neither of those work, you are out of luck, unless you are willing to dig in and do the pin mappings yourself.


text:
Sending values to an Arduino Yun across different networks
I have quite a lot of experience with Arduino but have recently been faced with a challenge that has stumped me. The project is to create a robot that can be controlled from a separate network than it is on. I had the idea of using the Yun board to receive the values. Does anyone know a way I could have a computer send data to a Yun on a different network? (Maybe through a website?)

What are the separate networks, how are they connected?

One is my home network, and the other is a network at my workplace. Otherwise they are not connected

This is a very open ended question. What have you tried or have in mind to try? Add some more details and you may get a better response.

I have accomplished this, first by reading this article on controlling a Yun through a web-browser on the same network. From there it was a matter of allowing my Yun to be accessed externally (setting up port-forwarding on my router) and changing a few lines of code to reflect the new location reference.
All the necessary files and code are included under the heading "Project Files" in the above link and no modification is needed to get it working within the same network. That said, I had to convert the two .jpg files to .png (and change the filenames in index.html) - I don't know why they wouldn't show up in my browser.
In brief:
The Yun hosts a webpage (index.html) which contains some indicators and control inputs. These objects are linked to the 32u4 using Bridge and the REST API - nothing special. The bulk of the html code is for visual purposes, and the actual REST calls are nice and simple.
What is good is that the webpage can be accessed from anywhere with the right jiggery-pokery, and with a little more determination can be hosted from anywhere.
External Access
Once you have that working, you need to do the following to allow access externally. I tested this using my smartphone - disconnected from my home WiFi of course - to ensure the link was over the Internet, not intranet.
1) Set up port forwarding and a static IP for the Yun. This is the fundamental step if you simply want to control your Yun over the Internet. However, I can't actually tell you how to do this because I don't know what equipment you have! Information is all over Google for setting up both DHCP static IP and port forwarding.
2) Get a static IP from your ISP for your home/work, or set up a Dynamic DNS service (these people offer it free, but I've never actually needed to use an external service). Most commercial ISPs tend to dish out static IPs, but that's no guarantee that yours will.
3) Access your Yun with a browser via: http://YOUR.IP.ADD.RES:PORT/arduino/<SketchName>.
External Hosting
If you want to host the webpage on something other than the Yun, you can! You will of course need a server to host this, either your work's central server or an external hosting service. You'll need to change some more lines in the code:
1) In the Yun sketch change server.ListenOnLocalhost(); to server.noListenOnLocalhost(); - the subtle difference is the 'no', and is essential for external control. Sorry, that's incorrect without a little more explanation than is required at the moment to answer your original question.
2) In the .html file, you need to change each instance of:
server = "/arduino/<SOMETHING>";

to
server = "YOUR.IP.ADD.RES:PORT/arduino/<SOMETHING>";

If you have the REST password set to ON then you have to incorporate the username/password in there too:
server = "username:password@YOUR.IP.ADD.RES:PORT/arduino/<SOMETHING>";

There are three occurences in the original file, so be sure to catch them all.
3) When making changes to the .html file, make sure you re-upload it to the external host, not the Yun - that mistake took me hours to figure out.
A little more...
While searching for the URL of the article in the opening paragraph I found this atricle on a similar theme. It looks to have plenty of information although I haven't read it yet fully yet; I've been busy writing an answer on Stack Exchange. External Access should be no different, and if you want the 'External Hosting' version you just need to find any line that references the 'server' as "/arduino/..." and change it to "YOUR.IP.ADD.RES:PORT/arduino...".

Basically your yun is a linux box with a arduino connected to it on port /dev/ttyATH0.
If you know linux that should answer all your questions about what is possible.
I have setup my own bridge and communicate via html to my robot using cgi script and lua.
I have demoed this on a web contest and you can see it in action on this video from 15:25 onwards https://www.youtube.com/watch?v=q0CnB7Yzpfg&index=3&list=PLCSjf7QmP3TCOLIw0lMPbwHtKrO-nwfKG

You havent mentioned what exactly your robot does, for now I am going to assume it is something as simple as switching on a light etc and not something like a rover.
The easiest way would be to make the YUN read from a db (like mysql, etc.) and depending on the value perform a task.
For example, you could have a row called light, if the value of it is 1 then turn on the light else turn off the light
The problem you are going to face is the power consumption as you will constantly be polling from the database. You could also look into push notifications ( I am not sure if it is applicable here)
You could also look into creating a private VPN and connecting the YUN and your other devices to it and then control it.


text:
Arduino Mini Pro not working with my Neopixel project
my project involves 9 Neopixel LEDs. I have tested my code with my Arduino Uno board successfully. I'm using a mix of breadboard, jumper wires, and solder to connect everything. Powering the strip of 9 LEDs with 4 AA NiMh rechargable batteries, showing 5.2v on the meter. I've put a capacitor (1000mF 25v) in the circuit, right at the power source.
But when I upload the same code to my Mini (5v/16MHz) and swap it in in place of the Uno, I get nothing. No matter how much I jiggle wires or provide a good ground (which helped me get good results from my Uno). Every now and then by messing with wires, or as a few minutes go by, the first few lights might light up, but not in the right colors and no animation.
Just to test the Mini board I uploaded the sample program "blink" and the mini runs that one properly. So I'm certain my code is getting on there. My program is definitely bigger and involves some quick changes (I'm making an "ebbing" glow of supernatural eyes). Connecting the Mini to the Neopixel strip I soldered a wire with a female jumper onto the board, and my strip of lights has a wire soldered on with a male jumper. As a side note, it takes a little physical handling to get the project to work with the Uno (like pressing a little bit on the data wire in it's plug on the Uno or using a jumper wire in the breadboard clamped in a metal measuring tool and my hand to ground out the circuit). So maybe I'm just experiencing some of the shortcomings of the Mini, but I was under the impression that it would do just about anything the Uno could do. Especially in terms of just providing a data line for the LEDs.
I'm new to Neopixel. This is my first project in fact. So it is entirely possible I'm doing something wrong or there's something I just missed completely, or maybe my luck just sucks and I have some piece of faulty hardware... No idea.
Any suggestions would be most appreciated!

For debugging your hardware (which sounds like the problem), use a simple sketch that just turns on one Neopixel after another, and power it from the wall instead of batteries.

I'll give that a shot! I'll whip up a quick and simple sketch tonight like you mentioned and see if I get some results.

Ugh. Don't know what's going on. I made a simple program, tried it, and nothing happens. I load up the program in my Uno, works fine. Tried soldering some connectors to another mini (I bought 3 of them) and nothing. The struggle continues... Still in the dark as to why. I just watched a video of someone lighting up a string of 144 lights with animation using a mini. So I know this is supposed to work. Oh well. Thanks for the suggestion, jwpat7. I'll continue troubleshooting.

Some random ideas to check:  Are there ATmega328 chips on both your Uno and your Mini Pro? (Ie are the processors the same on both, as one would expect?)  Have you verified +5V on all the +5V pins?  Perhaps post a closeup photo or two, in your question, in case of some wiring error like hooking unregulated power to Vcc, or regulated power to Raw (which conceivably might work ok with the Blink program but not with something that requires more current).

A quick glance at the boards confirmed they both have the Mega328 printed on them. I'll check voltages at each pin tonight and snap some pics when I get the chance later. Watching the YouTube video I also noticed that the light on the mini was either green or blue couldn't tell with the quality of the vid. My minis have both shown solid red on the boards. I assumed that meant "power on". Maybe it means there is a problem with power? It also occured to me that the board may not like running off of USB power through the FTDI adapter.

The power-indicator LED is red in several mini-pro videos I looked at (vs green on some other Arduino models).  (I don't remember the color on the mini-pro boards I have, and most are inside cases where I don't see the lights)

As I was playing around today I found a solution. Powering the board through the FTDI adapter, which in turn was being powered by a USB juicepack charger, wasn't supplying enough juice and/or ground. It was enough for the Uno to work, so that's what was confusing me. I soldered in a 9V battery and clamped down on the pins with a wrench to ground it out. That made the board happy and it kicked into gear and lit my project up perfectly. It's pretty ghetto but it works! Yeah! :D


text:
Arduino serial informations
Is it possible to change serial information of arduinos board ?
For example I have an arduino uno with this serial informations :
{
      comName: '/dev/cu.usbmodem1411',
      manufacturer: 'Arduino (www.arduino.cc)',
      serialNumber: '75430333137351804230',
      pnpId: '',
      locationId: '0x14100000',
      vendorId: '0x2341',
      productId: '0x0043'
}

I want to modify for example the manufacturer to be able to automatically detect the device whatever the comName is. I don't want to detect arduino board I want to detect arduino board modify by me without make a serial connection.

Have you purchased a vendor ID yet?

No didn't know that was possible... Where I can buy one ? How to use it after that ?

Once you have purchased a USB vendor ID you can edit the firmware within the Arduino installation at hardware/arduino/firmwares/atmegaxxu2/arduino-usbserial/ with your vendor ID, chosen product ID, and other USB parameters as you wish and then rebuild the firmware and upload it to the ATmega16U2 on the board via ISP.
If you do not wish to purchase a vendor ID for the time being then you can use 0x6666, the prototype vendor ID, in the meantime, but you are not allowed to make products using that vendor ID available to the public.


text:
Picking an Arduino
I'm looking to develop my own personal SmartWatch, hardware, software, and all. My problem is starting off on the hardware portion of it; more specifically what platform I should build it on. I already have an Arduino Uno (R3), nut I was hoping to find something a bit smaller. Any recommendations on what parts I should use?

Asking for purchasing recommendations is somewhat off-topic. You could always use the "raw" Atmega328P chip. That is smaller than the Uno.

What you start with is not too critical as you can develop basic concepts on any Arduino hardware and use it to drive a display of your choice for testing. This can be migrated to whatever is found suitable as the project progresses.
Important to consider are the number of I/O lines of various sorts that you need. Most AVR ICs that you are liable top use will have "some" analog input and PWM output lines. If you were going to drive a "bare" LCD you may need to use a processor with LCD drivers, but in  most designs use of an existing module with eg SPI interface is probable preferable.
Most Arduinos in the UNO, Nano, Pro Mini, ... range are in reality not a lot more functionally that a processor IC, USB bridge (if needed) and voltage regulator(s). For a tidily small watch you may ultimately wish to use a bare SMD AVR IC with an Arduino boot loader code installed. You can move away from AVR ICs to other Arduino compatible systems - with some extra knowledge needed in most cases.
.____________________________________________________
Examples only:
Here is an Internet of things hardware roundup which includes some small controllers as examples.
Panstamps offer MSP430 and ATMega328p (Arduino compatible versions).

. _______________________________________________
RFDuino - from here offer some fingertip sized products with RF capability. Note that this use an ARM Cortex M0 processor, not an ATMega controller. While it is "Arduino compatible" it will not run all code that the typical UNO, Nano, ... boards run.
Manual here

Their Kickstarter page

Why not start with your Arduino Uno, it's got lots of I/O pins, and it's a great little device to start prototyping your watch.
You could add a number of sensors/peripherals such as

a Bluetooth module, - connect your phone
an IMU, - detect different excercises from your wrist movement
a tiny motor - to make the watch vibrate
a speaker for audible notifications
tactile buttons for switch between modes and functions of the watch
a LCD screen, - to see the time and other data
maybe a few LEDs as a torch function.

Once you develop your code and your happy with it, you could shrink your board accordingly, because you will then know how much I/O pins you'll need, and what voltage these sensors need to operate, and their inputs (analog vs. digital). You could even design your own PCB board with all these sensors.
You could use the Uno as a stepping stone.

One Possibility is that you could just use an avr chip without the arduino breakout, but still include the arduino bootloader, and this way it would be easier for you to isolate your preferred features, however with this method you would be sacrificing some safety without short circuit protection, and it would be a bit more work to upload, but this is also the cheapest.

Possibly related: https://create.arduino.cc/projecthub/Sourcery/smallest-arduino-in-an-attiny85-6f714d

Have a look at the LilyPad (Main Board, USB, Simple) and Gemma. The Gemma may have too few I/O pins for your needs, but it really does look small.

I have quite a few nanos / mini pros that I got as plain avr boards. they are great little things.
I also got a few minimus avr - if you want to venture outside of arduino. like the at90 usb stick / key, they are little boards that are 100% self-contained. they are ideal to play with on long flights.

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


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

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

void setup() { }

void loop() { }

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

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

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


text:
How to program for two Arduinos with different code but share one same .h?
I am now programming for two Arduinos. One is used as Tx and the other is Rx. Of course they are programmed by different codes, but they share some same .h files I programmed(let's say 'share.h'), which are not libraries and shouldn't be put in Arduino's 'library' folder.
So I put 'share.h' and main.ino in one folder, and the ino is like:
#include "share.h"
#define TX
#ifdef TX
void setup(){...something for Tx...}
void loop(){...}
#else
void setup(){...something for Rx...}
void loop(){...}
#endif

The shortage is that every time I want to update my code to the two unos, I have to: first change the board port to 40(the Tx uno) in ide, add the #define line, and upload. Then I have to change port to 42(the Rx one), comment the #define line and upload. So inconvenient!
So do you have any good ideas? Much appreciation!


text:
Setting data pin with NanodeUNIO
I'm using a sketch that helps to reset Da Vinci XYZPrinter cartridge EEPROMs, and it's based on the NanodeUNIO library. It uses digital pin 7 for data. I want to use my TFT Touch Shield to set the extruder temperature, but the shield also makes use for digital pin 7. Being that the sheild is wired to use pin 7, it can't be changed. But any pin that can be used as a digital pin should be useable with NanodeUNIO (at least, that is my assumption), but I can't find where in NanodeUNIO it sets the data pin. Where is that pin set, and how can it be changed?

Did you try looking for a call to pinMode()?

It has a single call for pin 13, which is the LED to tell you when it's done. The pin is used both to red the contents of the EEPROM as well as to set it. Full code is here: https://github.com/voltivo/davinci_filament_reset_arduino/blob/master/xyz_dv_eprom.ino

xyz_dv_eprom.ino uses low-level access rather than Arduino calls to manipulate PD7, most likely for speed reasons. Lines 96 through 104 (specifically 96, 97, 100, and 104) need to be modified in order to change both the port and the bit used.
ATmegaXX8 pin mapping
ATmegaXXX0 pin mapping
ATmegaXXU4 pin mapping


text:
How to program for two Arduinos with different code but share one same .h?
I am now programming for two Arduinos. One is used as Tx and the other is Rx. Of course they are programmed by different codes, but they share some same .h files I programmed(let's say 'share.h'), which are not libraries and shouldn't be put in Arduino's 'library' folder.
So I put 'share.h' and main.ino in one folder, and the ino is like:
#include "share.h"
#define TX
#ifdef TX
void setup(){...something for Tx...}
void loop(){...}
#else
void setup(){...something for Rx...}
void loop(){...}
#endif

The shortage is that every time I want to update my code to the two unos, I have to: first change the board port to 40(the Tx uno) in ide, add the #define line, and upload. Then I have to change port to 42(the Rx one), comment the #define line and upload. So inconvenient!
So do you have any good ideas? Much appreciation!

So, you want a common file, but you don't want to put it in a common file location?

Are you on a real operating system, or are you using Windows?

@Majenko Sorry but can't quite follow you. What's a real operating system? I'm using windows 7.

Then you're not using a real operating system and I can't suggest a way to do it in the Arduino IDE.  If you were using a real operating system like Linux or OS X then you could create a symbolic link so that the share.h file was shared between two locations.  Instead you can't because windows doesn't provide that most basic of facilities.

@Ignacio Vazquez-Abrams Er you can say it is, and there may be other ways.

Something easier than writing or removing two backslashes? Uhm... How can you determine what is the device you want the program to be compiled? Since I suppose that the hardware is the same, the only easier solution I can figure out is to make two different programs and then open them in two different Arduino IDE windows. This way you won't even need to switch port...

@frarugi87 but then how to share the share.h? This is the main problem.

Modify your hardware to produce a HIGH on a digital input, then have your program decide whether it's TX or RX based on that input.  Then it is always the same code, plus a resistor.

Thanks to everybody, now I get a better solution. It is changing the build path to our working directory, and then we can use relative path!
Here are the deatiled steps:

Click IDE's File-Preferences and find where it storages preferences.txt. Mine is at C:\Users\Administrator\AppData\Roaming\Arduino15\preferences.txt
In the txt file add this line: build.path=D:\MyProject\ArduinoBuild. This means let Arduino put the temp files in this directory, such as the .h waiting to compile.
Because the .h Arduino automatically generated from our .ino is in ArduinoBuild directory, you can now use #include "./../Share/SomeShare.h" in order to include the D:\MyProject\Share\SomeShare.h

Here is the same question asked in another stackexchange board: Here

If your answer worked, select it as the correct answer.

@lan M It says i can only do it tomorrow.

I confronted this exact issue a little while back when writing some sketches that hard shared information. In particular github.com/nickgammon/arduino_sketches
Whilst another IDE may help, I wanted to make my sketches usable by people with the default IDE.
There are a few (annoying) issues here:

You can't use relative folders as suggested in another answer, because the IDE copies your current sketch folder to a temporary folder and compiles from there. It won't copy other nearby folders that happen to be mentioned in .h files.
You can make soft links (in Linux anyway) as suggested, however that makes it hard to do Git control on them. My first attempt had the link (only) appear in GitHub, which meant that the links didn't compile, once you downloaded them (via the .zip file option in GitHub).
I switched to hard links, but then had another issue. If you edit a file in the IDE, and save it, evidently this becomes a new file, and so the files in other folders, which are now hard-linked, have the older version and not the newer version.

The best solution I could come up with (and I am open to suggestions) was to have a "master" sketch - which has the "real" files you want to include. The other folders have links to them. However if you change the master folder you have to recreate the hard links. I wrote a shell script to do that, but it is still an ugly solution. However since it is a manual process anyway, under Windows you could simply make a copy of the files, when you change the master one.
The other (simpler) alternative would be to make a library, and then simply change the files in that library. That gives you better Git management. The only thing is that you have to edit the library, and then go and test the sketch. It's not that bad.

And I found that after I added the h as library, no matter how I change the content of the h, the first version is always used in ide.

That shouldn't happen unless the IDE doesn't expect the library to change in-between compiles. If that is the case, even the library idea has flaws.

Since it is unavailable to use ./../share.h, I think I may use absolute path. I can define the absolute path of the lib in a .h, and anyone else using my program only need to change this.

Yes, presuming they have the exact same folder setup as you do. Better not put your name for the home folder, for example. Better hope that they have the sketchbook folder in the same place you have. There are a lot of things that can go wrong there.

Thanks. And I find another way. See it in my own answer. :)

@NickGammon Your first point there about relative paths is making a wrong assumption. It's not because the IDE copies the files.  You assume that a relative path is only from the "build" location, but it isn't. It's taken from each of the given include paths (-I...) in turn until it's found.  The build location happens to be one of those paths, as are a myriad of others (including all the library paths and system include locations). If the IDE included the sketch folder in the list of includes then you could use relative paths even with it copying files to the build area.  By the way, it ...

... doesn't "copy" files at all, but it has all the files open in the IDE and when you compile it saves those files out to the build folder from the IDE, not copy them from the sketch folder.  That's why the IDE doesn't have to save your work when you compile.

I classify "saving the files" into a temporary folder as copying them. I agree that you can compile a file you haven't saved, but surely, that is a copy in the build folder. It is a copy of the file you have open in the IDE.

Anyway, I tried the idea out of using the ../whatever/foo.h idea and it didn't work, so my assumption wasn't exactly wrong.

Ok, first of all you have to answer this question:

How can I tell the compiler what program it should compile?

The first (and easiest) solution is to have the preprocessor to this job. It's just a matter of writing two /...
Personally, instead of wrapping everything in an ifdef, I would have done something like
#include "share.h"
#define TX
#ifdef TX
#define setup_tx() setup()
#define loop_tx() loop()
#else
#define setup_rx() setup()
#define loop_rx() loop()
#endif

void setup_tx(){...}
void loop_tx(){...}

void setup_rx(){...}
void loop_rx(){...}

This way I could put the two different setup/loop pairs in two different files (e.g. tx.ino and rx.ino). Moreover the ifdef block can be moved in an h file.
NOTE: I'm not sure wheter the function redefinition works well, because I never tried it. If it doesn't work you can try doing the opposite (i.e. #define setup() setup_tx() and so on) or, in the end, make single-line functions (i.e. void setup(){setup_tx();} and so on).
Another solution can be applied if the processors are different. For instance if you have an Arduino UNO as transmitter and an Arduino Mega 2560 as a receiver, you could write:
#ifdef __AVR_ATmega2560__
- receiver functions
#else
- transmitter functions
#endif

But this would require you to switch processor along with the port.
The third solution is to place the shared h file in an include directory. You can do this by using a common include dir:

The include path includes the sketch's directory, the target directory (/hardware/core//) and the avr include directory (/hardware/tools/avr/avr/include/), as well as any library directories (in /hardware/libraries/) which contain a header file which is included by the main sketch file.

(See here)
You can also pass the -Idir option to avr-gcc to include also dir in the include dirs list, but this requires you to change the boards.txt file.
The last solution I can think at is to compile both programs, load the same files on both arduinos and then choose at runtime what is the correct program to use by assinging a pin to the "choice of program" function.
For instance you assing pin 8 to this function. On the TX board you connect pin 8 to VCC, while on the RX board you connect it to GND. Then the program is:
#include "share.h"

// Loop function callback (to speed things up)
typedef void (*loopfunction)();
loopfunction currentloop;

const int RXTX_PIN = 8;

void setup()
{
    pinMode(RXTX_PIN,INPUT);
    if (digitalRead(RXTX_PIN))
    {
        setup_tx();
        currentloop = loop_tx;
    }
    else
    {
        setup_rx();
        currentloop = loop_rx;
    }
}

void loop()
{
    currentloop();
}

void setup_tx(){...}
void loop_tx(){...}

void setup_rx(){...}
void loop_rx(){...}

IMHO the best solution is the first one, i.e. the define one. But... You should choose the best for your particular problem.
Bye

Thanks. But I find another way. See it in my own answer. :) On account of your hard work by commenting such a long answer, I choose your answer as the "accepted answer".

Because you're using Windows there is no easy way of doing what you want to do.
If you were on Linux or OS X you would be able to create a symbolic link so that your shared file can exist in more than one location:
$ ln -s /path/to/real/share.h share.h

On Windows there is then just two options that I can think of:

Turn your shared file into a library.  I don't know why you are so adverse to this, since it is by far the simplest option.  Just create a folder "MyProjectShared" in your libraries folder, then name you shared header "MyProjectShared.h" within that folder.  Then #include <MyProjectShared.h>.  Of course, choose a sensible name not MyProjectShared.
Change to a different IDE that will allow you to add include locations.  One example is my UECIDE which allows you to add the line:
#pragma parameter board.flags=-IC:/Path/To/Other/Includes

to the top of your sketch, which adds another location to find header files while compiling.
Another thought has just occurred to me.  If the two sketches are side by side in a folder (say Arduino/Sketch1 and Arduino/Sketch2) then you may be able to use a relative path.
In Sketch2, do:
#include "../Sketch1/share.h"

Thx. I don't use library because I use git for my code. If there are a lot of folders dispersing in my computer, it is hard to track them in git(maybe there is a way to approach it?). And I found that after I added the h as library, no matter how I change the content of the h, the first version is always used in ide... I will try the idea tomorrow.

@Turtle I have just had another thought - take a look at my edit.

I remembered that Arduino ide doesn't support sub folder. Anyway I will have a try tomorrow.

@Turtle It doesn't need to - two separate sketches, as long as they are in the same place, you should be able to use a relative path.

My esthetic preference would be to put share.h in .. instead of in Sketch1, so the include looks like #include "../share.h"

@jwpat7 Or put it in ../shared so it's #include "../shared/share.h"

@Majenko, yes, that looks like a good alternative

"then you may be able to use a relative path" - surely that doesn't work? The IDE copies files into a temporary folder. It won't copy files from another folder in the way you have it.

@nickgammon it's been so long since I used the Arduino IDE I can't remember if it includes the sketch folder in the list of include paths or not. UECIDE certainly does.

Even if it did, the build path is not the sketch path. For example /tmp/build4769560075719248978.tmp/sketch_jul09a.cpp. So if it went up one level you would go to /tmp/shared/share.h which is a directory and file which won't exist.

Sorry but your last opinion doesn't work. But I find another way based on your opinion. See it in my own answer. :)

@NickGammon Except that's not how C includes work.  The given path is tried relative to each of the given include paths (-I...) until it is found.  "." is normally an implicit include path, though many people choose to add -I. to their compilation command anyway.  If the Aduino IDE includes the path to the sketch folder in its include paths (which evidently it doesn't) then it would find ../share/share.h relative to that path.   See this paste of a test I just performed: http://pastebin.com/hrz4EyVs

You could also use:

in transmitter.ino
#define TX 1
#include "share.h"

in receiver.ino
#define RX 1
#include "share.h"


text:
How to increase Arduino's memory to save Dot Matrix Library?
I need to display some dynamic Chinese characters to 12864 using Arduino. What to show is transported from my web server. The character is stored as a 16x16 dot matrix, needing 16*16/8=32 byte. And I need to show some sentences, which contains more than 100 Chinese characters.
The problem is that I can't storage all the dot matrix data in Arduino because it has too small memory.

If I get the dot matrix data from web server, I need to have 100*32B memory, but SPAM with EEPROM have only 3k. So that failed.
If I save the dot matrix "library" in the Flash memory, I need 3500*32B (There are 3500 Chinese frequent-used characters), but there is only 32K Flash. Saving the "library" means that I should storage the dot matrix data of all the 3500 chars in Flash, then the server only need to send the Unicode of characters, and I can get the matrix of the char.

Any help is appreciated!

The character is stored as 16x16 dot matrix, 1 character=1 B... why don't you change the type of the character. sincer is 1 B, I assume is char/unsigned char. But you can reduce the size of the variable using bitfields.
struct
{
type [member_name] : width ;
};

@23ars Yes I already use unsigned char[16*16/8] to storage a character dot matrix.

The basic EEPROM write, each 1 byte, as is mentioned in the above answer.
http://www.hobbytronics.co.uk/arduino-external-eeprom
The PAGE WRITE which is suitable for this situation. One can easily read 32 bytes for a dot matrix.
http://www.hobbytronics.co.uk/eeprom-page-write

Use a different Arduino or Arduino-clone with more flash memory
Store the character bitmaps in external EEPROM (example)

Er, how to clone with more flash memory? I can't find the solution in your first link.

@Turtle: I wasn't clear enough, I meant a clone of an Arduino design not manufactured by the Italian company of that name. I'll revise the answer to clarify.

Option 3: Add an external SPI SRAM chip to store the incoming dot-matrix data - you can get them commonly up to 128KiB in size.

@Majenko er, could you please tell me how to search for it? And what's the name of these chips?( for example, 24lc256)


text:
RF24 Stalls Arduino Program with powerDown
I have an ATtiny85 and an Arduino Uno both using NRF24L01 chips to communicate with one another. The ATtiny85 is powered by a CR2032 coin cell. I am using tmrh20's fork of the RF24 library which can be found here. Here's the problem I'm encountering:
Under the current code posted, the Uno will receive about 80 packets of data (80 packets times 2 seconds per packet is about 160 seconds of time) before the ATtiny will simply stop sending, and the Uno receives no more data. I can tell that it's the ATtiny, because I've got a DMM hooked up to it. Normally, my DMM tells me that the ATtiny is drawing less than 0.005mA of current, but at the instance of the stall the DMM reads approximately 1.4 mA of current draw, which makes sense because under normal conditions with no sleep the ATtiny draws about 1mA, and the radio not in power down mode and not transmitting draws 0.4mA.
I've spent quite some time trying everything from setting the clock speed to a different value (it's at 1MHz) to changing the power amplifier value. The only thing I've tried that makes an impact is getting rid of the powerUp and powerDown function calls. Once these are removed everything works perfectly transmission-wise, except the only issue is that the whole system is drawing 0.4mA constantly, which is too much.
I don't think the coin cell is a problem considering the system works when the powerUp and powerDown calls are removed. Here's my code:
Reciever:
#define CE_PIN 7
#define CSN_PIN 8

#include <SPI.h>
#include "RF24.h"

RF24 radio(CE_PIN, CSN_PIN);

byte address[11] = "SimpleNode";
unsigned long payload = 0;

void setup() {
  while (!Serial);
  Serial.begin(115200);
  radio.begin(); // Start up the radio
  radio.setAutoAck(1); // Ensure autoACK is enabled
  radio.setRetries(15,15); // Max delay between retries & number of retries
  radio.openReadingPipe(1, address); // Write to device address 'SimpleNode'
  radio.startListening();
  Serial.println("Did Setup");

}

long counter = 0;

void loop(void){
  if (radio.available()) {

    radio.read( &payload, sizeof(unsigned long) );
    if(payload != 0){
        Serial.print("Got Payload ");
        Serial.print(payload);
        Serial.print(" - ");
        Serial.println(counter);
        counter++;
    }
  }

}

Transmitter:
//Sleep
#include <avr/sleep.h>

const int sleepSecs = 2;

//Radio
#define CE_PIN 3
#define CSN_PIN 3 //Since we are using 3 pin configuration we will use same pin for both CE and CSN
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;

void setup() {
  //Setup radio
  radio.begin(); // Start up the radio
  radio.setAutoAck(1); // Ensure autoACK is enabled
  radio.setRetries(15,15); // Max delay between retries & number of retries
  //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
  radio.setPALevel(RF24_PA_HIGH);
  radio.openWritingPipe(address); // Write to device address 'SimpleNode'

  //Setup sleep
  setup_watchdog(6);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); //Power down everything, wake up from WDT
  sleep_enable();
}

volatile int watchdog_counter = 0;

ISR(WDT_vect) {
  watchdog_counter++;
}

void loop() {
  sleep_mode(); //Go to sleep!

  if(watchdog_counter >= sleepSecs)
  {
    ADCSRA |= (1<<ADEN);
    radio.powerUp();
    watchdog_counter = 0;

    payload = 123456;
    radio.write(&payload, sizeof(unsigned long) ); //Send data to 'Receiver' every second

    radio.powerDown();
    ADCSRA &= ~(1<<ADEN); //Disable ADC, saves ~230uA
  }
}

//Sets the watchdog timer to wake us up, but not reset
//0=16ms, 1=32ms, 2=64ms, 3=128ms, 4=250ms, 5=500ms
//6=1sec, 7=2sec, 8=4sec, 9=8sec
//From: http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/
void setup_watchdog(int timerPrescaler) {

  if (timerPrescaler > 9 ) timerPrescaler = 9; //Limit incoming amount to legal settings

  byte bb = timerPrescaler & 7;
  if (timerPrescaler > 7) bb |= (1<<5); //Set the special 5th bit if necessary

  //This order of commands is important and cannot be combined
  MCUSR &= ~(1<<WDRF); //Clear the watch dog reset
  WDTCR |= (1<<WDCE) | (1<<WDE); //Set WD_change enable, set WD enable
  WDTCR = bb; //Set new watchdog timeout value
  WDTCR |= _BV(WDIE); //Set the interrupt enable, this will keep unit from resetting after each int
}

Try resetting the nrfs with the below answer: https://arduino.stackexchange.com/a/54604/35167

A delay after the powerUp() made the program work for longer, but it still stalled. More delays after write() only exacerbated the issue. The only thing that I've done to get this to work is to put the sending code in the watchdog ISR itself. However, this is limited to only around 4 seconds max per sent packet because this is the watchdog's max value, but that's OK for my application.
This leads me to believe that somehow the watchdog is interfering with sending, so possibly disabling it and reenabling after sending could have some effect if anyone else is having this problem.

After looking at the RF24 header file, I suggest you call radio.stopListening() right before you call write(). Also add a delay of 5 ms after write(). It would be nice to know the exact point at which the program got stuck; add digitalWrite(13, HIGH) inside the IF block, after powerDown() and again outside the block, immediately after sleep_mode(), but with a LOW argument instead, so you can know if the problem is that the AVR stops waking up at some point or if its the radio methods that is blocking, for some reason.

an additional 5 ms after powerup?

Yeah...the header file says it should be included for maximum compatibility.

Oops...just checked your link...i didnt look at the source before...i guess i should change that

One more thing: do I need to call startListening again after writing and delaying?

No...theres no need to listen at all since you are only transmitting...

@AlexWulff I've edited my answer concerning the delay and the position of the digitalWrites.


text:
ATtiny85 and INPUT_PULLUP
I have read some conflicting sources about what pins have internal pullup resistors available for the Attiny85 microcontroller. Can all I/O pins work with INPUT_PULLUP, or just some of them? And if so, which ones?
Thanks!

Check the datasheet, probably just search for "internal" or "pullup"  I believe there are little more pins/ports as portB, so they should all have internal pull ups.


text:
BLE SPI Module with ATtiny85
Adafruit carries a number of Bluetooth LE 4.0 modules in their store, notably the SPI (https://www.adafruit.com/products/2633) and UART (https://www.adafruit.com/product/2479) version. I have used the NRF24L01 module with ATtiny85 via SPI to transmit data in the past, and this uses 3 pins. I used the following setup to do so: https://www.hackster.io/arjun/nrf24l01-with-attiny85-3-pins-74a1f2.
My previous system consisted of ATtiny85s communicating with a receiver (Bluefruit Feather) via NRF24L01 radios. As the receiver got data, it sent it to an iPhone app that I wrote. Now, I would like to cut out this receiver and BLE straight to the iPhone, which supports multiple peripheral connections.
However, unlike the RF24 library, the Adafruit BLE SPI library needs the actual SPI library to compile correctly, which for some reason the RF24 library (this version: http://tmrh20.github.io/RF24/) doesn't. I don't quite get how the RF24 library can compile fine without the SPI library when targeting the ATtiny85 - Is there some way to get this to work similar to the RF24 library?
Alternatively, I think there is a way to do software UART on ATtiny85, which I know nothing about, so if there truly is no way to do SPI is UART possible?
I realize that this is a question best asked to Adafruit, which I have done, but I thought I'd post it here and see if anyone can help.
Thanks,
Alex

Have you considered porting the BLE library to a USI library?

Use an SPI library that does support the tiny. Like e.g. https://github.com/jscrane/SPI

Huh - I'll take a look at that SPI library and see. Thanks.

The ATtiny85 does not have an SPI port. It has an USI (Universal Serial Interface) that can be made to work like SPI (or I2C, or UART), but this needs some software support.

Keep in mind that many of the BLE chips are themselves computationally comparable to an ATtiny.  There's a good chance you can run your project itself on an nRF51822 - granted there can be some annoyances in setup but the mbed option should work even if you give up on the Arduino port.

I find the ATTiny85 working well with software serial port. Serial UART (or in fact any of the protocols like I2C or SPI) are just bit banging - and you can do that pretty well in software. Of course, having a hardware support makes things easier and faster, but there is nothing badly wrong with a software uart either. Except that you have to continuously check if there is some data arrives.
I was using software serial on Adafruit Trinket (ATTiny85) in various projects to talk to a Bluetooth 2.1 module, and it worked pretty well.
Here
http://arduining.com/category/trinket-projects/ they use the same approach to talk to an ESP8266.
You may wish to look for the SoftwareSerial lib for Trinket, or in certain cases you may want to go for the SendOnlySoftwareSerial lib (send only, but smaller code footprint).
Also a hardware based serial lib is available:
https://blog.adafruit.com/2013/09/30/hardware-serial-library-for-the-trinket/

Thanks, this is very good information. I tried out SoftwareSerial and it appears to be working.


text:
Need to turn on project twice in order for screen to work!
This problem is really stumping me. I made a simple printed circuit board with an ATtiny85, a 128x64 I2C OLED display, and a Sharp IR analog distance sensor. You can view the circuit here: circuits.io.
If I turn the system on using the simple 3-pin slide switch that I put on the board, the screen does not turn on. I can see that the system is powered though, because I can see a little bit of red light escaping from the IR sensor where some of the IR light borders on the visible end of the spectrum. If I turn the board off then immediately turn it back on, the display powers up just fine. If I upload a new program to the board and use the programmer's 3.3v power I don't need to do it twice - the screen works first time.
I'm using a 3.7v LiPo battery, so I know power is not an issue (everything is 3-5v tolerant, and the LiPo battery can deliver plenty of current). Why do I need to turn it on twice in order for the screen to work? Thanks!

Add a delay at the start of your program before you initialise the display. It sounds like the display is taking a moment to charge its capacitors and become ready.

@Majenko Awesome, thanks. A 100ms delay before starting the screen solved it nicely

Adding a 100ms delay before calling oled.init(0x3c); oled.clear(); oled.startScreen(); made this problem go away.


text:
Two Arduinos get out of sync after a few seconds
I built a small PCB that has some LEDs (bare NeoPixel 5050) and an IR receiver on it. The microcontroller is an ATtiny85, and the PCB is powered by a LiPoly battery (3.7V). The circuit normally stays in ULP sleep mode until a pin change interrupt wakes the circuit. The pin change interrupt is tied to the IR receiver so when the receiver gets a signal from a remote (38kHz modulated IR burst) a lighting sequence is triggered. I have multiple of these PCBs running the exact same code (shown below). When the PCBs receive an IR signal they all start at the same time, but then after a few seconds they start to drift apart. The lighting needs to be synchronized. What is the reason for this drift and how can I eliminate it? Is it due to different battery voltages? That would be the only physical difference between any two PCBs. Thanks for your help.
#define IR_PIN      4
#define LIGHT_PIN   0
#define DELAY_TIME  200

#include <Adafruit_NeoPixel.h>
#define NUM_PIXELS  2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, LIGHT_PIN, NEO_GRB + NEO_KHZ800);

#include "avr/interrupt.h"
#include "avr/sleep.h"

void setup() {
  pinMode(IR_PIN, INPUT);
  strip.begin();
  pixelsOff();
}

void loop() {
  sleep();

  for (int i = 0; i < 5; i++) {
    pixelsOnRed();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
    pixelsOnGreen();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
  }

  for (int i = 0; i < 5; i++) {
    pixelsOnBlue();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
    pixelsOnRed();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
  }

  for (int i = 0; i < 5; i++) {
    pixelsOnGreen();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
    pixelsOnRed();
    delay(DELAY_TIME);
    pixelsOff();
    delay(DELAY_TIME);
  }
}

void pixelsOff() {
  strip.setPixelColor(0, 0, 0, 0);
  strip.setPixelColor(1, 0, 0, 0);
  strip.show();
}

void pixelsOnRed() {
  strip.setPixelColor(0, 255, 0, 0);
  strip.setPixelColor(1, 255, 0, 0);
  strip.show();
}

void pixelsOnGreen() {
  strip.setPixelColor(0, 0, 255, 0);
  strip.setPixelColor(1, 0, 255, 0);
  strip.show();
}

void pixelsOnBlue() {
  strip.setPixelColor(0, 0, 0, 255);
  strip.setPixelColor(1, 0, 0, 255);
  strip.show();
}

ISR(PCINT0_vect)
{
    //This is not needed for the current sketch
}

void sleep() {
    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT4);                   // Use PB3 as interrupt pin
    ADCSRA &= ~_BV(ADEN);                   // ADC off
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                                  // Enable interrupts
    sleep_cpu();                            // sleep

    cli();                                  // Disable interrupts
    PCMSK &= ~_BV(PCINT3);                  // Turn off PB3 as interrupt pin
    sleep_disable();                        // Clear SE bit
    ADCSRA |= _BV(ADEN);                    // ADC on

    sei();                                  // Enable interrupts
}

What is your clock source?

@Majenko internal 8MHz oscillator

That's about the worse clock source you can get.

@EdgarBonet in your opinion is it bad enough to produce the drift I experienced?

It is very likely.

What is the reason for this drift and how can I eliminate it?

two solutions:
1) try using crystal oscillators;
2) try driving on arduino with the other arduino's clock output.

Assuming internal RC oscillator:
In the datasheet:

By default, the Internal RC Oscillator provides an approximate 8.0 MHz clock. Though voltage and temperature
  dependent, this clock can be very accurately calibrated by the user. See “Calibrated Internal RC Oscillator Accuracy”
  on page 164 and “Internal Oscillator Speed” on page 192 for more details. The device is shipped with the
  CKDIV8 Fuse programmed. See “System Clock Prescaler” on page 31 for more details

And page 192 shows a graph of frequency vs voltage.
On 164 it says:

It is possible to manually calibrate the internal oscillator to be more accurate than default factory calibration. Please
  note that the oscillator frequency depends on temperature and voltage. Voltage and temperature characteristics
  can be found in Figure 22-40 on page 193 and Figure 22-41 on page 193.

So yes, conclusive evidence there that the voltage will affect the frequency.

Pretty sure the Arduino uses a 16mhz crystal rather than the internal oscillator.  http://dailylearningnotes.blogspot.com/2010/03/arduino-components-crystal-oscillator.html

@bigjosh "The" Arduino....? READ THE QUESTION: "I built a small PCB that has some LEDs (bare NeoPixel 5050) and an IR receiver on it. The microcontroller is an ATtiny85"... That's not an Uno (ONE of the MANY forms of Arduino)

Thanks, this is insightful. I didn't know that voltage and temperature could affect the oscillator. The only concern I have is that both batteries were charged up to their full 4.2v before use and both PCBs are right next to each other. Maybe small differences in both can produce cascading drift like I saw. I'll take a look at the calibration

@Majenko So true! Comment respectfully withdrawn! :)

It may be possible to characterize the drift between the two and compensate. To a 1st aprox, you might just be able to let them both run for a while, then measure the speed difference and then slow down the faster one to cancel out the difference. To a 2nd aprox, you could characterize the voltage  dependency on each adn then measure and compensate in real-time. But agree with others- easiest probably to use XTAL or a way of syncing (wire, IR LED, etc).

Other answers have noted that the internal RC oscillator's frequency is voltage and temperature dependent.  If you have good control over voltage and temperature, consider manually or automatically calibrating the clocks of your several ATtiny85's.
Absent that control, consider adding crystals or ceramic resonators to your circuits, or set up a synchronization protocol using IR.  For example, if your IR transmitter is programmable, have it send a synchronization character as often as necessary to adequately synchronize the lights.  If your IR transmitter is not programmable, add an IR LED and driver to one or more of your ATtiny85's, and send synchronization characters at regular intervals.


text:
Replace Wire library with TinyWireM
I want to integrate Pololu's vl53l0x Time of Flight distance sensor into a project of mine. They created a library to interface with the vl53l0x over I2C, which works great on my Uno. The only problem is that Wire.h doesn't work on the ATtiny85.
TinyWireM is a replacement library for Wire that I think would be compatible. My question is this: how can I go about replacing all the calls to the Wire library with calls to the TinyWireM library? Is it as simple as replacing all instances of Wire with TinyWireM? Is there anything else I need to do to make the library ATtiny85 compatible?
Thanks!

States:  Minor changes for consistency with the Arduino 1.0 Wire library (e.g. uses write() instead of send()). Buffer size slightly increased for Adafruit_LEDBackpack use.

I can't guarantee it will work, but it is probably possible to just modify the library. You can find the source code for that ToF sensor library here:
https://github.com/pololu/vl53l0x-arduino/blob/master/VL53L0X.cpp
The first step is to find the reference to Wire.h (line 7 in that file) and change it to TinyWireM.h. After that, you would need to find the functions that call the Wire library and replace them with the appropriate TinyWireM functions instead. Those begin at line 284 (Wire.beginTransmission(address);). You can find the source code for TinyWireM here (which should tell you all of the functions in the library):
https://github.com/adafruit/TinyWireM/blob/master/TinyWireM.cpp
So Wire.beginTransmission(address); would become TinyWireM.beginTransmission(address); and Wire.write(reg); would become TinyWireM.send(reg);
I'm not sure if that's all of the solution, but I think that's a good start.

In fact, there would be nothing to do now I guess, as TinyWireM is now included tiny boards packages.
If you just include Wire as usual, it should work as on an UNO.
Except for setting a different clock, if I remember well, it is fixed to 400kHz.


text:
Using Arduino to control a 12v car light system?
I am new, but I am wondering what options I may have to control a 12v line that connects to a light with Arduino i/o.
Given the voltage limitations of an arduino, I am thinking using some kind of 5v relay to switch a 12v line on/off ( if it exists )
Though I was also hoping to be able to utilize the PWM pins in conjunction with a 12v line to 'reduce' it to 6v without using a resistor.  (though I would have no idea how to go about this, or if it is even possible).
Any help appreciated.

Yes, you can use a relay. However, you'll almost certainly need to drive the relay with a transistor because the current requirements of the relay will be too high for an Arduino pin.
Better to use a logic MOSFET N-channel transistor as an electronic switch. You connect the Arduino's output pin to the gate of the transistor. You connect the + terminal of your 12 volt source to one end of the light, and connect the other wire from the light to the drain on the MOSFET. You then connect the source pin on the MOSFET to ground, and tie the ground of your Arduino to the 12 volt negative terminal.
In this setup, the MOSFET acts as a switch. When you switch the output pin of your Arduino to HIGH, the MOSFET turns on, providing a very low resistance path to ground. Current flows from the +12 volt supply, through the light, through the MOSFET, and to ground.
When the Arduino's output pin is low, the MOSFET acts as an open switch. There's no path to ground so the light is not lit.
You can't use PWM to lower 12 volts to 6 volts without some additional circuitry. PWM rapidly pulses the output from all the way on to all the way off. If you feed a PWM pin into a transistor, it can be used to create a higher voltage and/or current pulsed signal. However, pulsed DC is not the same thing as a lower DC voltage. You'd need to feed the pulsed 12 volts through a reservoir capacitor, perhaps 2 capacitors (and possibly a choke)  in order to average out the pulses into a lower DC voltage. That simple approach would work ok for powering a 6 volt incandescent light, but would not be good enough to power a solid state component because the output would not be even enough. It would have a fair amount of ripple and high frequency noise in it.

This is excellent thank you.  I've been studying transistors, but I think I need to study a bit more : )
re: PWM - I should have been more specific that these are LED lights.  It is a 12v line but the bulb itself has a few LEDs on it - (I'm not sure exactly how its internals are set up).  But it seems transistors are the way to go.
The goal with the PWM is to reduce brightness.

Okay. You can use PWM to reduce the apparent brightness of the LEDs. You still need to use the full voltage to calculate the current limiting resistor though (e.g. LED forward voltage = 1.2 volts. Supply voltage = 12 volts. desired LED current = 20 mA.  resistor value = (12-1.2)/.02= 540 ohms.Then PWM control varies the duty cycle of the LED, which changes the apparent brightness. (I say apparent because what really happens is the LED flashes between on and off too rapidly for our eyes to see, so our eyes average the total light output over time.)

Awesome, thank you.  This is perfect!  Project is actually for initially hooking up a microcontroller within my motorcycle to do various tasks.  I'll write up a tutorial sometime when it's completed.  Thanks again.
I suppose I have one last curiosity - is there any limitation on transistors when combined with PWM?  If a pwm is flashing at 50hz... is there any factor in limiting the transistor to 'keep up' ?

No, there shouldn't be. The whole reason for using PWM rather than varying the voltage is that transistors get hot when you run them in between on and off. One thing you should be aware of: Ardunio PWM runs at about 500 Hz. At that rate, if the lights are road lights, when you move across somebody's field of view what they will see is a trail of dots of light. It can be distracting. For that application you might want to put a properly rated capacitor between the + and ground leads to the LEDs to smooth out the output and eliminate the flashing.


text:
how to push data from an Arduino pin to Bluetooth module
I'm writing a software that can receive data from Arduino via Bluetooth. My software is pretty fine now, at least it can pair with my hardware but when I try to test whether it can receive data via Bluetooth, I'm stuck. My Arduino receives temperature readings from a sensor at Analog pin 0. My Bluetooth module HC-05 connects with Arduino at Digital 0 and 1 (RX and TX pin respectively, as default). I don't know how to push data from Analog pin 0 to the Bluetooth module. Thanks in advance for any suggestion.

You don't. You send a message via Bluetooth that the pin has changed.

Sorry, could you give me more explanation, Ignacio?

Let's start simple. How would you do it if you were using the serial connection?

You meant if the Analog pin 0 is HIGH, set TX pin of Arduino HIGH?

you will need to read this http://arduino.cc/en/Serial/Print And you might want to try some of the basic tutorials you can find online or a book on starting arduino.

The HC-05 looks like like any other terminal to the Arduino so any serial operations that you would use for a wired terminal can be used with the HC-05. See the HC-05's manual for how to set it up initially. Note that HC-05s don't forget their settings and they have no reset command to put them into a known state, so write down your settings for your future reference.
- Read the analog pin value;
- Convert the value into whatever physical units you require;
- Print the result with Serial.print() or Serial.println()

Edit:  You wrote that your HC-05 is connected to Digital 0 and 1, but you created your SoftwareSerial, mySerial, to transmit on Digital 11. In that case your HC-05's receive pin must be connected to Digital 11.

While this is correct, the asker has no idea how to perform serial operations.

Tks guys. I know how to convert my readings into Celcius values and print the result on Serial Monitor by Serial.print but I wonder whether I should convert my readings into bits (I mean analog-digital conversion) before pushing them into the Rx pin of Hc-05; as abovementioned, my sensor is connected to an analog pin while hc-05 is connected to 2 digital pins.

If you're trying to send the readings as text via Bluetooth, just as you would to a wired terminal, you don't need to do anything but replace the serial cable with the HC-05. It is designed to look to the Arduino like a serial terminal.

Could you look at my codes above and tell me if anything wrong, JRobert? I assume I connected HC-05 to Arduino correctly because I watched and followed exactly some tutorials on Arduino and HC-05.

I don't see any obvious mistakes in the code. Have you tried the suggestion in my edit, above? Have you tried replacing the HC-05 with a serial cable to make sure your codes transmits what you expect?

It's my code. Can anyone suggest anything wrong with it if my idea is to push data from Analog pin 0 to Digital pin 11, which is the Tx pin on Arduino connecting to Rx pin on HC-05?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int tempPin=0;

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

void loop()
{
 float reading = analogRead(tempPin); // reading on tempPin
 float voltage = reading*5.0/1024.0; // the resolution of a pin is 10 bit,
 float tempC = voltage/0.01; // 10mV = 1 Celcius
 mySerial.write(tempC);

 delay(3000);
}

looks ok to me. doesn't it work?

You're using mySerial.write() which will send binary data down the serial line.  Were you expecting text?  Maybe try mySerial.println().


text:
Can regular Arduino pins be used during SPI?
I have a circuit in which I'm using an Arduino Pro Mini to interface with an RF69 radio via SPI. The SCK pin on the Pro Mini is pin 13, which also happens to be the LED pin. Is it possible to write pin 13 high and low in the same sketch that I'm interfacing with the radio? I don't need to do SPI communication simultaneously with the LED. I can put the radio to sleep then use the LED. I'm wondering if this will some how mess up the SPI communication or if everything will be OK.

probably, but just try it, it won't zap anything...

You need to disable SPI before you use digitalWrite on the SPI pins, or nothing will happen! Then re-enable SPI when you start communication again.

I did not check the datasheet of the RF69, but it is customary for SPI devices to have a “slave select” input pin. When such a device is not selected, it will leave its MISO pin in high impedance and completely ignore whatever may happen on the MOSI and SCK pins. This effectively disconnects the device from the SPI bus. In this situation you show be able to play with the LED without disturbing the device.
Beware that the slave select pin is usually active low: write it to HIGH to deselect the device.

Great, thank you. This is exactly what I needed.


text:
Cannot correctly access element in array when given index
I have the following strings which are stored in the program memory. They are basically just morse code definitions, with another array of characters where each character in the array has the same index as the morse code definitions:
const char a[] PROGMEM = ".-";
const char b[] PROGMEM = "-...";
const char c[] PROGMEM = "-.-.";
const char d[] PROGMEM = "-..";
const char e[] PROGMEM = ".";
const char f[] PROGMEM = "..-.";
const char g[] PROGMEM = "--.";
const char h[] PROGMEM = "....";
const char i[] PROGMEM = "..";
const char j[] PROGMEM = ".---";
const char k[] PROGMEM = "-.-";
const char l[] PROGMEM = ".-..";
const char m[] PROGMEM = "--";
const char n[] PROGMEM = "-.";
const char o[] PROGMEM = "---";
const char p[] PROGMEM = ".--.";
const char q[] PROGMEM = "--.-";
const char r[] PROGMEM = ".-.";
const char s[] PROGMEM = "...";
const char t[] PROGMEM = "-";
const char u[] PROGMEM = "..-";
const char v[] PROGMEM = "...-";
const char w[] PROGMEM = ".--";
const char x[] PROGMEM = "-..-";
const char y[] PROGMEM = "-.--";
const char z[] PROGMEM = "--..";
const char one[] PROGMEM = ".----";
const char two[] PROGMEM = "..---";
const char three[] PROGMEM = "...--";
const char four[] PROGMEM = "....-";
const char five[] PROGMEM = ".....";
const char six[] PROGMEM = "-....";
const char seven[] PROGMEM = "--...";
const char eight[] PROGMEM = "---..";
const char nine[] PROGMEM = "----.";
const char zero[] PROGMEM = "-----";

const char* const morse_table[] PROGMEM = {a, b, c, d, e, f, g, h, i, j, k, l, m,
    n, o, p, q, r, s, t, u, v, x, y, z, one, two, three, four, five, six,
    seven, eight, nine, zero};

const char alphabet[] PROGMEM = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'};

I am then creating a function which is supposed to be able to take in the morse code definition and spit out a character. This function is below:
void checkString(char * compare) {
  //Unwrap the pointer to the array into a "real" array
  char buf[7];
  for (int i = 0; i < 6; i++) {
    buf[i] = compare[i];
  }

  int correctIndex = -1;

  for (int iterator = 0; iterator < 35; iterator++) {

    char buf2[7];
    strcpy_P(buf2, (char*)pgm_read_word(&(morse_table[iterator])));

    if ((buf[0] == buf2[0]) && (buf[1] == buf2[1]) && (buf[2] == buf2[2]) && (buf[3] == buf2[3]) && (buf[4] == buf2[4])) {
      correctIndex = iterator;
    }
  }

  if (correctIndex == -1) {
    Serial.println("Failed!");
  }

  else {
    Serial.print("Success! Index: ");
    Serial.println(correctIndex);
  }

  char characterBuffer = alphabet[correctIndex];
  Serial.println(alphabet[correctIndex]);
}

The strcpy_p line of code was essentially copied from the PROGMEM reference for Arduino. I don't understand much about it, but from my tests it appears to work in getting an actual string object out of the pointer.
If I input any of the morse code definitions given, the correctIndex integer does contain the correct location of that definition in the morse_table 2d array. However, when I pass this integer into the alphabet array hoping to get out the character at that location I am given a seemingly random character. Is there something that I'm doing wrong with this code to produce such a result? Thanks for your help.

This code cries for optimization... 1. Using binary code, letters could be stored as single byte instead of 2-5 bytes (+1 zero byte for string termination). 2. Comparisons could be as simple as comparing two bytes instead of multiple "&&" on string characters. 3. There is no need to store whole alphabet as string, just use ASCII table: numbers are codes 48-57, small letters are bytes 97-122 (https://en.wikipedia.org/wiki/ASCII)

@madneon thanks for the feedback - I'm new to c++. By letters, do you mean the morse code definitions? How is it possible to store multiple characters as one byte? I thought that each character had to be stored as one byte. I do see how storing them as null-terminated strings essentially wastes a byte though. That is helpful.

Sorry for late response. You can store Morse chars in bytes assuming eg. dashes are "ones" and dots are "zeroes", storing in lower bits, this way letter "a" would be 01, "b" would be "100" and so on. Im not sure if its needed, but you can also store the length of Morse code in eg. 3 higest bits.

You can't access arrays that are in PROGMEM as if they were normal variables. The compiler can't tell the difference and just interprets it as a RAM address, which is wrong.
Instead you have to use pgm_read_byte to get the data:
char characterBuffer = pgm_read_byte(alphabet + correctIndex);

Thanks, it appears that doing this solved my problem! Also removing PROGMEM and leaving my original code seemed to work as well. So by adding the location of the alphabet array to the offset the microcontroller is accessing the specific character at that location?

pgm_read_byte just reads a byte from a given address in flash. An array is just an address - usually a RAM address. Adding a number to a number yields a bigger number, which is the address that your requested byte lies at.


text:
DS1307 RTC conflicts with DS18B20
I'm working on a project to output the temperature from a DS18B20 to a 16x2 LCD while logging the temperature to a CSV file using the Adafruit Data Logging Shield. I keep getting this error when verifying the code:
RTClib-master/RTClib.cpp.o: In function `RTC_DS1307::now()':
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to 'Wire'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to 'Wire'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to
'TwoWire::beginTransmission(int)'RTClib-master/RTClib.cpp.o: In function 'TwoWire::write(int)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:72: undefined reference to 'TwoWire::write(unsigned char)'
RTClib-master/RTClib.cpp.o: In function 'RTC_DS1307::now()':
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:254: undefined reference to 'TwoWire::endTransmission()'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:256: undefined reference to 'TwoWire::requestFrom(int, int)'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:257: undefined reference to 'TwoWire::read()'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:258: undefined reference to 'TwoWire::read()'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:259: undefined reference to 'TwoWire::read()'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:260: undefined reference to 'TwoWire::read()'
/Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:261: undefined reference to 'TwoWire::read()' RTClib-master/RTClib.cpp.o:/Users/grafton/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:262: more undefined references to 'TwoWire::read()' follow

When I comment RTC_DS1307 RTC; in the code (below) these errors go away, but of course I get errors related to an undefined RTC. I'm a newbie cobbling together code from various sources, so any help is greatly appreciated. Code follows:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#include <SD.h>
#include "RTClib.h"

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int chipSelect = 10;
File tempLog;
RTC_DS1307 RTC;

LiquidCrystal lcd(6, 7, 8, 9, 11, 12);

void setup() {
  Serial.begin(9600);
   while (!Serial) {
    ;
  lcd.begin(16, 2);
  //         ----------------
  lcd.print("Current temp (F)");
   sensors.begin();
   }

Serial.print("Initializing SD card...");
  pinMode(SS, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("Initialization failed!");
    while (1);
  }
  Serial.println("Initialization done.");

tempLog = SD.open("templog.txt", FILE_WRITE);
if (! tempLog) {
  Serial.println("Error opening templog.txt");
  while(1);
}
char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      tempLog = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }

  Serial.print("Writing to: ");
  Serial.println(filename);
  tempLog.println("Data Logging File");
  tempLog.println("Date,Temp(F)");
  }
}

void loop() {
  sensors.requestTemperatures();
  float temperature = sensors.getTempFByIndex(0);
  lcd.setCursor(6, 1);
  lcd.print(temperature);
  Serial.println(temperature);
  //-----------------------------------------------------------

String dataString = "";

//date time stuff-------------------------------------------

DateTime now = RTC.now();
  // log time
// tempLog.print(now.unixtime()); // seconds since 1/1/1970
//  tempLog.print(", ");
  tempLog.print('"');
  tempLog.print(now.year(), DEC);
  tempLog.print("/");
  tempLog.print(now.month(), DEC);
  tempLog.print("/");
  tempLog.print(now.day(), DEC);
  tempLog.print(" ");
  tempLog.print(now.hour(), DEC);
  tempLog.print(":");
  tempLog.print(now.minute(), DEC);
  tempLog.print(":");
  tempLog.print(now.second(), DEC);
  tempLog.print('"');

  tempLog.print(",");
  tempLog.print(temperature);
  tempLog.print(",");
  delay(500);

tempLog.println(dataString);
tempLog.flush();

}

The RTC library requires the Wire library. Just put #include <Wire.h> in front of the line #include "RTClib.h"

I have tried to simply #include <Wire.h> in RTClib.h, rather than putting #include <Wire.h> above #include "RTClib.h" in my sketch, but this does not work.  Do you know why?

That indeed doesn't work. I don't know the reason; sorry.


text:
How do I set the motor state to "HIGH" at the beginning of this sketch?
My intent with this sketch is to have motors run for one minute, then stand by for 18 minutes. In practice, the sketch starts the motor state at "low" for the OffTime interval, then goes to the OnTime interval and loops. The desired result is exactly the opposite: the "high" interval first, followed by the "low". I have tried setting the motorState to "HIGH" in the constructor and played with the order of the IF statements to no avail.
I would appreciate any insight into this problem, as well as an intuition for the practical use of millis(). I need a solution which doesn't use delay but am having trouble wrapping my head around the logic of millis() as used. (I adapted this code from a tutorial.)
class LifeTest
{
  // Class member variables initialized at startup
  int motorPin;
  long OnTime;
  long OffTime;
  // These maintain the current state
  int motorState;                               // Used to set the motor.
  unsigned long previousMillis;                 // Stores last time motor was updated.

  public:
  LifeTest(int pin, long on, long off)
  {
    motorPin = pin;
    pinMode(motorPin, OUTPUT);

    OnTime = on;
    OffTime = off;

    motorState = LOW;
    previousMillis = 0;
  }

  void Update()
  {
    unsigned long currentMillis = millis();     // Check to see if it's time to change the motor state.
    if((motorState == HIGH) && (currentMillis - previousMillis >= OnTime))
    {
    motorState = LOW;                         // Turn off motor.
    previousMillis = currentMillis;           // Remember the time.
    digitalWrite(motorPin, motorState);       // Update the motors.
    }
    else if((motorState == LOW) && (currentMillis - previousMillis >= OffTime))
    {
    motorState = HIGH;                        // Turn on motor.
    previousMillis = currentMillis;           // Remember the time.
    digitalWrite(motorPin, motorState);       // Update the motors.
    }
  }
};

LifeTest motor1(50, 60000, 1080000);
LifeTest motor2(51, 60000, 1080000);
LifeTest motor3(52, 60000, 1080000);
LifeTest motor4(53, 60000, 1080000);

void setup()
{
}

void loop()
{
  motor1.Update();
  motor2.Update();
  motor3.Update();
  motor4.Update();
}

I would appreciate any insight into this problem, as well as an intuition for the practical use of millis().

I have a lengthy tutorial about this at How to do multiple things at once ... like cook bacon and eggs.
However as this site frowns upon link-only answers (the link might go down) I'll try to explain as well, here.
millis() is like having a wristwatch. You glance at it from time to time to see if it is time to do something, like catch a bus to work, put the dinner on, take the cake out of the oven, that sort of thing.
If you delay() all the time, you can only do one thing at a time. For example, if your cake takes 30 minutes to cook, and you do this:
PutCakeInOven ();
delay (30UL * 60 * 1000);  // delay 30 minutes
TakeCakeOutOfOven ();

This is fine, but you aren't also cooking some eggs at the same time, or doing the dishes, right?
With millis() you can do lots of things! Win-win! The basic technique is to note the time when you started, and then when time is up, you do whatever-it-is you need to do. Like this:
unsigned long BakeStartTime;
const unsigned long CookingTime = 30UL * 60 * 1000;  // 30 minutes
bool CakeInOven = false;

void setup ()
  {
  PutCakeInOven ();
  BakeStartTime = millis ();  // when the cake went into the oven
  CakeInOven = true;
  }

void loop ()
  {
  if (CakeInOven && (millis () - BakeStartTime >= CookingTime))
    {
    TakeCakeOutOfOven ();
    CakeInOven = false;
    }

  // do a whole lot of other stuff, like cooking some eggs

  }

You can expand this technique to do dozens of things "at once".

just change the constructor to
  LifeTest(int pin, long on, long off)
  {
    motorPin = pin;
    OnTime = on;
    OffTime = off;

    previousMillis = 0;

    motorState = HIGH;
    pinMode(motorPin, OUTPUT);
    digitalWrite(motorPin, motorState);
  }


text:
Physical dimensions(size) of the new MKR1000 board?
Anybody here knows the physical dimensions(size) of the new Aduino MKR1000 board?

If the diagram on the main page is to scale, then it's approximately 2.2 inches by 1.0 inches.

Exactly! I had the same figures in mind.