BobGenom / arduino_sketches

publish1
4 stars 0 forks source link

RCX 1.0 #1

Open rob-melb opened 8 years ago

rob-melb commented 8 years ago

Hi Bob,

Firstly, thanks for contributing this project - I recently picked up a couple of RCX 1.0 + motors and sensors for my son and I to play with. No IR Tower was provided... I've tried your program on the RCX 1.0 - but with no luck.

I'm using a Pro Mini Atmega 328 5V 16MHz, a TSOP4838 (IR Rx) and TSAL6100 (IR Led). Connected to the computer via an FTDI connector. All components have been tested and are working as expect.

From what I have read there is no notable difference in the hardware between the 1.0 and 2.0 (firmware only update).

I have tried both RCX bricks (x2) without any luck - I have tried using Robolab, RobotC and Bricx Command Center to do the update. With the serial set to 2400baud, 1 parity/odd, 1 stop bit.

Can you help - am I missing something?

Thanks, Rob

BobGenom commented 8 years ago

Hello Rob,

the Lego Bricks are using a 36kHz (38.5kHz is right, see below) IR modulation signal with 950nm:

Therefore I carefully picked the TSOP 31236, which supports 36kHz on 950nm!! And the SFH-409 with 950nm IR.

You picked the TSOP 4838, which supports 38kHz on 950nm. On the other side your TSAL6100 emits 940nm IR.

I'm really not an electronic expert but I guess that your choices are two times in-compatible with any RCX. What do you think?

Kind regards Bob Genom

rob-melb commented 8 years ago

Hi Bob, Thanks for getting back to me. I've ordered a TSOP31236 to try, however, all the documentation I could find states that it operates at 38.5khz, and your documentation states 38khz - am I missing something? Is the Tx and Rx at different frequencies or something? Also, have you been able to use your system to update the firmware on the RCX 2.0?  Thanks,Rob

  From: BobGenom <notifications@github.com>

To: BobGenom/arduino_sketches arduino_sketches@noreply.github.com Cc: rob-melb robin_schmitt@yahoo.com Sent: Wednesday, 16 March 2016, 9:02 Subject: Re: [arduino_sketches] RCX 1.0 (#1)

Hello Rob,the Lego Bricks are using a 36kHz IR modulation signal. Therefore I carefully picked the TSOP 31236, which supports 36kHz!! You picked the TSOP 4838, which supports 38kHz.I'm really not an electronic expert but I'm in doubt that this will be compatible. What do you think?Kind regards Bob Genom— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

BobGenom commented 8 years ago

Hello Rob,

I have to admit that I was following the wrong trace. Sorry for this. Lego Bricks are using a 38.5 kHz IR modulation signal (not 36 kHz, as I stated above) with 950nm. This can be found here: http://www.legolab.daimi.au.dk/CSaEA/RCX/Manual.dir/RCXManual.html or here http://lego.wikia.com/wiki/Mindstorms_RCX

You are right: (my) TSOP 31236, supports 36 kHz. (Your) TSOP 4838, supports 38 kHz. So yours is closer to the Lego Bricks spec.

Nevertheless, I'm using a TSOP 31236 (I double checked) and it works fine (by luck?).

If it's a physics problem, then your TSAL6100, which emits 940nm, could be the source of the problem.

Comming back to your question about uploading the firmware: I'm not sure about this. But at least I used "lejosfirmdl.exe" to upload my programs as shown in README.md:

lejosfirmdl --tty=\\\.\COM16 HelloWorld.srec

You may define this as a kind of (my) firmware. I guess this should work with any srec-file as well.

Sorry for the confusion, thank you for pointing this out and kind regards Bob Genom

rob-melb commented 8 years ago

Hi Bob,

No problem - 36khz module - the TSAL6100 is 80% efficient at 950nm - it is super bright so this shouldn't be the issue. I might use a transistor to up the power to the led, just to be sure.

I'll then build a test receiver setup so many can monitor what is sent and received. I'll also look at using interrupts in the code - but I don't really want to mess with the code - it is working for you, it should work for me.

PS: I have tried lejosfirmdl too - no luck...

I'll let you know how I go and thanks again.

Cheers, Rob

Sent from my iPad

On 17 Mar 2016, at 5:59 AM, BobGenom notifications@github.com wrote:

Hello Rob,

I have to admit that I was following the wrong trace. Sorry for this. Lego Bricks are using a 38.5 kHz IR modulation signal (not 36 kHz, as I stated above) with 950nm. This can be found here: http://www.legolab.daimi.au.dk/CSaEA/RCX/Manual.dir/RCXManual.html or here http://lego.wikia.com/wiki/Mindstorms_RCX

You are right: (my) TSOP 31236, supports 36 kHz. (Your) TSOP 4838, supports 38 kHz. So yours is closer to the Lego Bricks spec.

Nevertheless, I'm using a TSOP 31236 (I double checked) and it works fine (by luck?).

If it's a physics problem, then your TSAL6100, which emits 940nm, could be the source of the problem.

Comming back to your question about uploading the firmware: I'm not sure about this. But at least I used "lejosfirmdl.exe" to upload my programs as shown in README.md:

lejosfirmdl --tty=.\COM16 HelloWorld.srec

You may define this as a kind of (my) firmware. I guess this should work with any srec-file as well.

Sorry for the confusion, thank you for pointing this out and kind regards Bob Genom

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

rob-melb commented 8 years ago

Hi Bob, FYI: Got it working with the hardware I have. Wrote my own code based on the Dirt Cheap Wireless code, plus a CustomerSoftwareSerial library that allows the software serial port to be set to 2400, 8O1 - as you had it configured. I had to shield the tx led from the receiver to avoid cross talk - this was simple enough. I expect the 36khz RX remove any cross talk issues - I'll let you know if it work. Thanks for your help,Rob

The code is below: //Lego RCX IR Tower Code //Based on dirt cheap wireless TX using CustomerSoftwareSerial //See: https://tthheessiiss.wordpress.com/2009/08/05/dirt-cheap-wireless/ //See: https://github.com/ledongthuc/CustomSoftwareSerial //Generates 38kHz carrier wave on pin 9 and 10 //Sends/receives data through IR through a CustomSoftwareSerial port //Both Serials Ports are set 2400 baud, 8 bit, odd parity & 1 stop bit (8O1)

include

define rxPin 2

define txPin 3

CustomSoftwareSerial* customSerial; // Declare serial

void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT);

