Arduino Mega 2560
I’ve recently purchased an Arduino Mega 2560 R3 development board.
It’s in some ways more powerful than the Raspberry Pi as it has analogue inputs, more GPIO’s and less overhead – in that it doesn’t run Linux, it doesn’t have an IP stack, it doesn’t have HDMI output etc. Its just a microcontroller and a bunch of pins that you program using C++
I’m actually preferring it to the Pi for electronic interfacing, as “it just works” as they say in Apple land. There’s no messing around with device file permissions, drivers or a rubbish USB subsystem and iffy power supplies – you can use a 9V battery, USB power from a PC or anything that can supply 5V/500mA or more down a barrel connector!
I’ve been loving the analogue and PWN facilities – you don’t need an RC circuit or ADC to read from a LDR or pot like you would on the Pi.
Of course without a network interface you’re limited to standalone projects without either interfacing with a Pi or via serial to a PC or adding a wifi shield, but that’s what a Pi is for.
I’ve ordered the parts to make a standalone Atmega328P based device, essentially an Arduino Uno on a breadboard that no longer needs the PC for power or firmware.
I’ve been using arduino-mk package from Debian which means you can use GNU Makefiles to build your programs rather than the awful Java IDE.
The following code runs eight LED’s like a VU meter, via 3 wires to a 74HC595 shift register. An LDR (or just a pot) controls the speed the LED’s flash at via an analogue input, and the brightness is controlled via PWM.
#include <Arduino.h>
// init vars
const int latchPin = 5;
const int clockPin = 6;
const int dataPin = 4;
const int outputEnablePin = 3;
const int potPin = 0;
byte leds = 0;
void setup()
{
// set pins to output
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(outputEnablePin, OUTPUT);
}
void loop()
{
// count up
for (int i = 0; i < 8; i++)
{
// set brightness for all led's using pwm
analogWrite(outputEnablePin, 255-15*i);
// set led status using shift register
bitSet(leds, i);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
/* pause based on pot or ldr reading
divide by 5 for pot */
int reading = analogRead(potPin);
delay(reading);
}
// count down again by clearing bits
for (int i = 7; i >= 0; i--)
{
analogWrite(outputEnablePin, 255-15*i);
bitClear(leds, i);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
int reading = analogRead(potPin);
delay(reading);
}
}
I’ve also updated my desktop and netbook to Debian 8 Jessie (Sid actually) with only minor problems.
- OpenSSH client seems to nag about missing keys, solution is to add this to ~/.ssh/config:
LogLevel ERROR```
2. Thumbnails stopped working in Nautilus, solution:
```bash
ln -s ~/.thumbnails ~/.cache/thumbnails```
3. NFS root stopped working on the Raspbmc box, the solution was to remove the “vers=3” parameter from the nfsroot line in /boot/cmdline.txt, as it seems that the /etc/init.d/nfs-kernel-server script now disables NFSv3 by default. **Edit:** [fixed](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=707589).
4. I seemed to get warnings about missing Intel Microcode firmware or something on boot, solution:
```bash
aptitude install intel-microcode```
5. A lot of the libreoffice* packages were going to be removed as part of the upgrade from Wheezy to Jessie, I assume as they were automatically installed to replace OpenOffice and not manually chosen. The solution is to mark them as required using:
```bash
apt-get install libreoffice*```