This is an interrupt driven DALI interface for Arduino. It can be used as a master or slave in a DALI Lighting system, for example as a dimmer for LED Panels.

Download the DALI library

The library is capable of running multiple DALI interfaces simultaneously. The example program demonstrates with a DALI Master (interface dali1) sending commands received by the DALI Slave (interface dali2) on a single Arduino.

 

/*###########################################################################
DALI Interface Demo

On the Arduino connect pin18 and pin19 together

Dali interface1 transmit on pin18, interface2 receives on pin19

----------------------------------------------------------------------------
Changelog:
2014-02-07 Created & tested on ATMega328 @ 16Mhz
----------------------------------------------------------------------------
        pq_Dali_Demo.ino

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.

        see http://blog.perquin.com for latest, bugs and info
###########################################################################*/

#include "pq_Dali.h"

//create the DALI interfaces
Dali dali1; 
Dali dali2; 

//callback to handle received data on dali2 interface
void dali2_receiver(Dali *d, uint8_t *data, uint8_t len) {
  Serial.print("RX");
  if(len>=2) Serial.println((int)(data[0]<<8) + data[1]); else  Serial.println((int)data[0]);
}

void setup() {
  Serial.begin(115200);
  Serial.println("DALI Master/Slave Demo");

  //start the DALI interfaces
  //arguments: tx_pin, rx_pin (negative values disable transmitter / receiver)
  dali1.begin(18,-3); 
  dali2.begin(-2,19);

  //attach a received data handler
  dali2.EventHandlerReceivedData = dali2_receiver;
}

uint16_t i=0;

void loop() {
  Serial.print("tx");
  Serial.println(i);
  dali1.sendwait_int(i);
  //delay(200);
  i+=1;
}

The file below contains the precompiled modules to use an usb drive on the AR.Drone v1.0. It has been tested to work with firmware 1.11.3 and 1.3.3

Download usb-drive.tar.gz

To install, ftp usb-drive.tar.gz to the drone’s /data/video directory, then open a telnet session to the drone and execute:
cd /data/video
tar xzf usb-drive.tar.gz
/data/video/usb-drive/load.sh

The load.sh file and the recipe to create the the .ko binaries was found here:
http://taghof.github.com/Navigation-for-Robots-with-WIFI-and-CV/blog/2012/01/12/Enabling-The-Drone-USB-Port/
Thanks Morten Daugaard and Thomas Vrang Thyregod!

Note: on my drone setting pin 127 did not enable the +5V on the USB connector, I probably blew up the pin in previous experiments!!! So, instead I used the +5V from pin1 on the navboard connector. This works, but only if the USB Stick is inserted after running the load.sh script…

 

 

This project provides an open source firmware for the AR.Drone quadrocopter by Parrot.

WARNING: This project is not supported nor endorsed by Parrot S.A., using this sofware will most likely void your warranty and might destroy your drone or make it fly away into deep space. Use at your own risk.

Click here to download the Custom Firmware or browse the source code on github

The new firmware for the drone is called ‘fly’. Upon start it will listen on UDP port 7777, waiting for the PC based controller called ‘OpenFlight’ to connect. Once OpenFlight connects, ‘fly’ kills the Parrot firmware ‘program.elf’ and takes control of the drone. Now you can fly the drone with the PC keyboard. OpenFlight logs the flight data to a file called YYYYMMDDHHMMSS_navlog.csv.

Known Issues

  • The PID controller parameters have not been optimized yet and currently only use ‘P’ parameters. In particular the height controller will probably settle below the target height, or the drone might not have enough power to take off.
  • The OpenFlight user interface is very rudimentary.
  • No soft landing function is implemented. In order to land: fly the drone to minimum altitude and then switch off the motors.
  • ‘Flat Trim’ parameters are not saved and are estimated after OpenFlight connects. Place the drone on a horizontal surface before connecting with OpenFlight.
  • No battery voltage monitoring. The drone will fall out of the sky once the battery is drained.

Install

1) FTP the folder ardrone/bin to your drone

2) Open a telnet session to your drone and execute:
# chmod 777 /data/video/bin/*
# /data/video/bin/fly

3) On your pc, start OpenFlight.exe and follow the instructions on screen.

4) (Optional) Execute the following command to make ‘fly’ start everytime you powerup the drone:
# echo -e “\n\n/data/video/bin/fly &” >> /etc/init.d/rcS

