Learn Arduino With the Linkbot

From LinkbotLabs
Jump to: navigation, search

Note: The contents of this page are in active development.

Getting Started

To get your Linkbot talking with an Arduino, you will need the following items:

  • A Linkbot
  • An Arduino
  • A Linkbot Arduino shield
  • A short length of standard telephone line, preferably less than 6 inches in length. Longer lengths may be too prone to interference and signal degradation.
  • The Arduino development environment

You will also need at least basic knowledge of how to use the Arduino development environment to compile and load programs onto your Arduino.

The Arduino Firmware

Getting the Firmware

First, you will need to install the Linkbot Arduino driver program onto your Arduino. The Arduino sketch can be found here: [[1]] . There is a button on the lower right of the page called "Download ZIP". Click on that button to download the latest version of the Arduino Linkbot firmware. Unzip the contents of the zipfile into your Arduino sketchbook directory in a new subdirectory called LinkbotArduinoShield. Your directory structure should look something like:

sketchbook/LinkbotArduinoShield/LinkPod.ino

Installing the Firmware

Open the LinkbotArduinoShield sketch in your Arduino IDE by clicking on File->Sketchbook->LinkbotArduinoShield. Next, click on the "Verify" button to compile the code. Finally, plug in your Arduino and click on the "Upload" button, the same as if you were uploading your own code onto the Arduino.

The Python Environment and Package

Follow the instructions at [[2]] to install Python3 and PyLinkbot.

Documentation for PyLinkbot can be found at [[3]] . In the "Linkbot" class, there are a set of functions with the keyword "Breakout", such as "setBreakoutDigitalPin()". These functions get and set pin values on the Arduino board.

Setting up your Robot

To run demo programs, connect your Arduino to the Linkbot Arduino Shield, and connect the Linkbot Arduino Shield to the Linkbot with your telephone cable. Now, you can call Linkbot Python functions that will get/set settings on the Arduino.

Here is a simple Python program which tests a set of peripherals on the Arduino. This test runs diagnostics on a shield with the following digital pin connections:

  • 2 <-> 4
  • 7 <-> 8
  • 12 <-> 13
#!/usr/bin/env python3
 
import linkbot
import time
import math
 
def main():
    l = linkbot.ArduinoLinkbot()
 
    # Test the six ADC's by giving them six slightly offset sinusoidal signals
    for pin in [3, 5, 6, 9, 10, 11]:
        l.pinMode(pin, linkbot.ArduinoLinkbot.PinMode.output)
 
    t = 0
    analogPins = (3, 5, 6, 9, 10, 11)
    while t < 5:
        for i in range(6):
            l.analogWrite(analogPins[i], int(127*math.sin(2*t + i*2/math.pi))+127)
        #time.sleep(0.1)
        t += 0.2
 
    print('AnalogWrite passed')
 
    print('Getting analog read values...')
    for pin in range(6):
        print(l.analogRead(pin))
 
    outputPins = [2, 7, 12]
    inputPins = [4, 8, 13]
    for ipin in inputPins:
        l.pinMode(ipin, linkbot.ArduinoLinkbot.PinMode.input)
    for opin in outputPins:
        l.pinMode(opin, linkbot.ArduinoLinkbot.PinMode.output)
 
    # Test values
    for opin,ipin in zip(outputPins, inputPins):
        l.digitalWrite(opin, 0)
        assert(l.digitalRead(ipin) == 0)
        l.digitalWrite(opin, 1)
        assert(l.digitalRead(ipin) == 1)
        l.digitalWrite(opin, 0)
        assert(l.digitalRead(ipin) == 0)
 
    # Swap directions
    inputPins = [2, 7]
    outputPins = [4, 8]
    for ipin in inputPins:
        l.pinMode(ipin, linkbot.ArduinoLinkbot.PinMode.input)
    for opin in outputPins:
        l.pinMode(opin, linkbot.ArduinoLinkbot.PinMode.output)
 
    # Test values
    for opin,ipin in zip(outputPins, inputPins):
        l.digitalWrite(opin, 0)
        assert(l.digitalRead(ipin) == 0)
        l.digitalWrite(opin, 1)
        assert(l.digitalRead(ipin) == 1)
        l.digitalWrite(opin, 0)
        assert(l.digitalRead(ipin) == 0)
 
    print('Digital IO passed.')
 
 
if __name__ == '__main__':
    main()