Difference between revisions of "Lego Interactive Interface-A Driven via Arduino"

From LVL1
Jump to navigation Jump to search
 
(30 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
[[File:LBAP_brick.jpg]]
 
[[File:LBAP_brick.jpg]]
  
=== First Step ===
+
=== The Build ===
 
==== Opening the "brick" ====
 
==== 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.
 
The first step was to open up the brick.  This was done relatively easy by cutting a number of tabs along a seam.
Line 134: Line 134:
 
The parts needed:
 
The parts needed:
  
 +
{| class="wikitable"
 +
|+Parts
 +
|-
 +
|
 
[[File:LBAP_2560Mega.jpg]]
 
[[File:LBAP_2560Mega.jpg]]
 +
|
 +
[[File:LBAP_LCD_Shield.jpg]]
 +
|
 +
[[File:LBAP_TFT_LCD.jpg]]
 +
|
 +
[[File:LBAP_Cable_Connector.jpg]]
 +
|-
 +
|
 
Arduino 2560 Mega
 
Arduino 2560 Mega
 
+
|
 
 
[[File:LBAP_LCD_Shield.jpg]]
 
 
TFT LCD to 2560 Mega Shield
 
TFT LCD to 2560 Mega Shield
 
+
|
[[File:LBAP_TFT_LCD.jpg]]
 
 
3.2" TFT LCD with Touch Screen and SD Card reader
 
3.2" TFT LCD with Touch Screen and SD Card reader
 +
|
 +
Connector to brick with two 10K pull-down resistors
 +
|-
 +
|}
  
[[File:LBAP_Cable_Connector.jpg]]
 
Connector to brick with two 10K pull-down resistors
 
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|+Wiring
 
|+Wiring
 
|-
 
|-
|
+
|Arduino
 
|colspan="3"|Sainsmart Shield
 
|colspan="3"|Sainsmart Shield
|
+
|Brick
|
+
|Port
 
|-
 
|-
|Arduino
+
|Pin
 
|LCD
 
|LCD
 
|Touch Screen
 
|Touch Screen
 
|SD Card
 
|SD Card
|Brick
+
|Pin
|Port Id
+
|Id
|-
 
|2
 
|
 
|X
 
|
 
|
 
|
 
 
|-
 
|-
|3
+
|2 to 6
|
 
|X
 
|
 
|
 
|
 
|-
 
|4
 
|
 
|X
 
|
 
|
 
|
 
|-
 
|5
 
|
 
|X
 
|
 
|
 
|
 
|-
 
|6
 
 
|
 
|
 
|X
 
|X
Line 253: Line 236:
 
|7
 
|7
 
|-
 
|-
|22
+
|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
 
|X
 
|
 
|
Line 337: Line 243:
 
|
 
|
 
|-
 
|-
|34
+
|50 to 53
|X
 
|
 
|
 
|
 
|
 
|-
 
|35
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|36
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|37
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|38
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|39
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|40
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|41
 
|X
 
|
 
|
 
|
 
|
 
|-
 
|50
 
|
 
|
 
|X
 
|
 
|
 
|-
 
|51
 
|
 
|
 
|X
 
|
 
|
 
|-
 
|52
 
|
 
|
 
|X
 
|
 
|
 
|-
 
|53
 
 
|
 
|
 
|
 
|
Line 423: Line 252:
 
|}
 
|}
  
 +
=== Code ===
 +
Libraries
 +
''
 +
#include <tinyFAT.h>
 +
#include <UTFT.h>
 +
#include <UTFT_tinyFAT.h>
 +
#include <UTouch.h>
 +
''
 +
Libraries Downloaded from:
 +
[http://www.rinkydinkelectronics.com/library.php Rinky-Dink Electronics]
 +
 +
* [[Lego Interactive Brick Program]]
 +
 +
Background Image
 +
 +
[[File: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:
 +
 +
[http://forum.arduino.cc/index.php?topic=147762.0 Adding a delayMicroseconds command].
 +
 +
This solved my problem.
 +
 +
 +
The result is:
 +
 +
[[File:LBAP_Interactive_Unit.jpg]]
 +
 +
Which does this:
 +
 +
[[File: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 ===
 +
[https://www.youtube.com/watch?feature=player_detailpage&v=BzYoxeiuGic Arduino Uno Version running from Terminal Serial Input]
 +
 +
[https://www.youtube.com/watch?feature=player_detailpage&v=PcnFnsw_BFI Lego Interface-A Arduino Interactive Input Demo]
 +
 +
[https://www.youtube.com/watch?feature=player_detailpage&v=WV70fsvlqf8 Lego Interactive Interface-A Arduino Light Demo]
 +
 +
[https://www.youtube.com/watch?feature=player_detailpage&v=FwkXpQSl2sU Lego Interactive Interface-A Arduino Motor Demo]
 +
 +
[https://www.youtube.com/watch?v=QMZSc11cPR8&feature=player_detailpage Lego Interface-A Arduino Screen Demo showing details for sliders]
 +
 +
[https://www.youtube.com/watch?v=yz8cCkgc19g&feature=player_detailpage 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.
  
Wiring
+
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.

Latest revision as of 01:43, 3 April 2016

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.