Difference between revisions of "Microcontroller And Electronics"

From veeOp Wiki
Jump to: navigation, search
(Re-programming the on-board Arduino Compatible)
 
(7 intermediate revisions by one user not shown)
Line 7: Line 7:
 
In the distros provided here in the home directory for the "pi" user, you'll find a directory named 'arduino-vop' which already has an editable version of the code that's already on the microcontroller that you can use to get started!
 
In the distros provided here in the home directory for the "pi" user, you'll find a directory named 'arduino-vop' which already has an editable version of the code that's already on the microcontroller that you can use to get started!
  
 +
[[Image:aon-jumper-web.png|thumb|225px|Location of the "always on" (A-ON) header/jumper on the veeOP. (Shown with jumper off)]]
  
=== Installing the necessary tools ===
+
=== Hardware Steps ===
  
If you're not using a veeOP customized distro, you might wish to install the tools from scratch. The examples given here are from PiDora (the Fedora distro for the pi), but, can be easily applied to most distros.
+
One important step if you're going to re-program the microcontroller on the veeOP is to use a jumper on the "A-ON header" (short for "always on"). Because the veeOP controls power to the Raspberry Pi, when programming it -- you don't want the veeOP to turn off your Raspberry Pi. When a jumper is on this header, it makes it so that the Raspberry Pi is always in an on state. It's also imperative that you take the jumper off when you're ready to put the veeOP back in your vehicle, as it won't function the way it's intended! ...As you might imagine.
  
For example, where I say "yum install package_name" under a Debian-based distro you can use "apt-get install package_name".
+
Another option for programming the on-board arduino compatible microcontroller is to use the FTDI header on the board. This allows you to use an FTDI cable (which is basically a USB-to-RS232 adapter) to reprogram the microcontroller. Allowing you to program the micro without using the Raspberry Pi. However, since this also supplies the board with power, it's important that you do not have a micro USB cable attached, too.
  
 +
Your veeOP should come with jumpers provided. However, if you are to lose them, any standard jumper from a PC will also work. (Or you can wrap a wire around them, in a pinch.)
  
== Using Arduino Shields with your veeOP ==
+
=== Installing the necessary tools ===
  
The veeOP is designed to be able to extend it using Arduino Shields. There are shields for all kinds of applications
+
If you're not using a veeOP customized distro, you might wish to install the tools from scratch. The examples given here are from Raspbian, but, can be easily applied to most distros.
  
* GPSr (global position system recievers)
+
First install Arduino and the requirements for inotools
* GSM (cell phone service)
+
* LCD Displays
+
* Wireless (like the ZigBee / XBee)
+
* And much, much more.
+
  
== Are you new to Arduino? ==
+
sudo apt-get install arduino
 +
sudo apt-get install python-setuptools
 +
sudo apt-get install picocom
  
Don't sweat it! [http://arduino.cc/ The Arduino] is intended to be an approachable technology, and one that gives a new user a lot of power. And, you'll feel great interacting directly with microcontrollers. The best part is, you can use your veeOP to help you learn.
+
Then install ino with easy_setup
  