Other telnet commandline demo programs on the drone are:
You’ll need to execute `killall program.elf` before using these programs!
# /data/video/bin/navboard          – to see the navboard raw sensor data (3-axis accelleration, 3-axis gyro, sonar echos)
# /data/video/bin/attitude          – to see the navboard attitude data (pitch angle, roll angle, yaw angle, height)
# /data/video/bin/motorboard        – to control the motors/leds
# /data/video/bin/vbat              – to see the on board voltages
# /data/video/bin/video             – turns the drone into a giant optical mouse, keep it about 1 meter above ground and move it parallel to the ground. The program should report the movement.

Directories

ardrone/bin        – Pre-compiled binaries. FTP these files to your drone and run them in a telnet session.
ardrone/fly        – Custom firmware to fly the drone, the controller is in directory /pc/OpenFlight
ardrone/navboard   – Navboard driver and demo getting raw data from the navboard and converting it to realworld units
ardrone/attitude   – Attitude driver and demo calculating attitude (pitch,roll,yaw and height) estimates from navboard data
ardrone/motorboard – Motorboard driver and demo control of the 4 motors and leds
ardrone/vbat       – Battery voltage driver and demo
ardrone/gpio       – GPIO driver and demo
ardrone/video      – Video driver and demo (needs start&kill of program.elf to init the video)
ardrone/util       – Utilities
pc/OpenFlight      – C# controller for /ardrone/bin/fly

Compiling

For ardrone source code:
1) Download and install arm-2011.03-41-arm-none-linux-gnueabi.exe “Sourcery G++ Lite 2011.03-41 for ARM GNU/Linux” from http://www.codesourcery.com/sgpp/lite/arm/portal/release1803
2) On Windows: open a command prompt and cd to one of the directories
3) Run the make.bat batch file to compile the program in that directory

For pc source code
1) Download and install Visual Studio C# 2010 Express
2) Open pc/OpenFlight.sln

Changelog

19-Sep-2011 V03 Added ardrone/fly and pc/OpenFlight
20-Jul-2011 V02 Added video
17-Jul-2011 V01 Initial release

Below are the Software and Hardware versions of the AR Drone v1.0 that I used for the experiments on this site. The linux version is 2.6.26.47.

Software Versions

Firmware Release-Date Navboard Motor SDK FreeFlight-App
  1.11.3   02-08-2012?    4.70  1.42   ?   1.9.3
   1.7.4   26-07-2011     4.65  1.20 1.8     1.9
   1.6.6   25-05-2011     4.62  1.16 1.7     1.8
   1.5.1   24-02-2011     4.58  1.15 1.6   1.7.1
   1.4.7            ?     4.58  1.11   ?       ?
   1.3.3   04-10-2010     4.55  1.11 1.5     1.5
   1.0.4   23-07-2010?       ?     ?   ?       ?

Hardware Versions

Drone v1.0: 11.0
Navboard:    6.0
Motorboard:  3.0 (Motor Type/Supplier is 1.1 or 2.2)

The front camera is an OmniVision ov7725 and the datasheet is available on the web.

The bottom camera is a “cresyn qcif”, I could not find further information for this camera.

You can download a on-board c program (source+binary) to convert the drone into a giant optical mouse. Hold the drone at a fix distance above ground and the program will report the movement in the horizontal plane.

i2c bus

The cameras are configured via the i2c bus. The front camera is on /dev/i2c-1 address 0×21, the bottom camera is on /dev/i2c-0 address 0x5d.

Bottom Camera Initialization

i2cset -y 0 0x49 0x0a 0x85     - sets Vdd4 to 3.0V
gpio 59 -d ho 1                - set CE enabled

After this the camara is visible on /dev/i2c-0 address 0x5d. Now send configuration via i2c. The configuration sent over the i2c bus can be extracted from a “strace” of program.elf, but I did not dig furter into this.

Front Camera Initialization

gpio 101 -d ho 0      - set PWDN_H 1=power down,0=active
gpio 109 -d ho 1      - set CE_H 1=enabled,0=not enabled

However: This still does not make the camera visible on the i2c bus. Running program.elf does make it visible on the bus, after which “gpio 101 -d ho 1″, “gpio 101 -d i”,  ”gpio 109 -d ho 0″, or “gpio 109 -d i” will make it disappear from the i2c bus.