// Clear Timer on Compare Match (CTC) Mode bitWrite(TCCR1A, WGM10, 0); bitWrite(TCCR1A, WGM11, 0); bitWrite(TCCR1B, WGM12, 1); bitWrite(TCCR1B, WGM13, 0);

// Toggle OC1A and OC1B on Compare Match. bitWrite(TCCR1A, COM1A0, 1); bitWrite(TCCR1A, COM1A1, 0); bitWrite(TCCR1A, COM1B0, 1); bitWrite(TCCR1A, COM1B1, 0);

// No prescaling bitWrite(TCCR1B, CS10, 1); bitWrite(TCCR1B, CS11, 0); bitWrite(TCCR1B, CS12, 0);

OCR1A = 210; OCR1B = 210;

customSerial = new CustomSoftwareSerial(rxPin, txPin); // rx, tx customSerial->begin(2400, CSERIAL_8O1); // Baud rate: 2400, configuration: CSERIAL_8O1

Serial.begin(2400,SERIAL_8O1); }

void loop() { if(Serial.available()) { while(Serial.available()) { char dataIn = Serial.read(); Serial.print(dataIn); //echo read information - needed to echo to load firmware customSerial->write(dataIn); } } else { if (customSerial->available()) Serial.write(customSerial->read()); } }

BobGenom commented 8 years ago

Hello Rob,

A) I need some help with your approach. How is your wiring? How does the 38kHz carrier wave on pin 9 and 10 has any influence on Pin 3 (Tx) the LED.

B) removing cross talk issues When I started the project I tried shielding the tx LED too but without any success. I guessed cross talk comes from physical reflection of the Lego Brick. (Lego Brick plastic acts as a kind of mirror.) I ended up, accepting the physical cross talk. And counteract in software: The first byte received after each transmit burst is neglected by my software, assuming that it is cross talk garbage. (The variable 'state' accomplishes this.)

C) Just an idea: Why not using a baud rate of 76000? This -> https://github.com/ntim/hyperion/wiki/Ws2812b inspired me to the idea to have two serial objects TxSerial and RxSerial to set them like this: TxSerial: 76000 baud, 8 bit, no parity & 0 stop bit (8N0) and no(!) start bit RxSerial: 2400 baud, 8 bit, odd parity & 1 stop bit (8O1)

You will get a perfect 38kHz IR carrier wave (if no underflow occurs) if you write:

#define Wa 0b00000000
#define Wb 0b10101010
for(;;) TxSerial.write(Wb);

