Lego Interactive Interface-A Driven via Arduino

From LVL1
Jump to navigation Jump to 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

First Step

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
Sainsmart Shield
Arduino LCD Touch Screen SD Card Brick Port Id
2 X
3 X
4 X
5 X
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
23 X
24 X
25 X
26 X
27 X
28 X
29 X
30 X
31 X
32 X
33 X
34 X
35 X
36 X
37 X
38 X
39 X
40 X
41 X
50 X
51 X
52 X
53 X

Code

The result is:

LBAP Interactive Unit.jpg

Which does this:

LBAP Screen Lit.jpg