This blog page is dedicated to the GPIOs of the AR Drone. You can download a custom GPIO driver here.

nr I/O Description
 29 O ??? disable NAND flash write protection on P6 dev 1=disable write prot (FC6050 Parrot platform) fc6050.c
 34 O ??? disable NAND flash write protection on P6 dev 1=disable write prot
 43 O ??? Reset_Wlan 1=reset
 59 O Camera1 (Facing Down) CE 1=enabled,0=not enabled
 63 O Red LED 0=off,1=on
 64 O Green LED 0=off,1=on
 68 O Motor1 /Select 0=selected,1=deselected
 69 O Motor2 /Select 0=selected,1=deselected
 70 O Motor3 /Select 0=selected,1=deselected
 71 O Motor4 /Select 0=selected,1=deselected
 89 ? ??? CAM0_VSYNC
101 O Camera0 (Horizontal) PWDN_H 1=power down,0=active
106 I Motor Cutout
107 O Motor Enable 1=Enable
108 I Reset Button 0=unpressed,1=pressed
109 O Camera0 (Horizontal) CE_H 1=enabled,0=not enabled
127 O USB Connector Pin1 - Vusb
130 O Navboard Connector Pin2 - PGED2
131 O Navboard Connector Pin4 - PGEC2
132 O Navboard Connector Pin6 - /MCLR
158 I Pair Button 0=unpressed,1=pressed


Extension Port Pinout

Pin1 Vusb +5V (USB red)
Pin2 Vbat +11.7
Pin3 USB D- (USB white)
Pin4 RX (Serial data input to Drone)
Pin5 USB D+ (USB green)
Pin6 TX (Serial data output from Drone)
Pin7 GRD (USB black)
Pin8 No Pin

This blog page is dedicated to the I2C components of the AR Drone. You can download a custom i2c driver for the voltage measurements of the PMAAC here.

/dev/i2c-0

0×49 Atmel AT73C246 Power Management and Analog Companions (PMAAC)
0×50 24C32WI eeprom
0x5d Bottom camera

/dev/i2c-1

 0×21 Horizontal Camera – OmniVision ov7725

References

http://awesome-drone.blogspot.com/2011/01/i2c-tools-for-ardrone.html

This blog page is dedicated to the NavBoard of the AR Drone.

You can download an on-drone c program (source+compiled) to convert raw NavData into physical angle, rotation rate, height and temperature values.

Navboard Init

The following script  starts the navigation board data stream without first starting & killing program.elf. The script has been tested on an AR.Drone with firmware 1.7.4 and 1.3.3 and navboard hardware version 0xc0. I.e. the reply to command 15 is 0xc0.

The stty command sets up the serial port. The gpio command switches the /RESET pin of the navboard to high, and the echo command instructs the navboard to start the data stream. 

stty -F /dev/ttyPA2 460800 -parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
gpio 132 -d ho 1
echo -en "\x01" > /dev/ttyPA2

After this initialization the following command gets a navboard data packet:

dd if=/dev/ttyPA2 count=1 bs=46 | hexdump -C

Navboard Data Packet