I calculated that 32 waves of 38kHz IR carrier wave cover a single 2400 baud bit. With this, sending a 2400 baud bit '0' via 38kHz IR carrier looks like this: for(int i=0; i<32; i+=4) TxSerial.write(Wb); // 0

Sending a 2400 baud bit '1' via 38kHz IR carrier looks like this: for(int i=0; i<32; i+=4) TxSerial.write(Wa); // 1

Putting things together and sending the letter 'C' (HEX 43, binary 0100 0011) as 2400 baud 8O1 using TxSerial might look like this (just showing the principle idea):

for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // Start bit

for(int i=0; i<32; i+=4) TxSerial.write(Wa);  // D0=1
for(int i=0; i<32; i+=4) TxSerial.write(Wa);  // D1=1
for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // D2=0
for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // D3=0

for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // D4=0
for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // D5=0
for(int i=0; i<32; i+=4) TxSerial.write(Wa);  // D6=1
for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // D7=0

for(int i=0; i<32; i+=4) TxSerial.write(Wb);  // parity calculates to 0 to be odd
for(int i=0; i<32; i+=4) TxSerial.write(Wa);  // Stop

Kind regards Bob Genom

rob-melb commented 8 years ago

Hi Bod,

He is some quick photos of the board - you can see the wiring and how I shielded the IR.

Basically the led is between pins 3 and 10 (+), and the Rx goes to pin 2. I used a pen tip as a shield with bluetac/poster-tack to enclose and mount - a simple solution.

It works very well - but the unit needs to be placed around an inch form the RCX - directly in front of the receiver.

Sent from my iPhone

Robin Schmitt

On 7 Apr 2016, at 06:55, BobGenom notifications@github.com wrote:

Hello Rob,

A) I need some help with your approach. How is your wiring? How does the 38kHz carrier wave on pin 9 and 10 has any influence on Pin 3 (Tx) the LED.

B) removing cross talk issues When I started the project I tried shielding the tx LED too but without any success. I guessed cross talk comes from physical reflection of the Lego Brick. (Lego Brick plastic acts as a kind of mirror.) I ended up, accepting the physical cross talk. And counteract in software: The first byte received after each transmit burst is neglected by my software, assuming that it is cross talk garbage. (The variable 'state' accomplishes this.)

C) Just an idea: Why not using a baud rate of 76000? This -> https://github.com/ntim/hyperion/wiki/Ws2812b inspired me to the idea to have two serial objects TxSerial and RxSerial to set them like this: TxSerial: 76000 baud, 8 bit, no parity & 0 stop bit (8N0) and no(!) start bit RxSerial: 2400 baud, 8 bit, odd parity & 1 stop bit (8O1)

You will get a perfect 38kHz IR carrier wave (if no underflow occurs) if you write:

define Wa 0b00000000

define Wb 0b10101010

for(;;) TxSerial.write(Wb); I calculated that 32 waves of 38kHz IR carrier wave cover a single 2400 baud bit. With this, sending a 2400 baud bit '0' via 38kHz IR carrier looks like this: for(int i=0; i<32; i+=4) TxSerial.write(Wb); // 0

Sending a 2400 baud bit '1' via 38kHz IR carrier looks like this: for(int i=0; i<32; i+=4) TxSerial.write(Wa); // 1

Putting things together and sending the letter 'C' (HEX 43, binary 0100 0011) as 2400 baud 8O1 using TxSerial might look like this (just showing the principle idea):

for(int i=0; i<32; i+=4) TxSerial.write(Wb); // Start bit

for(int i=0; i<32; i+=4) TxSerial.write(Wa); // D0=1 for(int i=0; i<32; i+=4) TxSerial.write(Wa); // D1=1 for(int i=0; i<32; i+=4) TxSerial.write(Wb); // D2=0 for(int i=0; i<32; i+=4) TxSerial.write(Wb); // D3=0

for(int i=0; i<32; i+=4) TxSerial.write(Wb); // D4=0 for(int i=0; i<32; i+=4) TxSerial.write(Wb); // D5=0 for(int i=0; i<32; i+=4) TxSerial.write(Wa); // D6=1 for(int i=0; i<32; i+=4) TxSerial.write(Wb); // D7=0

for(int i=0; i<32; i+=4) TxSerial.write(Wb); // parity calculates to 0 to be odd for(int i=0; i<32; i+=4) TxSerial.write(Wa); // Stop Kind regards Bob Genom

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub