Toastie

The Mindful Pub - A Discussion Thread on 8bit Computers and LEGO

Recommended Posts

Dear All,

after I was sleeping two days over opening a thread on "an idea", I am just doing it:

This thread is intended to be a (Mindful) Pub to discuss ideas/projects/wild thinking/just memories/the good ol'days/8 bit/crazy16bit/express printers printing NCC1701/PDP10/11 ... and mostly 8bit computers - controlling LEGO 4.5V/9V/12V/RC/PF/ and yes: PUp devices. Whatever comes to mind.

8bit computers are OLD. Very old. As in: You may think the chemist down the road is old, but that's just peanuts to the age of 8bit computers. We are talking true retro here. C64, Dragon 32, Oric-1, BBC Micro, ZX's, Amstrad CPCs and so on and so forth.

I don't know why, but it just never "left" me. When I was 23 years old, my wife (I was studying - well - chemistry) allowed me to buy a Sinclair ZX Spectrum. And it all began. Games never ever interested me (other than cracking the "copy protection" using the disassembled machine code) - it was the hardware. And changing/adding things. Controlling periphery. I graduated with a degree in chemistry though - and all figured out is "true homebrew".

It was the world of TTL, CMOS, and ECL ... and the world of 16k x 1bit chips being expensive. Just imagine: The 16k ZX Spectrum I had was ready to be upgraded to 48k. There was also a factory version of the 48k Spectrum. To make that one as cheap as possible, Sinclair used defective 64k x 1bit chips: These chips are organized in 2 banks of 32k. Upon final testing manufacturers as TI and others sold chips with one defective bank to other companies as "32k" chips. Can you believe that? Yes of course. It makes total sense! But today? Never ever. 

Now, the idea for this thread is: Can we control ancient or even current LEGO electronics with 8bit computers?

I am working on: Let a ZX Spectrum talk to an RCX brick. Why? Because. Nothing else. It has remotely to do with LEGO bricks being around since the 1960s - and still clutching - and LEGO electronics officially appearing and disappearing even faster than fashion trends do. You may think: So what. He has the ZX IF1 featuring an RS232 port. Well. The ZX speaks (hardwired = bolted in) 1 start, 8 data, no parity, 1 stop bit. The RCX speaks (again: Hardwired into the UART) 1 start, 8 data, odd parity, 1 stop bit (Challenge 1: Parity change). And then: The LEGO IR serial tower cranks out and sucks in bytes with no protocol at blistering 2400 Baud. The ZX IF1 can't handle that: After receiving 1 byte is pulls down the CTS -> RTS line - allowing one more byte and then think about how to store that (Challenge 2: HW protocol - the tower is totally dumb). Possible solution: Arduino as translator. We'll see.  

This thread will not be heavily populated, I believe. And it will take time. We are talking 1980s.

There are some folks here on EB though who may have something to say ... or maybe not.

  • @dr_spock suggested the title of this thread
  • @Duq repairs old washing machines
  • @zephyr1934 knows how to print NCC1701 on endless paper
  • @UltraViolet likes when an EB topic is derailed because of 8bit computing ...

This is it. Don't expect a viral thread. I am old. The cool thing though is: Posting here after ... let's say a year or so of silence will not get the moderators mad, as it is designed to be a repository :pir-huzzah2:

All the best,
Thorsten

P.S.: Just for those who were born 2000(+) : k stands for kilo:pir_laugh2:. A 16k x 1 RAM is a chip that holds 16384 bit (0/1). You needed 8 to get 16kByte RAM. Today, a 16G x 8bit DDR3 DIMM module, which holds about 1 million times more bytes, sells for about the same price as 16kByte cost in 1982. In other words: 1 bit then was 1.000.000 times more expensive than 1 bit is now, 40 years later.  

Edited by Toastie

Share this post


Link to post
Share on other sites
Just now, Toastie said:

@JintaiZ

Very good idea. Title now better?

Thanks a lot!

Thorsten

Absolutely! :thumbup:

Share this post


Link to post
Share on other sites

So ... just learned that a retro computer work/place/space makes it to the front page! (it is an Apple, isn't it?) - This is soo so cool :wub:

Well, here we go - this is even beamed back in time a little further than Apple 2E ...

As I am working on a ZX Spectrum talking to the LEGO serial tower (with reply ... sigh(!)) - it seemed to be appropriate to "prepare". And as said elsewhere, I got both, my ZX81 and my ZX Spectrum from 1983/85 back to work. Before diving into old electronics and old and current programming - I prepared myself creating the right environment to work on this (during endless nights :pir_laugh2:):

 

zx81_workplace.jpg

There is the Zeddie on the left, with the 16k MonsterRAMPack, and nifty 9V power supply. On the right front is the small scale LEGO version - as it was, last millennium: The Zeddie, the cassette player for true mass storage, power supply, couple of mass storage cassettes, CRT (that one I got from my mum - was a red "Colani type" CRT - no edges, just curves:sweet:. For me, it was quite the challenge to build that one with bricks, see below.

Back right is my laptop showing a Stud.io render of the scene. Back left is the "CRT" = LED TV I am using as ZX display. This needs some modding to the ZX81 video output, as around 1980, VHF/UHF was the standard. Today, hardly any TV set knows anything about RF - at minimum they want composite video. In front of the TV is a good quality audio capturing device, used for loading/saving Zeddie programs from my laptop (almost "glitchless" when using Audacity).

Credits for the LEGO models: The Zeddie LEGO model is based on Steven Reid's design: https://www.reids4fun.com/. I just replaced the round 1x1 tiles with square ones. And made some space for the cables. Also resized the RAM pack a bit to fit the scale and moved it a little to the right - as in the "original". The cassettes - I can't find the reference anymore. Merde. It is >not< my design. The CRT is; however, the front screen idea is not. This is from http://www.fubiz.net/2014/04/30/retro-technology-lego-kits/retro-technology-lego-kits3/. I just changed the direction of the curved slopes and the scale. BTW: The Zeddie never produced a decent picture back then with the RF modulator - so this is why the screen is not grey/white only. I believe the cassette player is also my design - at this scale. The lid actually opens, and you can insert one of the cassettes - see LDraw MPD file.

The LDraw MPD file is here: https://brickshelf.com/cgi-bin/gallery.cgi?f=582185. This BrickShelf folder is not moderated yet though.

I believe this is it. As my photography is crappy, here are some Stud.io renders.

zx81_workspace_s.jpg

(Shadows below the devices because I am too dumb to get the wires bent in a way they don't penetrate through the floor - and Stud.io does adjust the floor location to the lowest part - as far as I know.

zx81_-_cassetteplayer.jpg

The cassette player ... right now it plays a program to be loaded into the ZX81 - may take several times though!

zx81_-_crtback.jpg

The "Colani type" CRT I had back then, back view. Black = power, yellow = antenna in ...

And here is the Zeddie:

zx81_-_zx81.jpg

The Zeddie with RAM pack.

Sorry for just the renders; but as said: I am not good with photography.

All the best,
Thorsten

Edited by Toastie

Share this post


Link to post
Share on other sites

Wonderful!
Awesome!

Both your idea and art products are interesting to me.


Dear, I agree with your idea. The old fashion computer has it's value. It is a fundamental tool for children learning computer knowledge, such as binary and Ascii.

Besides, when quantum mechanics computers are coming, old fashion computer will give a transparent compare between classic computers and quantum mechanics computers.

What’s incredible is, I have a similar experience with you. Learning and working in both the electricity and the chemical industry.

Just do as you wish! 

You are not old. You have a young spirit and positive thought.

You will have great success!

Share this post


Link to post
Share on other sites

Nice build. I remember the ZX81. Do your cassette tapes still work?  I may still have a Z80 processor somewhere.

I was thinking the thread would be more like the Technic Pub where it is not  too LEGO-centric and more on the off-topic side of shifting bits or shooting the breeze.

Back in the days, I wrote some assembler to control fluid flow with an 8088 processor.  I never did like the Intel segmented memory addressing.  Coming from the MOS 6502 and Motorola 68000, the Intel drove me nuts.  Making ASCII art on a IBM System/34's 5211 band printer was more entertaining.  :classic:

 

 

Share this post


Link to post
Share on other sites

@camellia  Thank you very much for your (very) kind words. I really agree with your assessment on 8bit computing and learning how computers work. Absolutely. It even works with the e.g. the 8/16 bit microchip PICs - and of course all small scale RIS brains from other vendors - at least for me. On the other hand, when I do program Arduino's and derivatives it is more or less a miracle to me, what they a) have on board and b) what they can accomplish. Usually I do import libraries without knowing how they work and copy code from the various forums etc. out there and stitch all that together with a couple of code lines (sometimes even a few more). And: When some programmer would look at my "C++" Arduino code, he or she'd say: "This isn't even close to the beauty of C++ - this is crappy BASIC style" :pir-blush:.

@dr_spock Oh - this is intended to be all about other things than LEGO. As I said: My goal is to have my Speccy talk to the LEGO IR serial tower - which is currently far, far away ... at least for me. I am working on it :moar:.

The LEGO stuff was just for setting the stage - my workspace that is. As I haven't figured out a decent way of building a Speccy at this scale that suits me, I was going with the Zeddie.

Back on topic:

I just ordered three tiny SP3232 based RS232 communications boards to be connected to an UnoR3. Three because chances are that I'll blow up one or two things. These boards have 4 lines (lets call them RxD/TxD/RTS/CTS) at RS232 voltage level available. The IF1 interface of my Speccy wants CTS and RTS hardware handshake - or it remains silent. In addition, the serial input buffer of the ZX IF1 is 2 bytes. So it pulls down CTS to signal stop it, I have to move these bytes somewhere else ... and when done, 2 more bytes are allowed to flood the buffer ... if I get that to work, I will of course build an old school MAX232 based little breadboard circuit. Looks much better!

Ah - and found an Arduino library for other than generating plain vanilla 1 start, 8 data, no parity, 1 stop bit frames! There are not that many out there I believe. And this is certainly because these C++ folks simply program their own code to accomplish 2400 baud, 1 start, 8 data, ODD parity:ugh:, 1 stop bit communication. On my laptop, HTerm hooked up via USB/Serial converter (just using a 3-wire RxD/TxD connection) to the tower can make the RCX beep. OK, and all the other things. Making it beep is good feedback though. It sounds like the RCX is happy:pir-cry_happy:.

Best wishes
Thorsten

P.S.: Just looked up what "shooting the breeze" means:laugh:. Yes. This is exactly it!

Edited by Toastie

Share this post


Link to post
Share on other sites

Crappy BASIC style? I taught myself to program in BASIC.  My code may read like a bad romance novel but they seem to work out in the end.  :laugh:

Older school would be 1488 and 1489 level converters for RS232.  I may have to build a serial IR tower one day when my LUG can meet again. One of my members has a SCOUT for me.  Hopefully it won't be too hard to fix and get working.

rs232.jpg

Are you writing your own serial communication routines for the ZX81?

 

Share this post


Link to post
Share on other sites

Swwweeet! 1488s ... oh my. Beautiful.

Yeah, I know - the cool programmers in my group who are literally talking to each other in C++ (and of course JAVA - and of course Python) always just shrug, when I talk about my more than 10000 lines of VB6 (yes, VB6) code - no dot, no net, no express, no studio - just VB6:pir-huzzah2:). The thing though is: It works. It controls RCX trains, SCOUT switch controllers talking to MicroSCOUTS via VLL links, NXTs and recently yes, also PUp hubs. The latter is a bit shaky as I have no clue what I am doing - got the ActiveX control from n_software for free, no manual other than an example program, so no questions asked! But it all works.  

(Ha, for the VLL SCOUT - MicroSCOUT link I used the optical fibers from one of our labs dye lasers. Those are now in laser heaven, but the 6 m long VIS light fibers were too much for me, I saved them. LambdaPhysik (company is also gone) found it cool in the 1990s to control the electronics in their dye lasers with optical fibers instead of RS232 or IEEE-488 (HP-IB or GPIB) cables. Well these lasers were pumped with serious XeCl/ArF excimer lasers - and you can shield with cm thick whatever material - when 32 kV stored in a capacitor bank of some meters in size are discharged within 10 ns, this generates some electronic noise :cannon:)

Let me know about how it goes with the SCOUT, I took several of them apart to fix them. I love them. Space for 396 bytes for LEGO byte code is all RAM you get! So programming them is total fun. Actually Dave Baum changed the NQC code, when I asked him (that was very generous): For jumps, he originally implemented always long jumps. That costs you three bytes more than compared to a short jump! For the RCX memory monster that is no issue, but when left alone with 396 bytes of RAM, it is something.

Also, for the LEGO tower replacement - there is really cool Arduino code to generate the 38kHz modulation frequency. I found this here:

void setup() {
  pinMode (11, OUTPUT);               // Pin 11: Timer 2 "A" output: OC2A 
  // set up Timer 2
  TCCR2A = _BV (COM2A0) | _BV(WGM21); // CTC, toggle OC2A on Compare Match
  TCCR2B = _BV (CS20);                // No prescaler
  OCR2A =  208;                       // Original value: 209. 
                                      // Original comment: "compare A register value (210 * clock speed)
                                      //  = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095"
                                      // This results in 37.83 kHz on the Uno R3 clone board
                                      // Changed to 208 - this results in 38.01 kHz
}

And this is it! This makes pin 11 oscillate at 38kHz, 50% duty cycle. Entirely hardware driven! (Comments following the last line are from me to remember). This is really cool. And works - the RCX beep was generated using this setup. However, just turning an IR LED on and off with one leg connected to pin 11 and the other to lets say pin 10 configured as output did not work - ther was always residual IR light flooding the scene. Oh well, one NOR gate of 74LS02 takes care of that issue.

Well I am using the ZX Spectrum with Interface1 from my good ol'days, not the ZX81. The Spectrum IF1 one has serial communication routines built is - but with HW handshake and only 1/8/N/1 frames.

So I will use an Arduino for translation purposes. Well, that is the plan. Who knows ...

Best wishes
Thorsten
 

Share this post


Link to post
Share on other sites

Good evening,

well, I did not expect that this would work out that swiftly ... :pir-huzzah2:

So this setup from 2021

zx_spectrum_arduino_test_setup_1.jpg

with this code on the Speccy from 1985

zx_spectrum_test_code_1.jpg

and this code on the Arduino Uno R3 clone

#include <CustomSoftwareSerial.h>

// Declare CustomSoftSerial ports 
CustomSoftwareSerial* customSerial_2400;
CustomSoftwareSerial* customSerial_9600;

void setup() {
  // Init 38kHz pulse train on pin 11 ------------------------------------------------------------------------
  pinMode (11, OUTPUT);               // Pin 11: Timer 2 "A" output: OC2A 
  // set up Timer 2
  TCCR2A = _BV (COM2A0) | _BV(WGM21); // CTC, toggle OC2A on Compare Match
  TCCR2B = _BV (CS20);                // No prescaler
  OCR2A =  208;                       // Original value: 209. 
                                      // Original comment: "compare A register value (210 * clock speed)
                                      //  = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095"
                                      // This results in 37.83 kHz on the Uno R3 clone board
                                      // Changed to 208 - this results in 38.01 kHz
                                      
  //Init Uno onboard serial (pins 0+1) -----------------------------------------------------------------------
  Serial.begin(9600);                 // Just to sniff when necessary ...

  // Init CustomSoftserial ports -----------------------------------------------------------------------------
  // By default (SS), the last initialized port listens!
  customSerial_2400 = new CustomSoftwareSerial(9, 10);   // RX, TX
  customSerial_2400->begin(2400, CSERIAL_8O1);           // Baud rate: 2400, configuration: CSERIAL_8O1
  customSerial_9600 = new CustomSoftwareSerial(2, 3);    // RX, TX
  customSerial_9600->begin(9600, CSERIAL_8N1);           // Baud rate: 9600, configuration: CSERIAL_8N1

  // Init IO pins --------------------------------------------------------------------------------------------
  pinMode (4, OUTPUT);                // from Arduino 4 to RS232 8 T2o (CTS) and from there to ZX 4 CTS
  digitalWrite(4, HIGH);              // LOW: ZX 4 CTS +V enables sending from ZX. HIGH: Sendinfg disabled 
  pinMode (5, INPUT);                 // from ZX 5 RTS to RS232 7 R2i (RTS) and from there to Arduino 5

} // end setup ---------------------------------------------------------------------------------------------------                                                       

void loop() {
  if (customSerial_9600->available()){                   // ZX IF1 9600/1/8/N/1 data received 
    customSerial_2400->write(customSerial_9600->read()); // Copy to 38kHz 2400/1/8/O/1 modulated output 
  }
}

makes the RCX 1.0 Unit 092547 from 1999 beep every time you run the program on the Speccy :sweet:

Line 900 on the Speccy carries the actual beep code; line 901 just makes sure that the next time the code runs, the RCX beeps again (the RCX never executes a command twice, when you don't toggle the toggle bit :laugh:).

Yes you can make that even less hardware intensive, but I am going full classic RS232 communication here. This is why the RS232 break out board is there. The stuff on the little bread board is a serial tower proxy. The 74LS02 (4 x NOR) is luxury; only one gate is used here to enable/disable the 38kHz output on pin 11 with pin 10 of the Arduino, the latter is the customSerial_2400 TXD output.

Next up: Connect a second RS232 break out board to the Arduino to connect to the serial LEGO tower. 

(The USB port of the Arduino is just for power - it does not talk to the laptop. And remember: All this is just an RS232 communication translator: From 9600/1/8/N/1 w/ handshake on the Speccy to 2400/1/8/O/1 w/o handshake on the RCX)

Best
Thorsten

Edited by Toastie

Share this post


Link to post
Share on other sites

Getting there ... will post more details soon :pir_laugh2:

getting_there.jpg#

And yes, the glass of white wine is in focus, and everything else is not. Merde.

So far the ZX Spectrum can control RCX equipped trains. Which is a 1985 -> 1998 "connection". The Arduino in the pic does just that: 9600/1/8/None to 2400/1/8/Odd protocol conversion and nothing else!

The NXT (had display issues, thus dismantled, fixed) is supposed to do the RCX IR messaging to PF IR command translation via HiTechnic sensor, but so far it is reluctant to do so. Guess this is due to timing ... time was less "fast" in 1985 ... 

Stay tuned (yeah, weirdo ...)  

Best
Thorsten

Share this post


Link to post
Share on other sites

Well. Updating this thread with my stuff - sorry for that!

  1. I did not find any way to convert 8N1 to 8O1 with an Arduino Uno and any XYSoftSerial library. The Zeddy is a bit special ... timing wise. It is byte per byte with a little BASIC overhead. And the NXT/hiTechnic IR sensor is very strict on the total transmission time. 
  2. Attempt 2: Arduino Mega clone. Has 4 hardware serial ports - each can be configured as you see fit. 
  3. Fiddling with timing (the LEGO IR tower collects a lot of software dirt over time) - done.
  4. Adapting my very own 2 byte "IR protocol" (ID + databyte) from 2004 (which I kept for the time being because LEGO lasts forever) - done.
  5. Writing a ZX BASIC program (No labels, no IF THEN ELSE, no DO WHILE, no UNTIL, no CASE, just GOTO and GOSUB :pir_laugh2:, which is considered as DA WORST in programming - but then: It is what it is ... done. Err, almost. But working: The Zeddy talks to the Mega, which simply translates serial protocol, and then drives IR.

So next step: IR to RF (because the HiTechnic sensor has about 50 cm radius of action) and then that "was it" (ZX controls NXT, which controls PF devices), We'll see ... its getting closer, I guess.

Best
Thorsten

P.S.: Will post all that programming crap here ... it will be a long read :pir-huzzah2:

P.P.S.: This works: image.png.87559d834d33f7ffbf3ac13533b15c06.png 

Edited by Toastie

Share this post


Link to post
Share on other sites
On 4/5/2021 at 12:16 AM, Toastie said:

and then that "was it" (ZX controls NXT, which controls PF devices),

Lalala - I started this - lala - thread - lalala - so I can necro-bump it - lalala lala ... :innocent2:

Phew. Four months later with apparent total inactivity (yes, semesters are semesters, and our work on the metrology for ASML's EUV scanners is a bit on the time-consuming side as well ...) I finally arrived at this:

view_front_left.jpg

Front dark blue trans tile: On-board IR RX/TX. Left RS232 port: Connects to LEGO serial tower. Top: Three keys to select IR/RF/RS232 communication. Back (not shown): RS232 to ZX Spectrum Interface 1, USB (power supply and Arduino programming), 9V power supply.

As you may recall, I want my ZX Spectrum, a 1985 computer I still own back from the days (and fixed recently, as two of the 4116 memory chips as well as the ULA died earlier), to control some of my trains (either RCX or PF equipped). The point was: The ZX is in control and runs a program that does it all.

This is all about using outdated hardware to run outdated trains using an outdated approach. Some call it retro computing. Others a waste of time. For me, it is pure fun, as I feel to be 23 years old again ;)

Now, this is only an update on the progress; hardware works. However, there is still something wrong with the software. Not on the ZX, the Sinclair Basic program works nicely; but with the C++ program on the Arduino Mega hiding in that case. No no no, don't get me wrong: It is not the Arduino MEGA doing the control; that one is only there to translate from x baud/no parity/1 stop bit hardwired into the ZX to 2400 baud/1stop/odd parity hardwired into the RCX protocol. Plus channeling the data stream either originating/coming from a) the inbuilt IR, b) a LEGO serial tower, c) from OOK modulated RF resembling the RCX IR protocol. The latter is to reach my PF/RCX driven trains without line of sight, as discussed here on EB several times (I don't want to resurrect these threads ;)) they all have simple RF (433 MHz OOK) receivers.

That's inside:

step_7_rf_rx_tx.jpg

and this is the 1980 electronics on the Arduino Mega "shield" (I found the two 74LS02's on a board on an old mass spectrometer in the lab, we have kept for educational purposes. It is not that easy to get the LS series chips anymore - yes I know the HCT series is there - not the point, this is about the 1980s. And yes, I know that a Mega is not from that time, but I need to start somewhere ;))

(Forgive my bad soldering skills. They seem to be still at 1980 level)

module_2_ttl_shield.jpg

Experts in the field will notice a 3 port NOR gate realized with diodes (we are talking 2400 bits per second high-speed data here) - a single transistor logic inverter :laugh: (with a 1nF/10kOhm low pass "filter" on the RF logic line) ... all these components are +30 years old. I tend to stick to old parts in my work shop ...

Here are the almost 20 years old RF components:

module_7_rf_rx_tx.jpg

The solid antenna is just to impress - the two 17.something cm long wires are the RF RX/TX modules antennas matching with 433MHz.

Summing up:

  • ZX Spectrum/Interface 1 RS232 communication with LEGO IR tower / RCX / NXT (with HiTechnic IR sensor) works bi-directionally: Check
  • Sinclair Basic control program (a couple of hundreds of "code":pir-laugh: lines) works: Check
  • Hardware UARTs required to establish serial communication between a X/N/1 and 2400/O/1 protocol required; I could not get any software serial program on any Arduinos to accomplish this; I believe the major problem is that the ZX Interface 1 requires hardware handshake; it has an input buffer of 1 byte (actually 2, but that is even tougher to sync) and then needs to move that byte before listening again. None of the serial software programs available for Arduinos could handle that weird timing. I used an Arduino Mega (T-O-T-A-L overkill, but I guess that is the cheapest (<10€ - clone of course) one - it has four(!) hardware UART ports. Fully configurable. Check.
  • LEGO brick case built - trying to blend that with the ZX Sepctrum case/hardware. Check???

Next: Will simply dump more pics here ;)

Arduino RS232 syncing software needs improvement.

And when that is done: Demonstrate how the ZX Spectrum (as >brain<) controls trains from the 4.5/12/9/PF era. PUp is only possible with an ESP32 as essential hardware piece - so not that much of retro computing here (but rather simple to implement).

Here is to feeling good: :pir-huzzah2:

Best
Thorsten

Edited by Toastie

Share this post


Link to post
Share on other sites
22 hours ago, Toastie said:

Arduino RS232 syncing software needs improvement.

No it does not, when a stupid user cannot handle C++ regarding its >most basic< commands, methods and whatever.

This now works on all channels; IR, RF, LEGO Tower. Just to make sure: A nested "if, while, if" thing is not good, nor elegant - I am too stupid though to come up with the elegant stuff. The thing is: This works :pir-huzzah2:   

  // Listen to Tower, but only when a) data were sent by IF1 (flag_tower_enabled is true) and b) something  
  // actually arrives. The ID+data sent (echo) are flushed above.
  // The receiving loop is cycled until max_tower_RX_enable_time is reached.
  // For the RCX this time can be considerably shorter than for the NXT, as the NXT send the reply MSG only after
  // finishing sending out the PF command(s). This may take a long time (even >3s) when going from +7 to -7 as 
  // the PF power is set +/- 1 at a time  
   
  if (flag_tower_enabled == true){               // listen to IR/RF/RS232 (RCX reply) on Serial2 
                                                 // otherwise skip to listen to ZX on Serial1
    while (millis() < (tower_RX_enable_time + max_tower_RX_enable_time)){ 
                                                 // record and send out entire Serial2 buffer using HW hand    
                                                 // shake via RTS line control by the ZX 
      if (Serial2.available()){                  // wait for data - whatever they are - to arrive ...
        byte tower_data = Serial2.read();        // store one byte - whatever it is 
        while (digitalRead(pin_RTS_in)==HIGH) {  // HW handshake (wait loop): wait while pin_RTS_in is held  
                                                 // HIGH = ZX IF1 accepts no data 
          if (millis() > tower_RX_enable_time + max_tower_RX_enable_time){
                                                 // when ZX BASIC program is set to no-handshake-mode, pin_RTS_in  
                                                 // does never go low. Checking for timeout again here, otherwise
                                                 // this loop becomes a trap. ONLY required for non-handshake 
                                                 // operation selected on the ZX BASIC program
            Tower_Flush();                       // time out has occurred; empty Serial2 input buffer;  
                                                 // RCX may have answered (RCX always replies by default)
            tower_data = 0;                      // optional; clear last Serial2 data byte received                                
            flag_time_out = true;                // only for debug mode - notify time out
            break;                               // break out of current while wait loop
          }
        }                                                 
        Serial1.write(tower_data);               // send out one byte to ZX - whatever it is
        Delay(10);                               // give ZX some time. Delay(1) does not work; then not all
                                                 // bytes of a regular reply are transferred, regardless of HW 
                                                 // handshake control. Mandatory!
                                                 // Delay(5) good for 2400 baud setting, Delay(10) always stable
        if (debug == true){                      // print some debugging data on the serial monitor
          Serial.print(tower_data);
          Serial.print(" ");
          if (flag_time_out == true){
            Serial.print("RTS time out");
            flag_time_out = false; 
          }
        }
      
      }//if Serial2.available                       
    }//while (millis() < ...)
    flag_tower_enabled = false;                  // reset "awaiting data LED" in next main loop via SetTowerLED
  }//if (flag_tower_enabled == true)

More images are here: https://brickshelf.com/cgi-bin/gallery.cgi?f=582185

And more "importantly" (as if anyone cares, dude): I >just< found out, that an ESP32 Espressif board (10 bucks) has - oh crap - 3 UART serial ports. One for the USB, two - for you. Man. The thing is, that that board speaks BLE as well ... is much smaller than the Arduino Mega ... and I used such a board for a stand-alone solution (= no stupid apps on smart devices) for my Croc ...

OK. So. What do I do ... 

... I'll use this setup with the Mega and my super-duper-shield to do tests on my RCX/PF trains. When that works, switch to an ESP32 board (see, whether this one can cope with the demanding HW protocol of a 1985 computer!) and - well - see what happens!

@1974: Ole, can you believe that I am looking forward to trying this crap (above) in September, when we are spending our two-week vacation on Fanoe? Red wine, white wine, Carlsberg Porter (and the locally brewed beers), the North Sea maybe calm, maybe demanding, a restaurant - more pub like - close to the beach, and all this ... slowliness ... Esbjerg not smelling fishy anymore, when the wind comes from the land (well - to be honest: Much, >much< better than seeing all this off-shore oil industry growing there - but - yes - also windmill parts) ... and me, after a what-ever-weather-day, after dinner, after all went to bed ... trying it out? Maybe not :pir-huzzah2:

All the best
Thorsten   

Edited by Toastie

Share this post


Link to post
Share on other sites

Ha,

flooding this thread with - most probably - irrelevant info! Well: Whatever :pir-laugh:

So, here is a link to the ZX Spectrum BASIC code: https://brickshelf.com/gallery/ThorstenB/RetroComputing/ZXSpectumAMega/Resized/zxif1_rcx_communication_v4.txt

It works ...

Here is a snapshot of the "send message" ZX BASIC code:

zx_if1_rcx_control_v24_send.jpg

Lines 5020 to line 5040 compose the messages to be sent to the RCX or NXT: ID + databyte.

I love that lines 5042 to 5047 don't work: The ZX has these system variables for "measuring" time (there is no millis() or whatever method - there is POKE and PEEK ;)) but that is just not "stable"; 50% of the time it works, and then jumps to almost zero delay, back to what can be expected. A simple FOR/NEXT loop is rock solid, though, timing wise. A quick glance at the machine code representing FOR/NEXT is simply bolted to CPU instruction/clock cycles. I have no idea why POKE and PEEK of the system variables does not work ... but whatever.

And here is the reply ZX BASIC code:

zx_if1_rcx_control_v24_receive.jpg

Here the "short" POKE/PEEK of the timing system variable works. Nice.

With this, I believe all the stuff required for an 8-bit stone old 1985 computer controlling LEGO trains is online:

ZX Spectrum BASIC code (with Interface 1): https://brickshelf.com/gallery/ThorstenB/RetroComputing/ZXSpectumAMega/Resized/zx_if1_rcx_control_v24.txt

Arduino MEGA code: https://brickshelf.com/gallery/ThorstenB/RetroComputing/ZXSpectumAMega/Resized/zxif1_rcx_communication_v4.txt

Next up: A little video showing how it works. May take time though.

Best
Thorsten

 

Share this post


Link to post
Share on other sites

Nice.  Does the ZX have RS232 routines in its ROM like the Commodore VIC20?  I used to use machine language for the speed critical parts and BASIC for everything else on the VIC20.  

Strangely enough I still have 74LS02 and 74F02 in my box of parts.

74LS02.jpg

 

Share this post


Link to post
Share on other sites
On 8/3/2021 at 10:05 PM, Toastie said:

@1974: Ole, can you believe that I am looking forward to trying this crap (above) in September, when we are spending our two-week vacation on Fanoe? Red wine, white wine, Carlsberg Porter (and the locally brewed beers), the North Sea maybe calm, maybe demanding, a restaurant - more pub like - close to the beach, and all this ... slowliness ... Esbjerg not smelling fishy anymore, when the wind comes from the land (well - to be honest: Much, >much< better than seeing all this off-shore oil industry growing there - but - yes - also windmill parts) ... and me, after a what-ever-weather-day, after dinner, after all went to bed ... trying it out? Maybe not :pir-huzzah2:

All the best
Thorsten   

All that sounds like gibberish to me, I can only do BASIC :laugh:

Fanø (Fanö) is real nice, enjoy! :pir-huzzah1:

Share this post


Link to post
Share on other sites
On 8/6/2021 at 11:06 AM, 1974 said:

Fanø (Fanö) is real nice, enjoy!

Oh yes. Let's see: I was 15 when I was there for the first time. Then basically every year. At least for the past 20 years. Even when we lived in the US, more than 20 years ago and visited Germany for X-Mas we spent 5 days there over New Years ...
I'd live there tomorrow ... but a) Germans can't buy (good thing) and b) they simply don't need chemists there, well at least none of the kind I am.

So we have to compensate for that with vacation time ;)

All the best
Thorsten

Share this post


Link to post
Share on other sites

It's fun to get more use out of old hardware.

Recently I received an old Klic-N-Kut die cutter. It has an old school RS232 interface. No problemo. Hooked up a USB to RS232 adapter and no comm. Doh, it's two DTE devices. I had to make a null modem and 3D printed enclosure. The die cutter uses XON/OFF so 3 wires is all that is needed--simple.

nullmodem.jpg

Don't throw out old computer cables. You never know when you'll need them again.

usb_rs232_cable.jpg

Now we can cut compatible sails and minifigure capes.

knk3.jpg

Works good for making vinyl transfer decals too.

db-logo.jpg

Share this post


Link to post
Share on other sites

Ahhh - yes, XON/OFF renders serial life so much more enjoyable :pir-huzzah2:

Nice, really nice! What I like the most is that the sail perfectly fits my Black Pearl (clone) ship :pir-grin: - using black cloth, though.

And then the douche bag sticker - man. Nice.

BTW, the nifty 2-3 3-2 (5-5) cross over thingy also comes in handy, when playing with the LEGO IR tower. The tower hooked up to that cross-over thingy needs an additional RTS/CTS bridge (pins 7/8), a USB2Ser converter that is aware of RTS/CTS, and boom, NQC, BricxCC, and the VB6 OCX plugin, are all happy to communicate with the tower. On any Win7/8/10/32/64bit machine. Just make sure in device manager that the COM port of the USB2Ser converter is <8. Because in the olden days, a COM port number exceeding 7 was considered - nuts. At least.

Best
Thorsten

Share this post


Link to post
Share on other sites
On 8/6/2021 at 1:37 AM, dr_spock said:

Nice.  Does the ZX have RS232 routines in its ROM like the Commodore VIC20?  I used to use machine language for the speed critical parts and BASIC for everything else on the VIC20.

It does.

This book I have here as paperback is showing a lot of wear (and tear ...): https://spectrumcomputing.co.uk/entry/2000076/Book/The_Complete_Spectrum_ROM_Disassembly

The interface 1 ROM disassembly is here: https://www.tablix.org/~avian/spectrum/rom/if1_2.htm

Regarding Z80 (as well as many microcontroller) machine code: Timing-wise, I like to use simple 1 clock "nop" instructions; load some register with the loop count, count down with djnz loops, the loop is just one or a bunch of nops. Implementation is straight forward in ZX Basic using DATA, READ, POKE (to prepare the machine code) and then RANDOMIZE USER (address) to call the code.

I have the impression though that FOR NEXT loops, provided the temporal resolution [read ("interprete") the FOR i = m to n BASIC code + load registers; read NEXT i] is good enough, then looping in ZX Basic appears to be as rock-solid as it is in machine code.

Best
Thorsten

Share this post


Link to post
Share on other sites

Hello Thorsten, thanks for your comment on the Control Lab thread :)

