Tag Archives: pinout

Lego Control Lab Interface – Serial Cable Woes

Lego Control Lab Interface – Serial Cable Woes

If you have a Lego Dacta Interface B (AKA Control Lab or 9751) but don’t have the original cable, you might have trouble talking to it. The reason for this is that RX and TX are wired backwards compared to what you’d normally expect. Even more confusing, the gender of the RS232 port on the interface is female, which isn’t normally the case for this wiring.

Getting the Right Cable

Buying an Original Cable

If you’re buying to connect to a standard RS232, 9 pin port on a PC, you’ll want Lego part number 9768-1.

If you’re buying to connect to a vintage Mac with RS422 ports, you will want Lego part 9769-1.

Lastly, if you’re buying for an Acorn Archimedes computer, you’ll likely want Lego part 9768-1 (the PC part).

Making a Cable

If you’re making your own cable, you’ll need to keep in mind that the pinout of the port on the interface is described as follows in the manual :

The connector on the back panel is male and you only need the three pins shown to be connected for everything to work.

Using a Null Modem Adapter

If you’re using a standard serial cable instead of one wired for the Control Lab interface, or using a USB to RS233 adapter, you’re going to need a null modem adapter, but one with a male plug on one end and a female plug on the other.

Making Your Own Adapter

I made my own using two ribbon cable RS232 9 pin D Sub connectors from eBay. It is a little fiddly, but a fairly cheap solution. As mentioned above, the interface doesn’t actually use most of the pins (such as flow control) so you only actually need three wires.

In your adapter, connect…

  • Pin 5 to Pin 5
  • Pin 2 to Pin 3
  • Pin 3 to Pin 2

You should end up with something that looks like the following…

Buying an Adapter

Most adapters look like the following, but it can be tricky identifying what is a null modem adapter and what is just a pass through or gender changer, so take care. Lately these adapters have been more expensive than I would expect.

You must buy one that is wired as a null modem adapter, and has one male and one female connector.

Alternatively, there are adapter cables available, which is what I most recently purchased.

Again, you must ensure that the cable is a null modem adapter, and that it has one male and one female end.

Lego Power Functions Connector Pinout

Lego Power Functions Connector Pinout

The Lego Power Functions electrical system replaced the older 9v system used on the Interface B (AKA Control Lab or 9751) and RCX, for connecting motors and in a small number of instances, sensors. The new connector retained the nominally 9v rating, but was no longer possible to rotate to change polarity. To solve this, reversing switches are available, and the most common battery box has a three position switch with both polarities as well as off.

The main advantage of the Power Functions connectors is that they carry an unswitch 9v power bus as well as the traditional reversable control signals. The permanent 9V is used to power the IR receiver, and is always passed through an IR receiver even when outputs are off. I suspect sensors also used the permanent 9v to power their circuitry without interruption.

This is a significant advantage over the older 9v system where sensors used to have to harvest and store power in a capacitor with the input port being momentarily switched to a different mode to recharge the capacitor and keep the sensor powered.

The Pinout

The Power Functions pinout is as follows.

It can be seen that the outer two pins have fixed voltages regardless of the polarity of the orange switch, while the pins labelled A and B (conventionally called C1 and C2, but I was unsure which was which) are swapped depending on whether the orange switch is in position 1 or position 2.

With the connector oriented with the two knobbles / studs at the top, numbering contacts from left to right, 1 is always ground, 4 is always 9v, and 2 & 3 are switchable so that one is 9v (or a reduced power signal when using an analogue controller) and the other 0v. When powered, but with no direction signal (for example plugged into a powered IR receiver, but with no buttons pressed on the basic remote), both 2 & 3 are at 0v.

With this battery box, the third central position of the orange switch completely turns off the power to all pins.

9v to Power Functions Adapter Cables

Warning! When making adapters between Power Functions and 9v, you must not connect the outer two contacts on the Power Functions end. This could/will result in a short.

ReadyAVR-64 – A board without documentation

I recently purchased a Atmel ATmega128 breaout board designed by LogiFind, called the ReadyAVR-64. The company seems to be imitating Mikroelektronika with their naming conventions and produce intermediately priced educational boards. They provide some examples and software, oriented around Windows as a host platform for most of their boards. I have a couple of examples for there wares, from the giant “EasyAVR128” to the more basic “ReadyAVR-28” (which I plan to swap a ATmega328 into – they do a board with one pre-installed, but it costs more). Currently, the documentation download link on their website for their ReadyAVR-64 board seems to be broken.

