How can you backup your SD cards for your Raspberry Pi?

Given that SD cards have a limited lifetime for writes, using an SD card for a harddrive for Pi may not be the smartest idea in terms of reliability or longevity, so asking how you back up your SD card is a good question. There’s some good answers here.

Specifically on the Mac, find out the disk number of the attached sd card with :

diskutil list

then use the dd command:

dd if=/dev/rdiskx of=/path/to/image bs=1m

where x is the disk number listed from diskutil.

Raspberry Pi Raspbian wifi dongle network config

There’s probably many ways you could configure a similar setup to this, but here’s what worked for me.

This is for static IP on wired, and a different static IP on wireless, where the wireless is using WPA2. I also have two different routers one for wired and for one wireless. Replace static_ip_here with your required ip addresses, and x and y with the IP addresses for your routers.

Edit /etc/network/interfaces:

auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.static_ip_here
netmask 255.255.255.0
gateway 192.168.1.x

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.static_ip_here
netmask 255.255.255.0
gateway 192.168.0.y
wpa-ssid "your_ssid"
wpa-psk "your passphrase"
wpa-pairwise CCMP
wpa-group CCMP

Useful Java ME 8 Embedded code snippets

Collection of ME 8 Embedded code snippets:

  • Using java.util.TimerTask and Timer – for scheduling periodic tasks (reading a sensor, checking a status etc eg
MyTimerTask myTimerTask = new MyTimerTask();
Timer timer = new Timer();
timer.schedule(myTimerTask, millisBeforeStarting, millisBetweenExecution);
  • Opening a GPIO pin:
this.pin = PeripheralManager.open(this.pinId); 
this.pin.setValue(true); // true = on, false = off
  • Adding an EventListener to a switch:
GPIOPinConfig config = new GPIOPinConfig(this.portId, this.pinId,
    GPIOPinConfig.DIR_INPUT_ONLY, PeripheralConfig.DEFAULT,
    GPIOPinConfig.TRIGGER_BOTH_EDGES,
this.pin = PeripheralManager.open(config);
this.pin.setInputListener(this);

… where this implements PinListener and valueChanged() method:

public void valueChanged(PinEvent event) {
    GPIOPin eventPin = event.getPeripheral();
    ...
}
  • Opening an I2C device for input/output:
I2CDeviceConfig config = new I2CDeviceConfig(i2cBus, address, addressSizeBits, serialClock);
myDevice = PeripheralManager.open(config);
  • Read from a UART device:
this.uart = PeripheralManager.open(UART_DEVICE_ID);
this.uart.setBaudRate(9600);

InputStream is = Channels.newInputStream(uart);
this.serialBufferedReader = new BufferedReader(new InputStreamReader(is));
  • Read using Generic Connection Framework:
CommConnection conn = (CommConnection)Connector.open("comm:/dev/ttyAMA0;baudrate=9600");
InputStream inputStream = conn.openInputStream();
this.serialBufferedReader = new BufferedReader(new
    InputStreamReader(inputStream));
  • Open and write to a record store:
this.store = RecordStore.openRecordStore(storeName, true);
byte[] dataBytes = data.getBytes();
recordNum = store.addRecord(dataBytes, 0, dataBytes.length);

Raspberry Pi ARM ASM syscall notes

A few notes on useful syscalls:

SWI 0 : executes instruction based on value in R7

Write to screen: R7 = 4

MOV R7, #4 @ Syscall 4 = write to screen
MOV R0, #1 @ stdout: move 1 to R0
MOV R2, #4 @ length of string to R2
LDR R1, =string
SWI 0
string:
    .ascii "testn"

Read from keyboard: R7 = 3

MOV R7, #3 @ Syscall 3 = read from keyboard
MOV R0, #0 @ stdin?: move 0 to R0
MOV R2, #4 @ length of string to ready to R2
LDR R1, =string @ load R1 value to string location 
SWI 0
string:
    .ascii ""