After the navboard has been initialized and acquisition has been started, it sends a 46 byte data frame every 5ms (200Hz) over serial port /dev/ttyPA2. The structure of a data frame is:

 u16 size;                // +0x00 Size of the following data (always 0x2C)
 u16 seq;                 // +0x02 Sequence number, increases every update
 u16 acc[3];              // +0x04 Raw data (10-bit) of the accelerometers multiplied by 4
 u16 gyro[3];             // +0x0A Raw data for the gyros, 12-bit A/D converted voltage of the gyros. X,Y=IDG, Z=Epson 
 u16 gyro_110[2];         // +0x10 4.5x Raw data (IDG), gyro values with another resolution (see IDG-500 datasheet) 
 u16 acc_temp;            // +0x14 Accs temperature -- startup value 120 @ 25C, rising to 143
 u16 gyro_temp;           // +0x16 XYGyro temperature (IDG), 12-bit A/D converted voltage of IDG's temperature sensor -- startup value 1532 @ 25C, rising to 1572
 u16 vrefEpson;           // +0x18 ZGyro v_ref (Epson), 12-bit A/D converted reference voltage of the Epson sensor 
 u16 vrefIDG;             // +0x1A XYGyro v_ref (IDG), 12-bit A/D converted reference voltage of the IDG sensor  
 u16 us_echo;             // +0x1C bit15=1 echo pulse transmitted, bit14-0 first echo. Value 30 = 1cm. min value: 784 = 26cm
 u16 checksum;            // +0x1E Checksum = sum of all values except checksum (22 values)
 u16 us_echo_start;       // +0x20 Array with starts of echos (8 array values @ 25Hz, 9 values @ 22.22Hz)
 u16 us_echo_end;         // +0x22 Array with ends of echos   (8 array values @ 25Hz, 9 values @ 22.22Hz)
 u16 us_association_echo; // +0x24 Ultrasonic parameter -- maybe echo number starting with 0. max value 3758. examples: 0,1,2,3,4,5,6,7  ; 0,1,2,3,4,86,6,9
 u16 us_distance_echo;    // +0x26 Ultrasonic parameter -- no clear pattern
 u16 us_courbe_temps;     // +0x28 Ultrasonic parameter -- counts up from 0 to approx 24346 in 192 sample cycles of which 12 cylces have value 0
 u16 us_courbe_valeur;    // +0x2A Ultrasonic parameter -- value between 0 and 4000, no clear pattern. 192 sample cycles of which 12 cylces have value 0
 u16 us_courbe_ref;       // +0x2C Ultrasonic parameter -- coutns down from 4000 to 0 in 192 sample cycles of which 12 cylces have value 0

Navboard Commands

The following lists the commands that can be sent to the navboard. The list is obtained from ARDrone_SDK_Version_1_7_20110525\ARDroneLib\Soft\Common\ardrone_common_config.h

ADC_CMD_STARTACQ                = 1,  /**command to start acquisition with ADC                             **/
ADC_CMD_STOPACQ                 = 2,  /**command to stop acquisition with ADC                              **/
ADC_CMD_RESYNC                  = 3,  /**command to resync acquisition with ADC                            **/
ADC_CMD_TEST                    = 4,  /**command to ADC send a test frame (123456)                         **/
ADC_CMD_VERSION                 = 5,  /**command to ADC send his number : version (MSB) subversion (LSB) **/
   Example: reply to cmd 5 is 0x37 00 04 00 <--> version 4.37
ADC_CMD_SELECT_ULTRASOUND_22Hz  = 7,  /**set the ultrasound at 22,22Hz                                      **/
ADC_CMD_SELECT_ULTRASOUND_25Hz  = 8,  /**set the ultrasound at 25Hz                                         **/
ADC_CMD_SEND_CALIBRE            = 13, /**command to ADC to send the calibration                             **/
ADC_CMD_RECEVED_CALIBRE         = 14, /**command to ADC to receved a new calibration                        **/
ADC_CMD_GET_HARD_VERSION        = 15, /**get the hard version of the navboard                               **/
   Example: reply to cmd 15 is 0xc0 <--> version 11.0
ADC_CMD_ACTIVE_SEPARATION       = 16, /**enabled the separation of sources ultrasound                       **/
ADC_CMD_STOP_SEPARATION         = 17, /**disables the ultrasound source separation                          **/
ADC_CMD_RECEVED_PROD            = 18, /**command to ADC to receved the prod data                            **/
ADC_CMD_SEND_PROD               = 19, /**command to ADC to send the prod data                               **/
ADC_CMD_ACTIVE_ETALONAGE        = 20, /**command to ADC to send PWM ultrasond in continue                   **/
ADC_CMD_ACTIVE_ULTRASON         = 21, /**command to ADC to stop send PWM ultrasond in continue              **/
ADC_CMD_ACTIVE_TEST_ULTRASON    = 22, /**teste de la perturbation de l'ultrason par le wifi                 **/

Navboard Connector Pinout

1 : +Vcc (5v)
2 : PGED2/RP10(1)/CN16/PMD2/RB10 (8) (ICSP)  <--> GPIO 130
3 : Txd (to Navboard)
4 : PGEC2/RP11(1)/CN15/PMD1/RB11 (9) (ICSP)  <--> GPIO 131
5 : Rxd (from Navboard)
6 : /MCLEAR (18)                             <--> GPIO 132
7 : GND
8 : GND

References

http://embedded-software.blogspot.com/2011/01/reading-navigation-data-directly-from.html

This blog page is dedicated to the motors of the AR Drone.

You can download an on-drone c program (source+compiled) to control the motors and leds.

Pinout

