Save the below code as spidev_test.c on to your Raspberry Pi and compile it
gcc spidev_test.c -o spidev_test
Plug your Arduino to your desktop via the serial cable. Open the arduino Serial Monitor and set the bitrate to 115200. Now, on the Raspberry Pi, run the compiled code
You should see HELLO WORLD print in the Arduino IDE Serial Monitor.
Make sure that your kernel has the required drivers (spi-bcm2708.ko and spidev.ko)
pi@raspberrypi ~/spi $ ls -al /lib/modules/`uname -r`/kernel/drivers/spi/
drwxrwxr-x 2 pi pi 4096 Aug 10 10:53 .
drwxrwxr-x 23 pi pi 4096 Aug 10 10:53 ..
-rw-rw-r– 1 pi pi 14428 Aug 10 10:53 spi-bcm2708.ko
-rw-rw-r– 1 pi pi 10852 Aug 10 10:53 spi-bitbang.ko
-rw-rw-r– 1 pi pi 15803 Aug 10 10:53 spidev.ko
-rw-rw-r– 1 pi pi 10693 Aug 10 10:53 spi-gpio.ko
This tutorial will show you how to use your Arduino as an oscilloscope. We end the tutorial with a verification portion that uses the Arduino to generate a square wave, requiring a single wire.
Lxardoscope is another Arduino + real-time graphing project that has the potential to turn an Arduino into an oscilloscope. Unfortunately, I was unable to get any readings (the visual graph remained static).
Poor Man’s Oscilloscope
First, download processing.
gzip -d processing-1.5.1-linux.tgz
tar -xf processing-1.5.1-linux.tar
Arduino uses a modified RXTXcomm.jar library. This causes a problem when the processing project runs poor man’s oscilloscope and loads the RXTXcomm.jar library bundles with the processing project. Instead, we wish for process to load the modified Arduino RXTXcomm.jar library. To remedy this problem we simply replace processing RXTXcomm.jar with the Android specific RXTXcomm.jar.
Use Arduino and two hobby servos to control physical servo gauges for cpu activity, memory usage, bandwidth, and more. The script uses the python psutil and pyserial modules. The psutil module provides an interface for retrieving information on all running processes and system utilization (CPU, disk, memory, network) providing service similar to command line tools such as ps, top, iostat, and netstat. The servo control portion of the project is based on Arduino-Python 4-Axis Servo Controlby Brian Wendt, and the Arduino sketch is essentially unmodified from the SerialServoControl Sketch on Sparkfun.
Connect the red, power lines of the servos to +5v, the black ground lines to GND, and the yellow signal lines to the desired output pins, 5 and 6 in the example (others can be used, but must be PWM capable
You can download my cheesy gauge overlay from here:
Print it out, cut out the gauges, and poke a hole in the lower center of the gauge. Remove the servo horn, slide the shaft through the hole in the gauge printout, and reconnect the servo horn on top of it.
The first step is to install the python psutil and pyserial modules. The easiest way to install it is using the python pip package manager. If you don’t have it installed already, you can install it using apt-get:
sudo apt-get install python-pip
Then install the psutil and pyserial modules:
sudo pip install psutil pyserial
Next, flash the sketch to the Arduino board. You can download it or copy and paste into the Arduino IDE.
Then download or copy and paste the Python script:
That’s it! To run the script:
Note:If you receive this error:
raise SerialException(“could not open port %s: %s” % (self._port, msg)) serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 13] Permission denied: ‘/dev/ttyUSB0′
The problem is the default permissions of the /dev/ttyUSB0 (or /dev/ttyACM0) device. This can be fixed by running the command:
Turn your Arduino UNO into a USB HID keyboard, and make buttons that do whatever you want. Make it a useful tool, with new buttons for Cut/Copy/Paste or Volume+/Volume-/Mute, or annoy your friends and colleagues by setting the keyboard to perform random keypress after random delays!
The USB HID keyboard conforms to the standard USB specification, so is functional on all modern operating systems. All this is made possible by the use of the Arduino Device Firmware Update (DFU) function.
Arduino Device Firmware Update (DFU)
The Atmega8U2 chip on the Arduino UNO can be programmed directly using the special USB protocol called Device Firmware Update (DFU). This is completely independant of the ‘normal’ method of flashing sketches to the board using the Arduino IDE.
This process is normally used to update the firmware to a more recent version, as explained in the offical Arduino guide, Updating the Atmega8U2 on an Uno or Mega2560 using DFU. Note: If your board is NOT an Arduino UNO SMD you’ll need to solder a 10k resistor (Brown-black-orange) at the back of your board as shown on the Arduino site.
However, in addition to the ability to flash standard USB Serial firmwares, we can also flash alternative firmwares as well. This allows the device to be recognized as many other device types, including keyboard, mouse, joystick, midi device, etc. This is made possible in part to the wonderful open source LUFA (Lightweight USB Framework for AVRs) USB stack, and keyboard HID firmware from Darran.
In this demonstration, we will flash generic USB HID keyboard firmware. The USB HID protocol provides manufactures the generic specifications to interact with nearly every operating system in existence. For more info, check out the USB HID Spec sheet.
Before you start, install the required packages. On Ubuntu and Debain systems, in a terminal run:
The first step is to make sure you are able to flash the standard arduino firmware. This will confirm that the programmer and the environment are both functional. NOTE: There is no chance of ‘bricking’ the device using this method. The Arduino bootloader firmware can always be updated using the DFU protocol!
NOTE: The Arduino can only be flashed with skectches through the Adruino IDE if the Arduino-usbserial.hex bootloader is active. So, to develop a USB HID device, the process becomes:
Flash Arduino-usbserial.hex bootloader with dfu-programmer (erase/flash/reset)
Plug cycle the Arduino
Flash firmware sketch using Arduino IDE
Plug cycle the Arduino
Flash Arduino-keyboard-0.3.hex bootloader with dfu-programmer (erase/flash/reset)
Test and repeat
Now that you understand how the process works, you can try out some of these keyboard samples. The easiest example is the random keypress with random delays, since it doesn’t require any components connected to the Arduino.
Random Key/Random Delay
The following two examples both use three buttons connected to the Arduino. The code can easily be changed to make the buttons perform other actions, by consulting the mapping tables in the USB HID documentation. Here is a diagram of the circuit, (created with Fritzing):
Connecting an Arduino to a Raspberry Pi is simple. In a terminal, install the Arduino IDE:
sudo apt-get install arduino
This will take a while to download and install all of the dependencies. Once completed, you can start the IDE from the terminal:
Or, from the LXDE menu, Electronics->Arduino IDE. Note: This is IDE version 0018, and does not seem to recognize boards newer then the Duemilanove. Update: The IDE version in the package manager has been updated to version 1.01 and should work with newer boards like the Uno and Leonardo now as well.
The 1 amp power supply I have connected to my Raspberry Pi was not sufficient to power both the Pi and the Arduino through the USB port, so I connected the Arduino through a powered external USB hub. This may not be necessary with a larger power supply connected to the Pi. Update: A larger power supply will not overcome this limitation; the micro USB port on the Raspberry Pi is fused with 1100mA. –Thanks cavebeat
Alternatively, the 5V GPIO R_Pi Pin can be used to power the Arduino. Just connect the 5V GPIO pin on the Raspberry Pi to the VIN pin on the Arduino, and respectively GND from one board to the other.
This eliminates the need for the externally powered USB hub, but can make development more of a chore due to the USB port restriction: the keyboard and Arduino will need to be swapped in and out to flash the Arduino.
Connect one of the photocell leads to 5v and the other to analog input pin A0. Also connect the same lead through a 10K resistor to ground. In hardware, this concept is known as a voltage divider. Then connect the ground and power leads of the TMP36 to, you guessed it, ground and 5V. Finally, connect the signal lead of the TMP36 to analog input pin A1. Here is a diagram of the completed circuit (created with Fritzing):
Next, upload the Arduino sketch to the microcontroller. The sketch uses the Microbridge implementation by Niels Brouwers. Microbridge uses Android Debug Bridge (ABD) forwarding over TCP, rather than the Google Android ADK. You can checkout the source for the Arduino sketch from Github, or just copy and paste the following into the Arduino IDE.
Always excercise caution when working with electronics. All software is provided on an "as is" basis without warranty of any kind, express or implied. Unless otherwise noted, all code content is licensed under the Apache 2.0 license