ZX Spectrum pre-dates the RCX by many years and for that reason, I choose to team it with early 80s Technic in the style of the book, ‘Make and Program Your Own Robots’. I have built a modern replica of the RoboTEK interface and I can sell you one if you like, though it’s not a cheap option at around 80 Euros (I had the circuit board specially made). 
 

Here is the three-motor arm project from the book; really crude programming compared to yours. The inputs and outputs of the RoboTEK are all over the place, so the inputs are not valued at 1, 2, 4 as you would expect, but instead 4, 1, 32… I could have easily rectified this and could have made improvements with double-pole relays etc. but I wanted to keep it completely compatible with the original projects in the book.

And here is a look at my part of New Zealand’s national brick show:


-Alex

Edited by alexGS

Share this post


Link to post
Share on other sites
On 9/22/2021 at 1:15 AM, alexGS said:

Hello Thorsten, thanks for your comment on the Control Lab thread :)

Hi Alex,

oh man - sorry for not responding earlier!!! Either this email notification thingy failed on me or something else went wrong.

You know, my heart was bumping so hard when watching the videos, seeing the Spectrums doing all this work - fantastic! It is so nice and encouraging to know that I am not alone (LEGO wise) with using the Speccy for LEGO control. So nice.

I am very interested in your RoboTEK interface! Wow. I have "upgraded" my Spectrums with the vDrive from Charlie Ingley - my "tape drive" was simply not working anymore (tried it ...). Another beautiful thing.

