Lego Interactive Interface-A Driven via Arduino

From LVL1
Jump to: navigation, search

Backstory

A number of years ago, a visitor to the LVL1 Hackerspace brought in a box of old Lego items that their father had in storage. The hope was that they would be an interesting project to build something and then use it to demonstrate engineering to children at a science center. The central element was an Interface-A (70455) control unit. The Lego collection also included the Apple II interface card. A working Apple II was not available, so someone suggested driving the "brick" with an arduino.

LBAP brick.jpg

The Build

Opening the "brick"

The first step was to open up the brick. This was done relatively easy by cutting a number of tabs along a seam.

LBAP brick guts.jpg

Now, cutting the brick open was not really necessary since a number of web sites already document this piece of technology. The pin-outs and voltage specs can be found through a series of simple Google searches. Below is a site used for reference.

LEGO - LEGO's first programmable product

From this link one can navigate to a number of others sites with information about this product. Among them is this page with pin-outs.

LEGO® TECHNIC 1093

The information was available and all that was required was a shield and some programming time to get an arduino to drive the brick.

Two Years Later - Some Follow Up

The project simply was forgotten until August 2015. The Director of Legal Evil for LVL1 discovered a LVL1 photo with the brick and decided to close the loop. Based upon the pin-outs and research, he fashioned an arduino UNO shield from a basic prototyping shield.

LBAP Uno Shield.jpg

The shield simply wired arduino pins directly to the pins from the brick (via ribbon cable).

The Brick Output Ports (0-5) were wired to PWM pins. The brick supports PWM signals as a way of regulating voltage to its ports.

Wiring
Arduino Brick Port Id
3 6 0
5 8 1
6 10 2
9 12 3
10 14 4
11 16 5
A0 18 6
A1 20 7


The Brick Input ports were wired to analog pins although testing to see if variable voltages would be sent from brick was not tested.

With the shield, an arduino could drive the brick. Now it was only a matter of writing arduino code.

Code becomes a Library

Code for the arduino would need to turn pins on and off as well as read the analog pins for input. A few #define, analogWrite and analogRead statements would be easy.

#define PORT0_PIN 3
#define PORT1_PIN 5
#define PORT2_PIN 6
#define PORT3_PIN 9
#define PORT4_PIN 10
#define PORT5_PIN 11
#define PORT6_ANALOGPIN 0
#define PORT7_ANALOGPIN 1

But once you write a few #define statements, you feel compelled to write a library. This library doesn't necessarily make things simpler but it can make a novices program requirements less pin detailed.

A library was created. During its creation the usual serial monitor statements were used to debug the system. But instead of stripping it out in the final version, an idea hatched. Instead of waiting for someone to write a program to drive the brick, why not allow it to accept terminal commands from the serial monitor or any other serial device. With this in mind, a serial input scheme was incorporated into the library as a command parser. The library link is below.

Control via Adruino Serial Monitor

#include "LegoTechnic.h"

String ByYourCommand;

LegoTechnic brick; 

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  brick.Port_Initialize();  
}

void loop() 
{
  int Valid = HIGH;
  
  while (Valid == HIGH)
  {
    // put your main code here, to run repeatedly:
    while (Serial.available() == 0)
    {
    }

    ByYourCommand = Serial.readString();    
    brick.Parse_Command(ByYourCommand);
  }
 
}

Instant Brick Driving Desired

With the library written and available, everything was complete. Except that writing a program takes time, terminal commands take syntax and people are sometimes impatient. To deal with these issues, a decision was made to make an interactive brick driver program using the library.

The parts needed:

Parts

LBAP 2560Mega.jpg

LBAP LCD Shield.jpg

LBAP TFT LCD.jpg

LBAP Cable Connector.jpg

Arduino 2560 Mega

TFT LCD to 2560 Mega Shield

3.2" TFT LCD with Touch Screen and SD Card reader

Connector to brick with two 10K pull-down resistors


Wiring
Arduino Sainsmart Shield Brick Port
Pin LCD Touch Screen SD Card Pin Id
2 to 6 X
8 6 0
9 8 1
10 10 2
11 12 3
12 14 4
13 16 5
A0 18 6
A1 20 7
22 to 41 X
50 to 53 X

Code

Libraries

#include <tinyFAT.h>
#include <UTFT.h>
#include <UTFT_tinyFAT.h>
#include <UTouch.h>

Libraries Downloaded from: Rinky-Dink Electronics

Background Image

LBAP LEGOPIC.png

Copy this file and use the ImageConverter565.exe program supplied in the UTFT libraries identified above.

Be sure to convert it to RAW type and name it LEGOPIC.RAW and include it on the SD Card.

Touch Screen Calibration Quirk

While programming, I had a problem with the touch screen not staying calibrated. After much searching I found a forum posting:

Adding a delayMicroseconds command.

This solved my problem.


The result is:

LBAP Interactive Unit.jpg

Which does this:

LBAP Screen Lit.jpg

The small LEDs on the brick light up when the ports are active. The interactive LCD display shows a brick which also shows the LEDs lit when active.

The slider scales have a value of [0..10]. The scale generates a PWM value of 25.5 times the scale value.

Video Proof

Arduino Uno Version running from Terminal Serial Input

Lego Interface-A Arduino Interactive Input Demo

Lego Interactive Interface-A Arduino Light Demo

Lego Interactive Interface-A Arduino Motor Demo

Lego Interface-A Arduino Screen Demo showing details for sliders

Lego Interface-A Arduino Screen Demo showing details for inputs

A Little More Side Information

The visitor to LVL1, bringing the Lego brick, eventually joined the hackerspace. She then became President of the space a few years later.

The project was languishing in the incomplete column until another member brought in an Apple II. The thought of just plugging the brick interface card into the Apple was short lived. The Apple II never booted properly. After several people tried to get the machine working, the prevailing feeling was that I could get the interactive brick working before the others could boot the Apple II. The Apple II never booted.