The final prototype of MegaPower mounted on RasPi |
The MegaPower photo album can be viewed here.
Comprehensive design documentation is available in the project folder here.
Running Standard Firmata Arduino Sketch
Because the UART connections are permanently in place, MegaPower can readily be set up to communicate with RasPi using the Firmata protocol.Prerequisites
Before attempting the following procedure, you should have already installed, as described on the Arduino page of this blog:- Raspian Arduino IDE,
- Gordon Henderson's extensions to Arduino IDE for Gertboard, and
- PiCocktails support for ATtiny and internal clocks.
Setting the Arduino Board
The Firmata protocol uses serial communications across the UART connection and it can not work unless the communication speed is correct. For MegaPower, in order for the communication speed to be correct, the ATmega fuses must be programmed to use the 8MHz internal clock (1MHz is not fast enough). Furthermore, when compiling the Standard Firmata sketch for uploading, the 8MHz internal clock parameters must be used by the compiler so as to match the fuse settings. Therefore, it is essential that you set the Arduino IDE to the correct board type before proceeding:Tools > Board > MegaPower /w ATmega328 (8MHz internal clock) or
Tools > Board > MegaPower /w ATmega168 (8MHz internal clock)
Setting the Communications Method
Specify that Gordon Henderson's modified version of avrdude is to be used:Tools > Programmer > Raspberry Pi GPIO
Burning the Bootloader
Having previously specified the board type that is to be the compile/upload target, you need to program the ATmega fuses accordingly by executing:Tools > Burn Bootloader
Uploading the Standard Firmata Sketch
Select the Standard Firmata sketch by executing:
File > Examples > Firmata > StandardFirmata
Then:
File > Upload Using Programmer.
N.B. Do not use the Upload shortcut.
File > Examples > Firmata > StandardFirmata
Then:
File > Upload Using Programmer.
N.B. Do not use the Upload shortcut.
Downloading the Test and Diagnostic Programs
Using the Midori web browser, download two programs to your home directory (Midori default) according to the following HyperLinks:
Running the Standard Firmata Manager
Open an LXTerminal (from the Accessories menu) and execute the command:python ~/pyfirmataManager.py
A Tk panel should appear after a delay of 10 seconds or so. The panel continuously displays samples from the 6 analogue inputs which may wander a little because they are unconnected. A slider can be operated to select which one of the ATmega's digital ports is to be managed. There are labeled control buttons that allow the selected port's operating modes to be managed.
LEDs D1,D2 & D4 can be turned ON by setting Arduino pins 8, 7 & 12 respectively to output a True. LED D3 should be lit whenever the ATmega's UART is transmitting a Mark which is nearly all the time when the Standard Firmata sketch is running.
Running the Raspberry Pi GPIO Manager
Open another LXTerminal and execute the command:sudo python ~/GPIO_manager.py
After a few seconds another Tk panel should appear with all of RasPi's GPIOs presented in passive (unobtrusive) mode. This means that GPIO Manager can be run without necessarily disrupting the operation of UART, I2C and/or SPI buses. GPIO Manager does not make any change to GPIO port states unless/until you select such change. You can control each GPIO port to input with or without pull-up/pull-down resistor or to output a High or Low logic level.
Using Both Programs Together
You can use the above two programs to demonstrate end-to-end continuity of the SPI bus circuits. For example, after setting the Standard Firmata Manager to monitor Digital Pin 13 (SCK) as an input, you can use the GPIO Manager to affect changes to GPIO Header Pin 23 and observe the state changes as they are repeated by the Standard Firmata manager. Be careful not to alter the state of GPIO Header Pins 8 and 10 or you will probably kill the UART communication session upon which the Firmata protocol depends.Related Projects
MegaMini
MegaMini's compact (1.25" x 2.5") PCB has provision for an ATmega168/328 MCU operating at 3.3V and with seven relay drivers. Via standing UART and SPI bus connections, RasPi can program and intercommunicate with the MegaMini MCU without jumper wires.MegaWire
A project of the "conjoined series", MegaWire's ATmega168/328 MCU operates at 3.3V or 5V and can be used standalone or connected to RasPi via UART, I2C and/or SPI buses. A 12MHz or 16MHz ceramic resonator can be fitted to allow Gertboard emulation or closer conformity with Arduino standards.MegaBoard Pi
With buffers and level shifters for the RasPi's GPIO ports and conforming closely with Arduino ATmega168/328 conventions (5V & 16 MHz), MegaBoard Pi includes a DC-DC converter, a high-integrity I2C bus, 16 Darlington drivers, socket for Tiny RTC (clock etc) and support for Arduino shields.Other Links
- Photo album for MegaPower
- Photo albums for all PiCocktail projects
- Project folder for MegaPower
- Project folder for MegaMini
- Project folder for MegaWire
- Project folder for MegaBoard Pi
- Folder of all PiCocktail Projects
- Standard Firmata Manager For ATmega (PiFirmataManager.py 14Aug13)
- Raspberry Pi GPIO Manager (PiGPIO_manager.py 14Aug13)
No comments:
Post a Comment