Pin 1 Battery 11.4V
Pin 2 VCC 5V (ATMega8a VCC Pin4+5)
Pin 3 TX+RX (ATmega8a Pin30+31)
Pin 4 IRQ to main board (ATmega8a PC3 Pin26)
Pin 5 GND

Pin 1 Red
Pin 2 White
Pin 3 Motor1=Yellow,M2=Orange,M3=Blue,M4=Green
Pin 4 Motor1=Purple,M2=Gray,M3=Brown,M4=Pink
Pin 5 Black

IRQ

Whenever the motor controller detects a problem, it will stop running and toggles the IRQ pin. A rising edge to 5v on the IRQ pin sets GPIO 106 (i.e. `gpio 106 -r` returns 1). Pin 106 can be reset to 0 by toggling GPIO 107, i.e. `gpio 107 -d ho 0; gpio 107 -d ho 1`.

In other words this is a flipflop circuit, with Set=IRQ, Reset=GPIO107 and Data=GPIO106.

GPIO

gpio 68 -d i = select motor1
gpio 68 -d ho 0 = deselect motor1
gpio 69 -d i = select motor2
gpio 69 -d ho 0 = deselect motor2
gpio 70 -d i = select motor3
gpio 70 -d ho 0 = deselect motor3
gpio 71 -d i = select motor4
gpio 71 -d ho 0 = deselect motor4
gpio 106 -i = IRQ input, 1=IRQ requested
gpio 107 -d ho 0; gpio 107 -d ho 1 = reset GPIO 106 to 0

Serial Communication

Baud rate: 115200, 8n1

Unicast Commands

Configuiration sent to single motor. The motor is selected with GPIO 68 to 71.

write -> reply in hex, null means no reply
E0 -> status             : get status 00=ok, 50=need reflash
if(status==50){
 71 64bytes 70 -> null    : program flash, repeated 120 times (120 blocks of 64bytes = 7920bytes)
 91 -> 120 bytes          : get 120 checksums of 64 byte flash blocks
 A1 -> A0 FF              : set status OK (command send after command 91)
}
01 or 02,03,04 -> null    : assign as motor1,2,3,4
40 -> 11 bytes            : check versions (eg 01 0b 03 00 01 01 0a 0a 1a 0a 0a = soft version 1.11, hard version 3.0, supplier 1.1, lot number 10/10, FVT1 26/10/10)

Multicast commands

Sent to all motors.

A0 A0 A0 A0 A0 A0 -> null : start of multicast
2x xx xx xx xx -> null    : set speeds sent every 5ms
89 or 8A,8B,8X -> 28 2f   : check motor1,2,3,4 alive - sent one command every 25 frames (i.e. every 125ms one motor, same motor every 500ms)
6x xx,7x xx -> null       : set leds bit5=Red Rear Left, bit6=Green Rear Left, bit7=Red Rear Right, bit8=Green Rear Right, bit9=Red Front Right, bit10=Green Front Right, bit11=Red Front Left, bit12=Green Front Left  (011grgrg rgrxxxx)

Init Sequence

(as used by program.elf)

for x=1 to 4
    CSx_ Low
    TX E0, RX 2 bytes
    TX 91, RX 121 bytes
    TX A1, RX 3 bytes
    TX 00+x, RX 1 byte
    TX 40, RX 12 bytes
    CSx_ High
    wait 500ms
end for
for x=1 to 4
    CSx_ Low
    TX E0, RX 2 bytes
    TX 00+x, RX 1 byte
    TX 40, RX 12 bytes
    CSx_ High
end for
wait 500ms
CS1_,CS2_,CS3_,CS4_ Low (select all)
for x=1 to 6
    TX A0 -> RX 1 byte
end for

Set Speeds

001aaaaa aaaabbbb bbbbbccc ccccccdd ddddddd0
a,b,c,d = 9 bits for motor 1,2,3,4 (msb first)
transmitted every 5ms (200Hz)
every 80ms send 2x + one 8x code

References

http://fenrir.naruoka.org/archives/000805.html

http://www.ardrone-flyers.com/forum/viewtopic.php?f=13&t=1025&start=15

Test Script

The following script initializes the motor and starts the control loop. The control loop flashes all leds. The script has been tested as replacement for program.elf on a AR.Drone with firmware version 1.7.4 and 1.3.3, motor software version 1.20 and 1.11, motor hardware version 3.0, motor supplier 1.1 and 2.2.

