Queen's Mostly Autonomous Sailboat Team Wiki
Advertisement



ArduinoMega

Arduino Mega Controller

Our History of Arduino[]

After evaluating the microcontroller from 2009/2010, and consultation between professors in the Electrical and Computer Engineering department, the Arduino microcontroller has been selected as an appropriate replacement/substitution to the board previously in use. The possibility that the sailing code will one day exceed the limitations of the Arduino microcontroller has been considered, and for the time being Arduino will be able to handle the code required by our boat. If the time comes that the designed code requires stronger hardware (main limitations of the Arduino is a 16 Mhz), a new microcontroller (or the currently owned one) will be implemented, best case scenario is that at that point, there will be an Arduino controller with a faster clock speed.



Arduino Mega Discussion[]

The Arduino Mega is the bigger brother of the Arduino Duemilanove, powered by the ATmega1280, sees large improvement through both processing power and physical connections. The ATmega1280 chip, although still powered by a 16 Mhz clock speed, has a four times as much memory as the ATmega168 (Flash Memory, SRAM, EEPROM, Clock Speed) and is connected to roughly four times as many pins, including three additional UARTs. UARTs allow us to take an RS-232 signal, send it through a RS-232 to TTL converter, and connect to the Mega using only TX and RX pins. Additional features include 54 digital I/O pins (14 of which can provide PWM output), 16 analog pins and compatibility with most Arduino shields. Shields allow us to add further functionality to our controller, particularly wireless communication to a land based computer through magic called Zigbee.


Serial[]

The Arduino mega has 3 serial ports which are connected to TTL level pins (we believe these are 5V), and a 4th which is connected to a USB-B (port 0, 1). [1].


The buffer is 128 bytes long. This can be modified by opening the file


arduino-0022\hardware\arduino\cores\arduino\HardwareSerial.cpp


and modifying


#define RX_BUFFER_SIZE 127


to have a different size.


* Presently, this is 511 on the bay computer, and should be modified on new Arduino-0022 installations or other computers.

* This is to allow a full Wind Sensor data dump to be stored, presently around 280 characters per second; we can reduce this number once the Wind Sensor is sending less data, ie when we figure out how to talk to it.

* This (with 2 serial channels) uses 1kb of our 8kb of SRAM available.


The speed at which the processor loops will have to empty the buffer fast enough to avoid missing data; or compensate for this (data less frequent, check how much data is in the buffer.


SerialX.read() ; X = 1,2,3 (or nothing for the USB-B port)


These will be the Zigbee (USB-B), Wind sensor, and Compass. Pololu will not be used? (comment?)


Internal Memory[]

Our Arduino Mega (2560) has 8kb of SRAM that is used for storing and manipulating data. The 256kb of Flash memory is where the program is actually stored. Variables that will not be modified by the code (such as look-up tables for polar plots) can be stored in Flash memory or EEPROM if desired. See http://www.arduino.cc/en/Tutorial/Memory for more information (remember that the numbers given on that page are for the ATmega168 chip which has much less memory than the ATmega2650 on our Arduino Mega)



Communication with Computer (via Zigbee)[]

MAST Zigbee documentation


[2] this talks about the board resetting with receipt of serial data through the serial monitor. (look into this later)


With the old microprocessor TS-7260, a COM1 connection had complete control over the microprocessor, ie rebooting, etc.


NOW with the Arduino, there is likely not reboot functioning via COM port, selecting a program, other functionality


* Arduino has a reset pin that when triggered acts just like the physical reset button. This pin was designed for boards whose reset button is blocked by shields (as ours will be with the Xbee expansion)

* Triggering this reset pin will reboot Arduino into the "loop" function (main program) therefore a menu program would be suitable and from there we would be able to launch specific programs

* menu program becomes CRITICAL

* test what functionality X-CTU and mini-com have with Serial.read() from Zigbee to Arduino





Can also add additional serial port channels through software (which will not have a buffer to store data, best for output ie Pololu) [3]


Installing Arduino Environment[]

Linux[]

If you need to install Arduino on Linux, go here: http://www.arduino.cc/playground/Learning/Linux For MAST's linux distro, KDE-Ubuntu, use sudo apt-get install gcc-avr and all the other things it lists on that website.


Or follow the instructions here. It suggests adding the user account to the Dialout group - we tried this and the arduino IDE is still having trouble finding the board reliably.


Perhaps this fix for setting DTR low is the problem?


ls -l /dev/ttyACM0 will list permission on the USB port; chmod 777 if it isnt


Forum suggestions[]

Most forum suggestions are to reflash the firmware; more info on Arduino Firmware page.


Windows[]

Has been done. Documentation on Arduino site .


To start Arduino, double click 'Arduino' shortcut. This will open the Arduino environment, be sure that COM3 is selected, and that the board is set to Arduino Mega 2560. These should be automatic settings that do not change with reboots, but we will see.


To upload to Arduino, click the 'upload' button within the sketch environment. Second button from the left of the top buttons.


Programming[]

Uploading to Arduino[]

To upload make sure you;


1) Make sure the board is not conductive surface


2) Make sure you have selected the correct serial port (/dev/ttyACM0)


3) Make sure you select the correct board (Arduino Mega 2560)


3) try pushing reset before and/or after uploading


4) Use Arduino forum


5) Check your usb port/ try a different one



We are having significant trouble getting it to connect reliably through KDE-Ubuntu. Possible fix above (add account to group). Either timeouts, or more recently the USB port we're plugged into being "already in use" or not seeing the arduino on the port. This does not seem to be a problem with windows; there is however no Arduino Mega 2560 drivers installed on the third floor computers.


Arduino-Specific Coding[]

http://www.ladyada.net/learn/arduino/lesson4.html Excellent tutorial on serial, general math, data types


EEEPROM[]

http://www.arduino.cc/en/Reference/EEPROM


the arduino has EEPROM memory which could possibly be used to store state variables before a possible power-down (ie from low power?)


Arduino vs TS7260[]

The code compiled for TS7260 is linked between multiple files; this might cause trouble for porting to arduino.



Hardware[]

Using Arduino as a power source[]

http://arduino.cc/en/Main/ArduinoBoardMega2560 DC Current per I/O Pin: 40 mA


This means that it will break our arduino to power the wind sensor with it; compass might be ok, it draws 45mA; and servo motors cannot be powered by arduino.


Arduino Serial Ports[]

Compass#On_arduino has details on how to connect the compass via the arduino serial ports. The debugging notes have been moved to Debugging Arduino Serial


Links[]

Arduino serial guide


Arduino serial guide intro


Arduinos RS232 tutorial, using an MAX3232


Zigbee with Arduino[]

How_to_Zigbee#Zigbee_with_Arduino has details on how to connect zigbee to arduino using a zigbee shield.

Using Servo Motors[]

When using Servo motors you can look here for some basic functions http://arduino.cc/en/Reference/Servo


you must use a common ground, so that the arduino providing the signal is being powered by the same source as the motor or anything else.


External Links[]

"Whats a microcontroller?" by Paralax List of Hardware options


Tutorials


Arduino emulator, emulino


Breadboard design software, apparently has a programmable arduino


Blog post about arduino emulators


Waspmote, a zigbee module for arduino


Wiki article with links to information about connecting hardware to arduino


http://www.freeduino.org/ Arduino website link index

Advertisement