Despite being a blue PCB in all adverts etc. the board I received in the post was green. I had some minor postage issues, with my package been returned to sender for an unknown reason, but the seller was very honest and quick responding and the item arrived by airmail a few days after I reported my concerns.

ReadyAVR-64
ReadyAVR-64

Upon getting my board in the post, the first thing I did was swap out the crystal oscillator for a turned pin socket. There are two reasons for this – firstly the pre-installed crystal was an odd speed (7.3728mhz – I prefer 16mhz), and secondly, a socket means I can change the speed as I wish. Making this change requires your usual component desoldering – I used some flux, an iron and some solderwick – once the crystal was out of the board I finished clearing the holes with a solder sucker. Break off a 3 long piece of turned pin female header and solder it in. You don’t even need to remove the middle pin as there is an unconnected hole already on the PCB.

The next thing I did was replace the pre-installed bootloader with a variant of optiboot. I can’t remember exactly where I got it, but the hex file is here. This USB bootloader uses the PE1, PE0 serial port and so I had to switch the jumpers on JP2 for it to work. Loading in the new bootloader is done through the ISP6 or ISP10 ports. I used my STK500 with AVRdude, as I’ve had some difficulties programming AVR128s with my usbasp in the past. It should be possible to follow “Arduino as ISP” instructions to reflash the board. I wont go into depth here. At some point I’ll write a guide to reflashing bootloaders onto AVRs, but there are already a lot of guides out there. For reference, I used the following two AVRdude commands to setup the bootloader and fuses on my board :

avrdude -p m128 -c STK500 -P /dev/ttyUSB0 -u -U flash:w:optiboot_atmega128.hex
avrdude -c STK500 -p m128 -P /dev/ttyUSB0 -U lfuse:w:0xff:m -U hfuse:w:0xc6:m -U efuse:w:0xff:m

At this point, if you wish to program the board using the Arduino IDE, you will need to install MegaCore. This adds extra microcontrollers, including the ATmega128 to the boards menu in the Arduino IDE. Installation is described in the “How to Install” section of the linked github page.

As I couldn’t find any documentation on the board due to the broken download link, I experimented and followed traces on the board until I worked out the following. Note that the LEDs are Active Low (setting the connected pin on the microcontroller to High turns them off).

  • LED0 = Arduino Pin 28 (PC0)
  • LED1 = Arduino Pin 29 (PC1)
  • LED2 = Arduino Pin 30 (PC2)
  • LED3 = Arduino Pin 31 (PC3)
  • BOOT = Arduino Pin 37 (PA7)

The Joystick is connected to Port B, but required the chip’s internal pullups to be enabled before it works correctly. One way this can be done in the Arduino IDE is by using digitalWrite to set the pin HIGH after having set it to be an input. Connections are as follows :

  • Joystick Up = Arduino Pin 9 (PB1)
  • Joystick Down = Arduino Pin 11 (PB3)
  • Joystick Left = Arduino Pin 10 (PB2)
  • Joystick Right = Arduino Pin 8 (PB0)
  • Joystick Click = Arduino Pin 12 (PB4)

Note that when you trigger two options at once, say for up and right, or left and click, all 5 pins trigger. The joystick connections are also Active Low, meaning the input goes low when the joystick is triggered.

The following Arduino example shows the functionality of both the LEDs and the joystick.

int LEDS[] = {28,29,30,31,37};
int Inputs[] = {8,9,10,11,12};

void setup() {
  for(int x = 0; x<5; x++){
    pinMode(LEDS[x], OUTPUT);
    digitalWrite(LEDS[x], HIGH);
  }
  for(int x = 0; x<5; x++){
    pinMode(Inputs[x], INPUT);
    digitalWrite(Inputs[x], HIGH); // enable pullup
  }

  int LED = 0;
  while(LED<5){
    pinMode(LEDS[LED%5], OUTPUT);
    digitalWrite(LEDS[LED%5], LOW);
    delay(250);
    digitalWrite(LEDS[LED%5], HIGH);
    delay(250);

    LED++;
  }
}

void loop() {
  for(int x = 0; x<5; x++){
    if(digitalRead(Inputs[x])==LOW){
      digitalWrite(LEDS[x], LOW);
    }else{
      digitalWrite(LEDS[x], HIGH);
    }
  }
}