#set baud rate
stty -F /dev/ttyPA1 115200

#reset IRQ flipflop - on error 106 read 1, this code resets 106 to 0
gpio 106 -d i
gpio 107 -d ho 0
gpio 107 -d ho 1

#all select lines inactive
gpio 68 -d ho 1
gpio 69 -d ho 1
gpio 70 -d ho 1
gpio 72 -d ho 1

#configure motor1
gpio 68 -d i
echo -en "\xe0" > /dev/ttyPA1
usleep 100
echo -en "\x01" > /dev/ttyPA1
usleep 100
echo -en "\x40" > /dev/ttyPA1
usleep 100
gpio 68 -d ho 1

#configure motor2
gpio 69 -d i
echo -en "\xe0" > /dev/ttyPA1
usleep 100
echo -en "\x02" > /dev/ttyPA1
usleep 100
echo -en "\x40" > /dev/ttyPA1
usleep 100
gpio 69 -d ho 1

#configure motor3
gpio 70 -d i
echo -en "\xe0" > /dev/ttyPA1
usleep 100
echo -en "\x03" > /dev/ttyPA1
usleep 100
echo -en "\x40" > /dev/ttyPA1
usleep 100
gpio 70 -d ho 1

#configure motor4
gpio 71 -d i
echo -en "\xe0" > /dev/ttyPA1
usleep 100
echo -en "\x04" > /dev/ttyPA1
usleep 100
echo -en "\x40" > /dev/ttyPA1
usleep 100
gpio 71 -d ho 1

#all select lines active
gpio 68 -d i
gpio 69 -d i
gpio 70 -d i
gpio 71 -d i

#start multicast
echo -en "\xa0" > /dev/ttyPA1
usleep 100
echo -en "\xa0" > /dev/ttyPA1
usleep 100
echo -en "\xa0" > /dev/ttyPA1
usleep 100
echo -en "\xa0" > /dev/ttyPA1
usleep 100
echo -en "\xa0" > /dev/ttyPA1
usleep 100
echo -en "\xa0" > /dev/ttyPA1
usleep 100

#reset IRQ flipflop - on error 106 read 1, this code resets 106 to 0
gpio 106 -d i
gpio 107 -d ho 0
gpio 107 -d ho 1

#multicast loop
while true
do

echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
#all leds orange
echo -en "\x7f\xf0" >/dev/ttyPA1

echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
echo -en "\x20\x00\x00\x00\x00" >/dev/ttyPA1
usleep 5000
#all leds off
echo -en "\x60\x00" >/dev/ttyPA1

done

A set of sensor and actuator modules for mobile robots. The modules are build using AVR ATMega microcontrollers and use a minimum of external component. The microcontrollers are programmed in C (GCC) to allow for easy modification of the code. I2C is used to communicate between the modules, the modules are interconnected with only 4 wires. The i2cMaster module can be used to control the modules via a serial interface. The actual module code and the bus interface code are split in two separate source files, it is also possible to rebuild the code for use with a different communicatio interface.

License

This project is under the GPL license, see the LICENSE.txt file for details.

Download

Click here to download OpenSense.

Available modules

Module Status Description
I2cMaster Works Acts as a interface between the i2c module bus and the external serial bus.
Servo Works Actuator for up to 16 hobby servos inclusive speed control.
Sonar Works Sonar distance sensor for up to 8 sonar units.
Motor Works Synchonized and PID speed controlled actuator for a two DC motor differential drive robot with encoders.
DockTx Works Docking station IR transmitter.
DockRx Works Docking station IR receiver.
RcReceiver Works Decodes signals from a RC-Receiver.
RcReceiverMaster Works I2c bus master, decodes RC-Receiver signals and drives DC motor and servos. Mainly for demostration purposes: it digitize the RC-Receiver servo PWM signals, sends them via i2c to the servo module which converts them back to servo PWM signals. Easier is of course to directly connect the servo to the RC-Receiver.
LCD Works Drives a character LCD display. Currently integrated in modI2cMaster, not individual i2c module yet.
Battery Planned Monitoring of discharge/charge current, voltage and Ah.
IrDistance Planned Drives up to 5 Sharp GP2D12 (10-80cm) / GP2Y0A02YK (20-150cm) / GP2D120 (4-30cm) IR distance sensors.
IrRemote Planned Receive commands from a IR remote control.
Radio Planned Receive/Transmit via low cost 433 MHz radio modules.