Nice. Really nice.

Thanks a million for posting the videos!

All the best,
Thorsten

 

Share this post


Link to post
Share on other sites

So ... 2021 - Time ... as Pink Floyd put it - on the second last verse (... just skip all the preceding text, it is frustrating :pir-huzzah1:) :

Home, home again
I like to be here when I can
And when I come home cold and tired
It's good to warm my bones beside the fire

@dr_spock called me out, when I was - again - blabbing about "back then stuff" on a thread that deals with Mindstorms coming down in flames - as per TLG flak.

Now, in this thread, we are discussing >really old< stuff. Nobody is >really interested< in :pir-laugh:

And: I started this thread, so I can necro-bump it, la la la ... @Milan forgive me ...

OK, this is what happened: Checked on stuff to be trashed, as we were hiring new faculty, and these folks need space. I won't comment on space as in the Last Frontier ... not relevant: Faculty in Theoretical Chemistry, say no more. Next, "storage rooms" tend to convert into dumpsters - provided there are enough of them ;) So ... I had a look.

What I saw were Amiga's, VIC20's, Commodores, telephones, a cell phone from the Neanderthal age, DEC VT XY terminals (OH MY), modems (with these soft shell covers) - and beware and hold your breath - an IBM 5160, IBM Color Monitor, IBM keyboard, of the variety you can use to hit a baseball out off the park. 2 x floppy disk drives at full height - no hard drive. With a sticker: 1985.

And this was the system, my wife learned "intro of using a PC" in 1985 - as part of her industrial management curriculum. They had IBM PC's with 256k memory, color graphics card and monitor, 2 x 360k floppy drives - and these clocked in at about 10000 D-Marks in Germany - I was just sitting there in the classroom (after carefully asking her whether I can have just a look) - and of course I did not touch anything. And since then, I am dreaming at night - you know, when I come home cold and tired - of that system. Since 30+ years.

Fast forward: "It" is now in my attic. And I will try (as in seriously try) to get this thing to do any sort of BASIC - providing access to the serial port card it also has. That very moment, I can get access to all my trains with the help of an ESP32 and LEGOINO, as already posted.

So far, it boots off from an original IBM (= Tandon) 360k drive, leaving me with 6 programs - two of which asking for time and date.

I am working on this. And will post any irrelevant progress here.

You have been warned :pir-skel:.

Best,
Thorsten

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.