Electronics and software - for interfacing PC/mac/linux to physical hardware


There are many ways to control / monitor the real world by computer. In this course we will focus on using the Arduino AVR/ARM framework due to its simplicity, robustness, availability, large supporting community and low price. Arduino AVR/ARM microcontroller development kits are assumed to be so simple to use that even musician and artist have shown to manage computer IO via simple C++ (C) programming using this framework.

The standard Arduino way of simplified C++ (C) programming may be limited when it comes to utilizing the low level functionality of the AVR/ARM processors, but by adding simple (one line) register commands to the Arduino C++ code, we have access to all low level functionality and the full speed of the AVR/ARM processor.

To get full debugging possibilies of your programs you may have to leave the Arduino framework, and use Atmels own development tools ARM / AVR but this topic is not covered in this course.

  • Arduino home page
  • Arduino 32 bit ARM based 84Mhz 96 KBytes SRAM DUE, used in this course.
  • Atmel DUE SAM3X8E datasheet used as a basis for register programming

To get Arduino up and go:

  • Download and install the complete software tool package (free)
  • Connect your Arduino card to the computer and make sure it is rcognized as a serial device. Windows: DeviceManager COM/LPD
  • In the arduino window select TOOLS_BOARD and your Arduino card
  • In the arduino window select TOOLS_PORT and your serial port

How to start programming the microcontroller

  • A spearate design / project / program is called a Sketch
  • Arduino have simplified the setup for you in a sketch and given you access to two main functions:
    • void setup() : this code is run once when the microcontroller power up
    • void loop() : this code will be running as an ininite loop
  • Open the included example (sketch): FILE_EXAMPLES_DIGITAL_BlinkWihoutDealy
  • Have a look at the code and press the UPLOAD (arrow) button - the program is loaded into the microcontoller and you should see the LED blinking
  • To make a program running on the microcontroller communicate with the computer - use the SERIAL library - have a look at FILE_EXAMPLES_COMMUNICATION_SERIAL...

Atmel DUE SAM3X8E register programming examples (if you really need to)

  • Fast digital input from pinNr: int enc0 = !!(g_APinDescription[pinNr].pPort -> PIO_PDSR & g_APinDescription[pinNr].ulPin);
  • Fast HIGH digital output on pinNr: g_APinDescription[pinNr].pPort -> PIO_SODR = g_APinDescription[pinNr].ulPin;
  • Fast LOW digital output on pinNr: g_APinDescription[pinNr].pPort -> PIO_CODR = g_APinDescription[pinNr].ulPin;
  • Low level PINOUT overview
Computer / microcontrollers communication software

In many cases computer - AVR/ARM communication is carried out by the use of serial communication over the USB bus. Virtual serial communication may also be the basis for other types of communications, for example different types of wireless communication. Any program able to talk with the (virtual) serial port on the computer may be used to communicate with the AVR/ARM processor.

In this course programs written on the computer may be rather small and to make things simple we use the Java based Processing development environment. The Prosessing development environment is made to offer a maximum simple / fast way of getting small Java programs up and running with access to hardware communication, simplified GUI, and easy to use OpenGL (3D rendering). If you are used to other programming environments, for example Eclipse, you may use it directly or in even in combination with Processing, but be aware of possible practical problems with various versions of libraries that may stop you from accessing the serial port on the computer you are working on.

To start programming in Processing:

  • Download and install it package (free)
  • A spearate project / program is called a Sketch
  • Processing have simplified the setup for you in a sketch and given you access to some main functions:
    • void setup() : this code is run once when the program is started
    • void draw() : this code will be running as an ininite loop
    • A console window is included in the bottom of the main window,println() ...
    • You make a new Java Frame window simply by including, for example size(640, 360); in the draw() function.
    • Compiling and running the program is done by pressing the arrow button in top of the window
  • Run some of the FILE_EXAMPLES
  • To communicate with the Arduino chip - use the SERIAL library, you may start with FILE_EXAMPLES_LIBRARIES_SERIAL_SimpleRead/write
Motor drivers

To directly control electrical motors we need much higher current (voltage) than the microcontroller output can provide. Tips:

  • Be aware of voltage compability between your microcontroller pin output and the driver input.
  • Remember to connect driver ground to microcontroller ground.
  • It may be necessary to use a separate power supply for the motor and the microcontroller (if it is not powered by the USB).
  • Think about power up / down. Will you get into a situation where the driver have no supply power and the driver input pins are sinking more current than the microprocessor can handle? (add serial resistors)
  • Make sure that you dont access the same serial port from both Arduino and Processing at the same time

Used drivers

Dynamixel servos - a fully integrated solution

A very simple way to implement high quality motion is by using the Dynamixel servos from Robotis

  • 32 bit internal ARM processor for communication, configuration and torque/speed/position control
  • Relatively strong: 1.18 - 40Nm
  • Resolution: 1024 - 502.000 steps/turn
  • 300 / 360 deg motion
  • Speed: 60 - 300rpm
  • Backlash: down to 3.8 arcMin (Dynamixel Pro)
  • Very easy to communicate with - serial port communication up to 1Mbit/sec
    • In INF4500 we will communicate directly via Processing (Java) and will not use any library
    • Communication commands (AX12)
  • Downside
    • Expensive:30 up to 2,259 GBP
    • Seems like it is not possible to directly move to a specified angle out of the interval 0-360deg for the 360deg versions
Tutorial / startup