Files and Directories

doc The documentation is in the ‘doc’ directory.

modXXX contain the source code and Makefile for a specific module. Run ‘make’ in a mod subdirectory to compile the source code and program the microcontroller.

lib contains shared libraries. The libraries are the actual workhorses of the modules, each module is actually a i2c wrapper around the library code. It’s is therefor possible to combine several libraries into a single module, as long as the libraries don’t exclusively use the same resources such as timers or interrupts. For example the i2cMaster module includes the lcd.c library to implement a lcd driver as well.
vb_HexTerm Contains a terminal program written in VB6 to communicate with i2cMaster. Functioning but needs some cleanup work. In the send box type ‘s’ and hit enter to scan the i2c bus. Note: all input is decimal, so ‘r 170 10 4′ reads 4 bytes from slave AA (=170) command 0A (=10).

Software and Hardware Setup

  • Download OpenSense and WinAVR.
  • If you do not have a programmer, solder together this very simple STK200 compatible parallel port programmer:
    Wire Par-Port Pin ATMega Signal AtMega8 (DIP) Pin AtMega16 and 32 (DIP) Pin
    1 25 Grd 8 11
    2 8 SCK 19 8
    3 4 MISO 18 7
    4 7 MOSI 17 6
    5 10 /Reset 1 9
      connect 2 to 12      
      connect 3 to 11      
  • Connect the programmer to an ATMega8 and apply VCC.
  • Run “avrdude -p m8 -c stk200 -t” from a DOS prompt.
  • For 8Mhz internal oscillator enter commands: “write lfuse 0 0x0d1″ and “write hfuse 0 0xe4″
  • Or, for external crystal oscillator enter commands: “write lfuse 0 0x0d1″ and “write hfuse 0 0xef”
  • Type “quit” to exit avrdude
  • cd to one of the pq-module directories
  • Type “make” and the module will be compiled and programmed on the microcontroller.

    Why AVR ATMega?

  • Low cost: 8k flash 1k ram for less than $4 each.
  • Availability: Can be easily procured in small quantities.
  • DIP versions for easy prototyping (bread board).
  • Low cost programmers available.
  • Opensource C compiler (GCC) available.
  • Opensource development toolchaing (WinAVR) available.
  • Large developer community with loads of examples.
  • C-friendly architecture: stack, single linear RAM and Flash spaces.
  • Full range of periphirals: on-chip oscillator, timers, uart, i2c, adc, hardware 8x8bit multipicator, etc.
  • High speed processing: up to 24 MIPS with ATMega8x devices.

    Programming Style

    The programs are designed for small devices, usually 8k flash. I tried both to keep the number of files to a minimum and the Makefiles as uniform and simple as possible. I opted to directly include the library c files in the code usually without using header files. Precompiler #define directives and macros are used to steer the properties of the individual modules. Read the library source file to get a list of the available options. All functions, macros and defines in a library are prefixed with a 3-5 character prefix followed by an underscore. For example all mot_XXX functions are in the motor.c library.

    I2C interface

    One address (0xFF) has been reserved for default functionalty in each module:

  • Set the I2C SLA address
  • Set the I2C bus speed
  • Enable/disable interrupts.
  • Reset
  • Read module configuration and save the configuration to eeprom
    I2C Command Description
    r ff 00 00 Get 16 char device string (shortcut= r ff)
    r ff 01 00 Get 2 byte twipq library verson (major,minor) (shortcut=r ff 01)
    w ff 02 00 <newsla> Set slave i2c address to newsla
    r ff 02 01 Get interrupts status : 1=send interrupts to busmaster, 0=disable interrupts
    w ff 02 01 <0|1> Set interrupts status : 1=send interrupts to busmaster, 0=disable interrupts
    r ff 02 02 Get i2c speed as multiple of 10kbaud
    w ff 02 02 <speed> set i2c speed as multiple of 10kbaud
    r ff 03 <adr> Read user eeprom, see module documentation for details.
    w ff 03 <adr> <val> Write user eeprom, see module documentation for details.
    w ff 04 Reset device (required after changed in configuration)
    w ff 05 Clear eeprom + reset + load defaults
  • © 2018 Tech Toy Hacks Suffusion theme by Sayontan Sinha