There's one important thing that you need to remember when working with time on an Arudino of any form:
Every operation takes time.
Your foo() function will take an amount of time. What that time is, we cannot say.
The most reliable way of dealing with time is to only rely on the time for triggering, not for working out when the next triggering should be....
Your first snippet is the correct solution.
Be careful though, you can only sink up to 6mA or 9mA per pin (as per the documentation ["Input and Output" section], I never tried more). If you need more current, use a transistor (this looks like a good example, you just need to invert the output pin to ...
sizeof doesn't return the number of elements. It returns the number of bytes. Since they are uint16_t arrays each element is 2 bytes - hence twice the size.
The reason your last number is only 40928 is because of integer wraparound. You only provide a 16-bit unsigned variable to store it in, so all you get is the lower 16 bits of the answer.
92000 + 40000 +...
For a 5V logic output to a 3V3 logic input, you can use a resistive divider to lower the voltage.
When unloaded, a 3V3 logic output is just enough to drive a 5V logic input. Check the AVR datasheet for the exact voltages (0.6 × Vcc = 3V, found under DC Characteristics in the datasheet).
In other words, with a little bit of special care it may just work.
The limitations of accuracy of the library depend on accuracy of the crystal. When they make, or cook, the crystal they can only make it to a certain degree accurate, also the environment of the crystal (temperature, humidity, etc.) play a role in the accuracy of it. Let's say you have a crystal that is off by .5 second every hour, great for short term, but ...
Search for male-male jumper wire. Some of what you'll find is individual wires but there are also many that are connected together and you can rip off the width you need.
Here's one from Adafruit but there is no shortage of them on ebay/amazon.
If you have a read of section 31 of the Datasheet, available from here, things may come a little clearer for you.
Here's a summary of what I know:
PIO stands for Parallel Input/Output and offers the functionality to read and write multiple register ports at a time. Where the datasheet mentions a register, for example PIO_OWER, the Arduino library has ...
That method only works on AVR based systems. It exploits a "feature" whereby the IO pin, when in OUTPUT mode, is also in INPUT mode at the same time, and reading the pin reads the value that the pin is being driven to by the digitalWrite function.
The same is not true of the Due, which is an ARM based system. The IO pins function completely differently ...
Either port can be used for programming, but the native USB port lets you do other things:
It also enables the Due to emulate a USB mouse or keyboard to an attached computer. To
use these features, see the Mouse and Keyboard library reference pages.
The Native USB port can also act as a USB host for connected
peripherals such as mice, keyboards, ...
Both the DigiX and the SIM908 are natively 3.3V boards. They should be able to connect to each other directly.
For some reason, the SIM908 breakout seems to only offer RS232 level serial outputs for the GPRS and GPS. On U3 (the SIM908 module itself) Pins 68/71 offer 3.3V levels for the GPRS (GPRS-TXD and GPRS-RXD) and 15/16 offer 3.3V levels for the GPS (...
To generate a square wave, you only need to update the output at a rate of two points per cycle. (Technically, when the Arduino's PWM output is configured for 50% duty cycle, that's a square wave at some frequency.)
But to generate a clean sine wave (without a lot of distortion), you need to update a lot more frequenclly than two points per cycle. ...
What connects the resistor to the LED?
It's hard to work out which holes the LED is plugged into, but I think your current circuit looks something like this:
You need to connect that resistor and LED together.
For your edit:
Now your circuit looks like this:
Behind the 5 pins in that column with the ground wire there is a big chunk ...
You have a couple of problems (although the lack of pull-up resistors is not one of them, because the board you linked has pull-up resistors on it).
The DS1307 needs to operate at a minimum of 4.5 volts, so you can't connect it to the 3.3V pin on the Due. (You need to supply it with 5V).
However the Due is a 3.3V device on its data pins, and thus you can't ...
Re-visiting an old question... as I found a very informative blog post
that sheds new light into it. But let me first provide some context
before giving the link.
When assessing the quality of a time base, be it a crystal, a ceramic
resonator or a lab-grade frequency standard, there are two notions that
should be distinguished:
accuracy: how close is the ...
I am playing on a Arduino UNO, you would have to compare the datasheets to determine differences.
For my research on this answer I am looking at:
Code/PwmFrequency (for a quick rundown)
TimerPWMCheatsheet (explains the prescaller and resulting frequencies)
varying the pwm frequency of timer0 and timer2
feature request: adjustable pwm ...
Again similar to Sachleen's answer. You can crimp your own connectors onto a ribbon cable, that way you can have the desired header size.
I've just done this manually with some pliers (I couldn't afford the crimping tool) a bit tricky but I'm pleased with the results. I got all of the bits I needed from www.hobbytronics.co.uk. Anywho I'm happy with the ...
The ATmega16U2 on those boards isn't intended to be programmable by the end-user. It's only there to help convert from USB to TTL serial, which lets your computer communicate with the board's main microcontroller. It replaces the FTDI chip which was used on some older boards.
In the case of the Uno, the main microcontroller is the ATmega328. For the Due, it'...
What you want is something like this (ignore the fact that my mini breadboard is stuck to a shield):
My starter Arduino kit came with the connector for the 9 volt battery into the power socket on the Arduino, you may need to make one. You cannot connect the 9V battery to any other part of the Due that I am aware of (without damaging it!).
It is perfectly ...
Your Duemilanove only has 1k of RAM. That's not much. Each pixel takes 3 bytes of RAM (R/G/B). So (say) 60 pixels would be 180 bytes. That's less than 1k, but there would be other uses of RAM in your sketch.
750 LEDs sounds like pushing it for the low-RAM Arduinos.
You might want to look at NeoPixels Revealed: How to (not need to) generate precisely timed ...
The slow clockr is primarily used for the real time clock (RTC) module inside the SAM3X chip. It can also be routed to other places when you want a low speed clock source, but the only places it is actually required are the RTC and the watchdog.
The slow clock can be generated from an internal RC oscillator instead of requiring an external crystal, but ...
My question here is how can I simultaneously read out all the data from the different serial ports on the arduino mega sketch.
As you are using several serial ports data can already be received simultaneously. Each serial software class (Serial1, Serial2, Serial3) has an internal buffer where data is stored until it is read.
You only need to read the data ...
Not Pascal, but Ada, which is much less restrictive than Pascal while enjoying the same advantages over low-level programming, and much more actively supported with language revisions as recently as 2012 and the formally provable SPARK language, for when you need your code to work.
Any processor which gcc supports can potentially support Ada, whose Gnat ...
The sizeof operator's result is number of bytes, not number of array elements. Your arrays in the program above have two bytes per element, hence twice as many bytes as elements.
If you want to report the number of elements, divide the total size by the number of bytes per element. For example:
nElements = sizeof BuffA / sizeof BuffA;
As uint16_t ...
You should split your problem in pieces. Like you cannot get communication with your Arduino again, so check first:
If you plug in the Arduino / USB, do you get a message on your computer?
Is it visible in the systems manager?
Is it visible by the IDE?
If you connect an adapter (12 or 9V), does it make a difference?
If you try another Arduino, does it work ...
You're over-stressing the MCU and causing all sorts of horrible things to happen with the power rails. Of course nasty things are going to happen.
The only way to fix it is to change the circuitry. Something as simple as adding a 1kΩ resistor in series with each of the input connections could be enough to sort it out.
The built in serialEvent() function on arduino only responds to serial port 0, called just "Serial" in the code. To respond to messages on "Serial1", use serialEvent1() on the Arduino Due there also exists serialEvent2() and so on.
EDIT: the serialEvent() handlers are not on interrupts; they run sequentially in-between loops. If the loop is blocking they ...
According to your comment:
after commenting out those ifdef guards, it worked
I would say that is a bug in the Adafruit_GPS library.
As a matter of fact, the DUE is not using the AVR architecture (it uses ARM), that explains why #ifdef __AVR__ in Adafruit_GPS.h never passes; but then something else should be done specifically for the DUE (missing #else ...
Although Sachleen's answer is preferable in a lot of situations, there are a few other options that you have.
Quick note on his answer: I find clamping a row of those wires together and rubbing a thin line of superglue over the connectors a useful way to keep them together. It's not very neat, but it works pretty well and, with that many wires connected, ...