You can log onto the veeOP connected to your raspberry pi, but, you might want to [http://arduino.cc/en/Main/Software download the Arduino IDE] (integrated development environment) and get started on your workstation (your laptop or desktop computer). You can compile the veeOP code right there to do some initial testing and exploration.
+
sudo easy_install ino
  
Some resources you might be interested in:
+
Add the pi user to the tty group
  
* [http://arduino.cc/en/Guide/HomePage Getting Started With Arduino]
+
sudo usermod -a -G tty pi
* [http://arduino.cc/en/Main/Software Arduino Software Download]
+
* [http://oreilly.com/arduino/ O'Reilly Arduino Development Landing Page]
+
* [http://shop.oreilly.com/product/9780596802486.do The Arduino Cookbook]
+
  
== The I²C API ==
+
And make a symlink to the tty that inotool / arduino likes...
  
: ''Main Article:'' [[I²C API]]
+
sudo ln -s /dev/ttyAMA0 /dev/ttyACM0
  
The I²C API on the microcontroller is a rather simple little set of commands that rides on I²C. For more information about [http://en.wikipedia.org/wiki/I%C2%B2C I²C we direct you to Wikipedia].
+
And make sure it's writable
  
In practice, this is also abstracted by the veeOP REST API, which resides on the Raspberry Pi. The REST API is much more verbose, and provides more flexibility in handling the day-to-day tasks with your veeOP. But, should you see an opportunity to extend it's communication -- it's a simple system. Don't let all the bits and bytes confuse you here, when it comes down to it it's this simple:
+
sudo chmod o+w /dev/ttyAMA0
  
#Raspberry Pi says "Hi, microcontroller, I want you to do something."
+
== Download the code! ==
##...And sends it 4 bytes to tell it to do so.
+
#Microcontroller says "Sure! I did what you want, and here's some info about it."
+
##...And it sends 4-bytes back to the Raspberry Pi.
+
  
The veeOP uses the Raspberry Pi as the I²C master, with the arduino-compatible being the slave, at address 4 (0x04) by default (this is configurable in the library.)
+
: ''Main Article:'' [[Downloads]]
 
+
=== Download the code! ===
+
  
 
If you're using one of the downloadable pre-customized distros, you can look in:
 
If you're using one of the downloadable pre-customized distros, you can look in:
Line 63: Line 55:
 
It's as simple as placing the vOP folder into your libraries folder in your Arduino's default install directory, to compile it. Check out the provided example sketch as it will guide you into extending the functionality. You can use the provided example sketch to keep the veeOP functionality intact, but! Use the microcontroller for other purposes, and it's extend it's functionality.
 
It's as simple as placing the vOP folder into your libraries folder in your Arduino's default install directory, to compile it. Check out the provided example sketch as it will guide you into extending the functionality. You can use the provided example sketch to keep the veeOP functionality intact, but! Use the microcontroller for other purposes, and it's extend it's functionality.
  
=== How Commands are transmitted ===
 
  
Commands are sent to the veeOP arduino-compatible with a 4-byte tuple. It looks like so:
+
== Using Arduino Shields with your veeOP ==
  
: <math>(C,P_1,P_2,C_e)</math>
+
The veeOP is designed to be able to extend it using Arduino Shields. There are shields for all kinds of applications
  
Where each element is a single byte, representing:
+
* GPSr (global position system recievers)
 +
* GSM (cell phone service)
 +
* LCD Displays
 +
* Wireless (like the ZigBee / XBee)
 +
* And much, much more.
  
: <math>
+
[[Image:VeeOP_v003.png|thumb|350px|The veeOP schematics as of v0.300]]
    \begin{align}
+
      C & = \text{Command}                      \\
+
      P_1 & = \text{First Parameter}            \\
+
      P_2 & = \text{Second Parameter}            \\
+
      C_e & = \text{Command Ending (0x0A)} \\
+
    \end{align}
+
  </math>
+
  
<BR />
+
== The Schematics ==
* <math>C</math> (command) is any (known) value other than 10 (0x0A, in hex.) and originally assigned all higher 10.
+
* <math>P_1</math> & <math>P_2</math> are sometimes treated as individual integer values each, or together as a 16 bit integer, depending on context.
+
* <math>C_e</math> Command ending allows the microcontroller know when a command is incomplete, or too many bytes are sent.
+
<BR />
+
  
Why's it end in 10? It's the "end of line" ASCII character, check it out [http://asciitable.com asciitable.com].
 
  
=== How responses are received ===
+
An extensible platform isn't exactly that without knowing how to really dig deep into the electronics. You can simply use the board "like an attached Arduino-compatible" -- or you can really get in and hack it how you want.
  
When the microcontroller recieves the proper 4 bytes for the command, it responds in turn with a response of 4 bytes.
+
Or! You can even build your own. We've included the schematic to show you that we really do care about the Open Source Hardware (OSHW) movement.
  
: <math>(E,C_r,R_1,R_2)</math>
+
== Are you new to Arduino? ==
  
Where each element is a single byte, representing:
+
Don't sweat it! [http://arduino.cc/ The Arduino] is intended to be an approachable technology, and one that gives a new user a lot of power. And, you'll feel great interacting directly with microcontrollers. The best part is, you can use your veeOP to help you learn.
  
: <math>
+
You can log onto the veeOP connected to your raspberry pi, but, you might want to [http://arduino.cc/en/Main/Software download the Arduino IDE] (integrated development environment) and get started on your workstation (your laptop or desktop computer). You can compile the veeOP code right there to do some initial testing and exploration.
    \begin{align}
+
      E & = \text{Error Code}          \\
+
      C_r & = \text{Command return}    \\
+
      R_1 & = \text{First return byte}  \\
+
      R_2 & = \text{Second return byte} \\
+
    \end{align}
+
  </math>
+
  
<BR />
+
Some resources you might be interested in:
* <math>E</math> errors of a value of 0 denotes an error-free response, any non-zero value is defined in a table below.
+
* <math>C_r</math> is a redundant byte that represents <math>C</math> from the sent command. This is used for error handling on the raspberry pi.
+
* <math>R_1</math> & <math>R_2</math> are the resulting responses from the command. Treated as two bytes, or a 16-bit unsigned integer depending on the context of the command.
+
<BR />
+
  
=== Commands ===
+
* [http://arduino.cc/en/Guide/HomePage Getting Started With Arduino]
 +
* [http://arduino.cc/en/Main/Software Arduino Software Download]
 +
* [http://oreilly.com/arduino/ O'Reilly Arduino Development Landing Page]
 +
* [http://shop.oreilly.com/product/9780596802486.do The Arduino Cookbook]
  
In this chart, we show each available command, and it's return type. The example commands and responses are given showing each 4-byte command and response, in decimal.
+
== The I²C API ==
  
{| class="wikitable"
+
: ''Main Article:'' [[I²C API]]
|-
+
! Command Description !! Value !! <math>P_1</math> !! <math>P_2</math> !! Returns !! Example Command (Decimal) !! Example Response (decimal) !! Example Description
+
|-
+
|Check Ignition State
+
| 11
+
| align="center" | -
+
| align="center" | -
+
| Boolean
+
| align="center" | <math>(11,0,0,10)</math>
+
| align="center" | <math>(0,11,0,1)</math>
+
| Response showing the ignition is on. An <math>R_2</math> value of 1 denotes the ignition is on, where a value of 0 denotes it being off.
+
|-
+
|Last time ignition changed (seconds ago)
+
| 12
+
| align="center" | -
+
| align="center" | -
+
| 16-bit Integer
+
| align="center" | <math>(12,0,0,10)</math>
+
| align="center" | <math>(0,12,1,2)</math>
+
| Responds showing us the ignition last changed it's state 258 seconds ago. See 16-bit integer note, below.
+
|-
+
|Last time ignition changed (minutes ago)
+
| 13
+
| align="center" | -
+
| align="center" | -
+
| 16-bit Integer
+
| align="center" | <math>(13,0,0,10)</math>
+
| align="center" | <math>(0,13,0,90)</math>
+
| Responds showing us the ignition last changed it's state 90 minutes ago
+
|-
+
|Pat the watchdog
+
| 15
+
| align="center" | -
+
| align="center" | -
+
| -
+
| align="center" | <math>(15,0,0,10)</math>
+
| align="center" | <math>(0,15,0,0)</math>
+
| Responds simply stating it pat the watchdog without an error.
+
|-
+
|Echo bytes sent
+
| 14
+
| align="center" | Byte
+
| align="center" | Byte
+
| 2 Bytes
+
| align="center" | <math>(14,1,2,10)</math>
+
| align="center" | <math>(0,14,1,2)</math>
+
| Simply echos the sent bytes back. Returns <math>P_1</math> as <math>R_1</math> and returns <math>P_2</math> as <math>R_2</math>. Mainly useful as
+
|}
+
  
==== 16-bit Integer Example ====
+
The I²C API on the microcontroller is a rather simple little set of commands that rides on I²C. For more information about [http://en.wikipedia.org/wiki/I%C2%B2C I²C we direct you to Wikipedia].
  
Using the "Last time ignition changed (seconds ago)" command example from above.
+
In practice, this is also abstracted by the veeOP REST API, which resides on the Raspberry Pi. The REST API is much more verbose, and provides more flexibility in handling the day-to-day tasks with your veeOP. But, should you see an opportunity to extend it's communication -- it's a simple system. Don't let all the bits and bytes confuse you here, when it comes down to it it's this simple:
  
Note that <math>R_1</math> and <math>R_2</math> represent a 16 bit integer.In the response <math>(1,2)</math> could be represented as bytes in hex as <math>\text{(0x01,0x02)}</math>, which will convert as a little endian into a decimal value of <math>\text{0x102 hex = 258 dec}</math>
+
#Raspberry Pi says "Hi, microcontroller, I want you to do something."
 +
##...And sends it 4 bytes to tell it to do so.
 +
#Microcontroller says "Sure! I did what you want, and here's some info about it."
 +
##...And it sends 4-bytes back to the Raspberry Pi.
  
=== Error Codes ===
+
The veeOP uses the Raspberry Pi as the I²C master, with the arduino-compatible being the slave, at address 4 (0x04) by default (this is configurable in the library.)
 
+
{| class="wikitable"
+
|-
+
! <math>E</math> value !! Code Constant !! Description
+
|-
+
| align="center" | 1 || ERR_BUFFER_OVERFLOW || Too many bytes received before <math>C_e</math>
+
|-
+
| align="center" | 2 || ERR_COMMAND_UNKNOWN || Command is unknown.
+
|-
+
| align="center" | 3 || ERR_COMMAND_INCOMPLETE || Request for data from master received before <math>C_e</math> sent.
+
|}
+
  
 
== Advanced Resources ==
 
== Advanced Resources ==

Latest revision as of 23:39, 23 October 2013

Contents

Re-programming the on-board Arduino Compatible

The veeOP has an on-board arduino compatible, allowing you to customize it to the fullest extent.

The tool included with the downloadable distros here is the InoTool, a command-line Arduino tool. To get into the details, check out their installation guide, and their quick-start guide. But, we'll go over the details here, too.

In the distros provided here in the home directory for the "pi" user, you'll find a directory named 'arduino-vop' which already has an editable version of the code that's already on the microcontroller that you can use to get started!

Location of the "always on" (A-ON) header/jumper on the veeOP. (Shown with jumper off)

Hardware Steps

One important step if you're going to re-program the microcontroller on the veeOP is to use a jumper on the "A-ON header" (short for "always on"). Because the veeOP controls power to the Raspberry Pi, when programming it -- you don't want the veeOP to turn off your Raspberry Pi. When a jumper is on this header, it makes it so that the Raspberry Pi is always in an on state. It's also imperative that you take the jumper off when you're ready to put the veeOP back in your vehicle, as it won't function the way it's intended! ...As you might imagine.

Another option for programming the on-board arduino compatible microcontroller is to use the FTDI header on the board. This allows you to use an FTDI cable (which is basically a USB-to-RS232 adapter) to reprogram the microcontroller. Allowing you to program the micro without using the Raspberry Pi. However, since this also supplies the board with power, it's important that you do not have a micro USB cable attached, too.

Your veeOP should come with jumpers provided. However, if you are to lose them, any standard jumper from a PC will also work. (Or you can wrap a wire around them, in a pinch.)

Installing the necessary tools

If you're not using a veeOP customized distro, you might wish to install the tools from scratch. The examples given here are from Raspbian, but, can be easily applied to most distros.

First install Arduino and the requirements for inotools

sudo apt-get install arduino
sudo apt-get install python-setuptools
sudo apt-get install picocom

Then install ino with easy_setup

sudo easy_install ino

Add the pi user to the tty group

sudo usermod -a -G tty pi

And make a symlink to the tty that inotool / arduino likes...

sudo ln -s /dev/ttyAMA0 /dev/ttyACM0

And make sure it's writable

sudo chmod o+w /dev/ttyAMA0

Download the code!

Main Article: Downloads

If you're using one of the downloadable pre-customized distros, you can look in:

/home/pi/arduino-vop/src/

For the source code. But, if you really want to dig in -- download the code from google code.

It's as simple as placing the vOP folder into your libraries folder in your Arduino's default install directory, to compile it. Check out the provided example sketch as it will guide you into extending the functionality. You can use the provided example sketch to keep the veeOP functionality intact, but! Use the microcontroller for other purposes, and it's extend it's functionality.


Using Arduino Shields with your veeOP

The veeOP is designed to be able to extend it using Arduino Shields. There are shields for all kinds of applications

  • GPSr (global position system recievers)
  • GSM (cell phone service)
  • LCD Displays
  • Wireless (like the ZigBee / XBee)
  • And much, much more.
The veeOP schematics as of v0.300

The Schematics

An extensible platform isn't exactly that without knowing how to really dig deep into the electronics. You can simply use the board "like an attached Arduino-compatible" -- or you can really get in and hack it how you want.

Or! You can even build your own. We've included the schematic to show you that we really do care about the Open Source Hardware (OSHW) movement.

Are you new to Arduino?

Don't sweat it! The Arduino is intended to be an approachable technology, and one that gives a new user a lot of power. And, you'll feel great interacting directly with microcontrollers. The best part is, you can use your veeOP to help you learn.

You can log onto the veeOP connected to your raspberry pi, but, you might want to download the Arduino IDE (integrated development environment) and get started on your workstation (your laptop or desktop computer). You can compile the veeOP code right there to do some initial testing and exploration.

Some resources you might be interested in:

The I²C API

Main Article: I²C API

The I²C API on the microcontroller is a rather simple little set of commands that rides on I²C. For more information about I²C we direct you to Wikipedia.

In practice, this is also abstracted by the veeOP REST API, which resides on the Raspberry Pi. The REST API is much more verbose, and provides more flexibility in handling the day-to-day tasks with your veeOP. But, should you see an opportunity to extend it's communication -- it's a simple system. Don't let all the bits and bytes confuse you here, when it comes down to it it's this simple:

  1. Raspberry Pi says "Hi, microcontroller, I want you to do something."
    1. ...And sends it 4 bytes to tell it to do so.
  2. Microcontroller says "Sure! I did what you want, and here's some info about it."
    1. ...And it sends 4-bytes back to the Raspberry Pi.

The veeOP uses the Raspberry Pi as the I²C master, with the arduino-compatible being the slave, at address 4 (0x04) by default (this is configurable in the library.)

Advanced Resources

Looking at the DTR and Serial RX/TX lines on a HP Logic Analyzer (from 1984!) on the ATMega while developing the veeOP

Other resources that were valuable as the interface between the veeOP board and Raspberry Pi for programming the onboard arduino-compatible: