Arduino Forum

Topics => Robotics => Topic started by: bmd1103 on Jun 27, 2018, 04:42 am

Title: Meccano MAX and Arduino
Post by: bmd1103 on Jun 27, 2018, 04:42 am
Is there anyone out there trying to get to grips with the Meccano MAX robot?

It's an addition to their Meccanoid range with a few new bells and whistles -

 .  motors are "smart" motors using the same daisy-chain arrangement as for the servos in the older versions

 .  there is an ultrasonic sensor included operating off the same system

 .  the "face" is a 16 col x 8 row LED array with only green LEDS.

So far I have managed to get it to talk to a Mega and have managed to find out the codes for the new items -

 smart motors 0x03
 ultrasonic sensors 0x04
 face 0x06.

(note that I did record an 0x05 for the face at one stage - haven't been able to reproduce that though)

I'm trying to get the comms going using a non-blocking approach with pin 18 used as TX1 and serial managed by the port, and also using it to generate an interrupt on receive.

If anyone else has tried anything with these and are interested in sharing info, I think this is a better option than the older series.


Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 01, 2018, 01:35 am
After a bit more research ...

The face pattern is set using a format different from that set out in the protocol document.  A similar pulse width arrangement is used, but the bit period is shorter at 416 us.  There is a 140us LOW, 550 us HIGH,  140 us LOW sequence as a START combination.  LEDS in the display are OFF if the message bit is high for 277 us on average,ON if it is about 138 us.

The first bit is the bottom left LED, and the sequence is bottom to top, left to right as viewed from the front.

After the 16 bytes carrying the display data, two more bytes are added presumably as some sort of error check. There also appears to be 2 very short pulse which I cannot resolve with my equipment.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 13, 2018, 06:35 am
Hi bmd1103,

Have you made any progress in interfacing to the MAX's ultrasonic sensor, face, etc? If so, could you share your finding please?
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 15, 2018, 11:27 pm
Getting there - I have managed to build a signal sniffer that lets me eavesdrop on the communications between the brain and the outlying devices, and am trying to complete code that will allow me to record a complete series of transactions.  At the moment, I can receive and decode a single command/response pair but have a gremlin that stops it repeating on subsequent cycles.  Once I have that working, I'll try to build up a library of commands and associated effects.  I'm currently using the motors as there are 2 of them which allows me to look at how subsequent response are set out, bu will get into the ultrasonic sensor asap.

I'll keep this stream up-to-date when I start to make progress.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 18, 2018, 08:19 am
Looking forward to hearing your latest update. It will be interesting to know how the new devices communicate differently from that defined in the Smart Module Protocol. And SpinMaster has not updated its "Open Source" from a long while!

Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 19, 2018, 10:06 am
I have managed to get signals from the system - both commands and responses.  There is still an issue I have to sort out with picking up the initial traffic when the MAX is first turned on, (which is of course the most interesting part).

The two Smart motors, when stationary, both return 0.  Using 0x24 as the command byte drives the motor forward; 0x34 drives it back.  Using the Remote Controller, there seems to be another command in there to change the speed.  So when I start the first motor in the forward direction, then the second in the same direction, the command sequence is:

FF 0 0 FE FE C0  - 8
FF 0 0 FE FE C1  - 0
FF 0 0 FE FE C2  - ~~
FF 45 20 FE FE 93  - ~~
FF 24 0 FE FE 40  - 8
FF 24 0 FE FE 41  - 0
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - c
FF 24 45 FE FE D1  - 0
FF 24 24 FE FE A2  - ~~
FF 24 24 FE FE A3  - ~~
FF 24 24 FE FE A0  - 14
FF 24 24 FE FE A1  - 0
FF 24 24 FE FE A2  - ~~
FF 24 24 FE FE A3  - ~~
FF 24 24 FE FE A0  - 1a

where the first 6 bytes are the command, and the final value is the response. (the ~~ indicates there is no response).  I'm presuming the response is something to do with the speed, as it increases after the "45" command.  The command to go to full speed is 0x4A.

Starting just the second motor in reverse gives:

FF 0 0 FE FE C2  - ~~
FF 20 45 FE FE 93  - ~~
FF 0 34 FE FE 50  - 27
FF 0 34 FE FE 51  - 1e
FF 0 34 FE FE 52  - ~~
FF 0 34 FE FE 53  - ~~
FF 0 34 FE FE 50  - 27
FF 20 34 FE FE 71  - 18
FF 0 34 FE FE 52  - ~~
FF 0 34 FE FE 53  - ~~
FF 0 34 FE FE 50  - 27
FF 0 34 FE FE 51  - 11

I still need to work on my sniffer program so I can get at the start-up codes, but at least I'm getting sensible results.  I also need to sort out what the responses mean.

What is your interest in the MAX?

Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 20, 2018, 12:26 pm
I have a MAX. I want to use it as a robotic platform ie, as a base for use as a vision-based robot. Before that can happen, I have to be able to control its motion, face expression (the strong point of MAX) and the hand and head movements. Hence my interest in how the meccabrain protocol works for these new devices. I am looking forward to your analysis of the communication protocol for these devices. I may borrow a Xprotolab scope to do some analysis of my own during the weekend ;-)
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 20, 2018, 11:30 pm
mrdreambot -

I've got as far as reading a string of transactions during start-up - see the attachment.  I have given my interpretation of each step. I've also attached the current version of my sniffer program. It probably needs some refinement around the final presentation of results and there are a few little glitches from time to time that might need sorting.

The results are presented as the 6-byte command string, followed by the module response - ~~ shows that there is no response.  Some interesting things are that it appears that a command may be addressed to a particular module even though the "item code" (last nibble of the string) refers to a different module.  

Next step is to see if I can replicate the command strings from the Arduino in some sort of clever way (probably involving a multidimensional string array) and get the same responses back.  I'm also going to set up MAX programs to repetitively do a series of commands such as move the servos, and see what the traffic is then.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 21, 2018, 04:08 am
Further testing on the servos installed as specified:

Using the remote control display to adjust the position of the servos gives:

FF B4 8D FE FE 41  - 8d         Claw fully open

FF B4 C7 FE FE 11  - c8         Claw partly open

FF B4 E8 FE FE 41  - e2         Claw fully shut


FF 18 C7 FE FE A1  - c8         Head tilted to right

FF 78 C7 FE FE 11  - c8         Head central

FF E8 C7 FE FE 81  - c8         Head tilted to left

So a command
   FF nn xx FE FE c1
will tilt the head at an angle dependent on nn in a range of 0x00 to 0xFA, and open the claw to a amount dependent xx in a range 0x80 to 0xFA.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 21, 2018, 08:46 am
Thanks for that.

Try Xprotolab scope with Windows Interface. Did not get anywhere. Recorded trace as a file but when playing back, the app always crashes. Here are a couple of screenshots. Can't analyse unless able to record and playback. Have to use your approach of writing a sniffer!
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 22, 2018, 11:25 pm
I've managed to get a sniffer reading the commands to the LED array.

The first table gives time in us for each logic level after the first HI-LO transition. - indicates a low level, + a high.  So there is a preamble or "start bit' consisting of a 132 us LOW, a 564 us HIGH, and a 140 uS LOW.


-132 +564 -140
+280 -144 +276 -176 +236 -144 +280 -144 +136 -284 +280 -144 +280 -144 +280 -140
+280 -144 +280 -140 +280 -144 +280 -144 +156 -272 +284 -144 +280 -152 +260 -140
+280 -144 +280 -144 +276 -144 +280 -144 +148 -272 +280 -144 +284 -140 +280 -140
+280 -144 +280 -144 +276 -144 +280 -144 +144 -276 +280 -144 +280 -144 +280 -140
+280 -144 +280 -144 +280 -140 +280 -144 +144 -288 +312 -108 +272 -144 +280 -140
+280 -144 +280 -140 +284 -140 +280 -144 +160 -260 +280 -144 +280 -140 +284 -140
+280 -144 +280 -140 +284 -140 +280 -140 +148 -276 +280 -144 +280 -140 +284 -140
+280 -144 +280 -140 +284 -140 +280 -140 +152 -296 +260 -140 +280 -144 +280 -140
+280 -144 +280 -144 +280 -140 +280 -144 +144 -276 +280 -144 +280 -144 +280 -140
+280 -144 +280 -144 +280 -140 +280 -144 +140 -280 +280 -144 +280 -144 +280 -140
+280 -144 +280 -144 +280 -140 +280 -152 +144 -284 +276 -132 +280 -144 +332 -124
+256 -140 +280 -144 +280 -144 +276 -144 +140 -284 +280 -140 +280 -144 +280 -144
+280 -140 +280 -144 +280 -144 +276 -144 +140 -284 +280 -140 +280 -144 +280 -144
+280 -140 +280 -144 +280 -144 +280 -160 +132 -280 +272 -140 +280 -144 +280 -140
+284 -140 +280 -144 +280 -140 +284 -140 +140 -280 +284 -140 +280 -144 +280 -140
+284 -140 +280 -176 +240 -140 +140 -284 +140 -280 +140 -284 +280 -140 +284 -140
+280 -144 +280 -140 +284 -140 +288 -156 +144 -268 +284 -132 +144 -276 +280 -140
+280 -144 +148 -276 +144 -280 +276 -144 +280 -144 +280 -140 +280 -144 +144 -280
+20 -56 +128 -340
  #################  ################# 

The second table has the above data converted to binary: 1 = a long HIGH (>210us) and 0 a short HIGH.  The pattern on the screen at the time was the standard horizontal line with a "moving" vertical bar of 3 dots.  The first line is the long HIGH in the preamble, and the last 2 lines are some sort of check-sum (which needs a bit of working on).
1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 0 0 0 1 1
1 1 1 1 0 1 0 1
1 0 0 1 1 1 1 0
0 0  - 0


The tab
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 23, 2018, 12:08 pm
Great work. I am going to write a library incorporating your work for experimentation in the next few day. Shall keep you informed.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 23, 2018, 10:28 pm
I'm working on analysing the check-sum - remembered overnight that the data is transmitted LSB first, so the hex version of the data above is:

1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 1 0 1 1 1     EF
1 1 1 0 0 0 1 1     C7
1 1 1 1 0 1 0 1     AF
1 0 0 1 1 1 1 0     79

I've got information from a number of the array patterns provided as part of the "Programming" function, and they all have AF as the first byte in the checksum.  I'll assume that the calculation is a variant on the one used for the standard serial mode and see where that gets me.

Then I'll have to see what is involved in getting the Arduino to generate this type of string - probably won't be too bad with the PWM feature, but the subtle changes in timing for the start bit, and the need for an initial standard 2400 bd serial link will make it interesting.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 24, 2018, 01:03 pm
OK. You keep analyzing the protocol. I've started writing a framework for MAX. Right now I can control the servos and motors. It is work in progress. I shall put it on Guthub soon so that others may improve on it. I am using Gang of 4's Chain of Responsibility Design pattern to loosely couple the different modules. I shall describe it in more details when I put it onto Github.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 25, 2018, 12:26 pm
Here is a photo of my setup using Smart Power and an UNO. Also here is a screenshot of the Serial Monitor displaying the communication with the attached devices. Note that the header byte FF has been omitted. Also the checksum has been removed. Only the module number is shown. The response from the device is shown after the "-".
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Jul 26, 2018, 03:29 am
Good work! - I haven't done anything with the Mega apart from using it to snoop on the Max communications.

Here is the list of checksums derived from the standard face displays provided under the "Programming" option.  I'll be away from home for a few weeks from Saturday so will have to work on the system on paper only.  If I can't come up with a reasonably easy formula, I might try a brute strength approach - generate messages for simple patterns such as a single LED, and try all 256 possibilities until I find one that works.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 26, 2018, 01:10 pm
Here is the UML class diagram of  the framework I am working on now. Still in progress. As I said earlier, I am using the GOF Chain of Responsibility Design Pattern.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 26, 2018, 11:56 pm
Need some time to digest your findings. I am going to be away for a week too. Enjoy your break.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Jul 27, 2018, 09:37 pm
BTW, the max distance sensor is not an ultrasonic but an infrared device and haveing similar behavior as a Sharp infrared sensor.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 02, 2018, 02:41 pm
OK - I've got an algorithm for the checksum for the LED array.

First, the 8 bits for each of the 16 columns have to be converted into numerical form.  The LS bit of each byte is the top one, rather than the bottom one as I assumed earlier, and each byte is therefore transmitted MSB first.

Second, the 16 bytes for the full display are added together using 1's complement arithmetic if there is an overflow, it is wrapped around and added in to the LSB position. The checksum flag value of 0xAF is also added in this fashion,

Third, the resultant is subtracted from 0xFF to get the checksum to be transmitted as byte 18 of the message.

Code: [Select]
byte checkSum(byte data[])
{
  int cs = 0;
  for (int i = 0; i < 17; i++)
  {
    cs = cs + data[i];
    if (cs > 255) cs = cs - 255;
    Serial.print(i);Serial.print("  ");Serial.println(cs);
  }
  cs = 0xFF - cs;
  return (byte)cs;
}
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 04, 2018, 05:51 am
bmd1103,

Question: after identifying the device ID=6 which is the face after the exchange:

Starting Max Tests...
FE FE FE FE 0 - 0
FE FE FE FE 1 - 0
FE FE FE FE 2 - 0
FE FE FE FE 3 - 0
FE FE FE FE 0 - FE
FC FE FE FE 1 - 0
FC FE FE FE 2 - 0
FC FE FE FE 3 - 0
FC FE FE FE 0 - 6

Do I need to send a command before sending the data for display? If so, what command code is it?

If not, does it mean one can send data to the Face at anytime? That appears to violate the protocol above?

I tried sending the data right after identifying the device. But it does not work. I also try send a command (cycle between 0 and f8 before sending the data, it does not work either.

I did not calculate the checksum but used your recorded AF, checksum in your Lead_array_message PDF for the various images.

Any suggestion will be appreciated.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 05, 2018, 08:08 am
mrdreambot,

The sequence I logged repeated the commands FF FC FE FE FE FE 8n twice - I don't know if that is the requirement. Then there is FF 00 FF 00 FF 00  - ~~, with no response from the  module, then it appears to start on the pwm sequence. 

However, I haven't looked for any more detail at the transition between the two modes and can't do any hands-on testing till I get home in a month.  I'll try and run my transition timing program on the startup sequence, or trigger my oscilloscope from the Arduino so I can grab the last couple of frames of the serial and the start of the pwm mode.
There is about a 33 ms delay between the pwm frames so you could try that between the serial and pwm as well.

So I'd suggest -
send

FF FE FE FE FE A1  - ~~
FF FE FE FE FE A1  - ~~
FF FE FE FE FE A2  - ~~
FF FE FE FE FE A3  - ~~
FF FE FE FE FE A0  - fe      Module 0 replies with 0xfe
FF FE FE FE FE A1  - ~~
FF FE FE FE FE A2  - ~~
FF FE FE FE FE A3  - ~~
FF FE FE FE FE A0  - fe      Module 0  repeats reply
FF FC FE FE FE 81  - ~~
FF FC FE FE FE 82  - ~~
FF FC FE FE FE 83  - ~~
FF FC FE FE FE 80  - 06      Module 0 replies with type code 6
FF FC FE FE FE 81  - ~~
FF FC FE FE FE 82  - ~~
FF FC FE FE FE 83  - ~~
FF FC FE FE FE 80  - 06      Module 0  repeats reply
FF FC FE FE FE 81  - ~~
FF FC FE FE FE 82  - ~~
FF FC FE FE FE 83  - ~~
FF 00 FF 00 FF 00  - ~~              ?? Change to pwm command ??

then wait 30 ms, then start sending the pwm strings.

Hope that helps.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 05, 2018, 01:06 pm
Tried different variations and delays but still not able to get any LED on the Face to light up. Shall try some more tomorrow and keep you informed.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 06, 2018, 10:00 am
mrdreambot-

If you are using the program I wrote to write to the array, the csFlag array is wrong - it needs to be

Code: [Select]
boolean csFlag[] = { true, true, true, true, false, true, false, true };

The original was written when I was assuming that the message was sent lsb-first.

I'm going to go back to my original data stream tests and try to translate them into the correct format - but it's easy to make a mistake.  I've written an Excel app to see if I can tidy it up but need to double-check the results against the hardware. (unfortunately, I can't attach an Excel file).

For the default horizontal bar, the correct sequence is:
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xF7
0xE3
0xF5        - checksum marker
0x9E        - checksum
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 06, 2018, 12:15 pm
mrdreambot -

I've modified the list of face array data - see the attachment.  I haven't completed it but have gone through my face array designer and verified the hex bytes and checksums.  Try these and see if they work.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 06, 2018, 12:44 pm
BMD1103,

Thanks for spending time on your trip to do this. I am using my own code. Using your new data, it is still not working for me. I have the following:

FF FF F1 E6 E4 B1 7F 7F 7F 7F F1 E6 E4 F1 FF FF F5 2D
Checksum: 2D vs EC
F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 F7 E3 F5 9E
Checksum: 9E vs 9E
Starting Max Tests...
FE FE FE FE 0 - 0
FE FE FE FE 1 - 0
FE FE FE FE 2 - 0
FE FE FE FE 3 - 0
FE FE FE FE 0 - FE
FC FE FE FE 1 - 0
FC FE FE FE 2 - 0
FC FE FE FE 3 - 0
FC FE FE FE 0 - 6
Last device has been discovered...
Face: Connected at position: 0
Device #0: Face
0 FF 0 FF 1 - 0
0 FF 0 FF 2 - 0
0 FF 0 FF 3 - 0
0 FF 0 FF 0 - 0
Face: Connected at position: 0
Device #0: Face
0 FF 0 FF 1 - 0
0 FF 0 FF 2 - 0
0 FF 0 FF 3 - 0
0 FF 0 FF 0 - 0

This first array is the happy face in your latest pdf. Note that the checksum is different from using the algorithm you posted. The second array is the horizontal line. The checksums agree.

The exchange is similar to your working observation. After sending 0 FF 0 FF x - y 2 times, I waited for 30 ms before sending the array MSB first. I tried sending them MSB first and LSB first and no LED was lit. Just to confirm, there is a start bit consisting of -132 +564 -140 ie, 132 us low, 564 us high and 140us low, which is followed by the values of the array. And there is no stop bit. Is this correct?

BTW, don't ruin your holidays working on this. It can wait. I can work on other aspects of the project.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 06, 2018, 02:54 pm
No problem- it's too hot here (in the UK) to do a lot ( - and my room is on the shady side of the house).

I'm working with a timing base of 140 us. The "preamble" is 1 time interval LOW, 4 HIGH, and 1 LOW.  Then each message bit is made up from 1 HIGH, 1 HIGH or LOW depending on the data bit, and 1 LOW.  There is something at the end of the message but I have not been able to resolve it - it looks as if there is possibly some tri-stating going on as there is a definite exponential charge curve from LOW to HIGH,  followed by a LOW. It looks as if I'll have to check that out when I get home.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 07, 2018, 01:00 pm
Success at last! All that is missing is a stop bit. After the start sequence followed by the data, you still have to send a stop bit consisting 550 us high and then low.

You have to precede the sending of the image data by the data stream (00 ff 00 ff) every time you want to update the Face:

Face: Connected at position: 0
Device #0: Face
0 FF 0 FF 1 - 0
0 FF 0 FF 2 - 0
0 FF 0 FF 3 - 0
0 FF 0 FF 0 - 0
Displaying happy face...

Here are photos displaying a happy face and a sad face.
 
BTW, the check sums of the faces in your latest pdf are not correct. Have to replace them with the check sums calculated using your algorithm posted.

Thanks for your help! Enjoy your stay in the UK ;-)
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 09, 2018, 09:33 am
Great! - so the start sequence (140 us LOW, 560 us HIGH, 140 us LOW ) needs to be repeated at the end.

I've attached my Excel spreadsheet for you to try out and check - should make it easier to come up with other face patterns.  It includes the checksum calc. as per my algorithm.  Hopefully, its operation is explained adequately.  I might play with it a bit more to make it less likely to be tampered with.  The password is Max.

I want to use the display to show dynamic patterns, and that's going to be quite hard on processor resources, so I;m thinking of getting hold of a Nano and using it as a dedicated processor - pass the Nano a pattern and it takes care of the updates etc.

Anyway, thanks for your help and I hope to have a few things to show you once I get back to base.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 09, 2018, 11:31 pm
No need for the initial LOW as the previous bit will always end with a LOW. After sending the 18-byte pattern, just send a 550 us HIGH following by LOW and don't have to time the LOW, just set it to LOW

Let's have a quick calculation (4 x (6 + 1) + 18) bytes x 10 bits/byte x 430 us/bit = 197,800 us or roughly 200 ms to update the face pattern. This means that you can update the face at a maximum of 5 times/sec. Limitation is the protocol and not the speed of your microprocessor.  Owing to the weird protocol, certain exchanges using HIGH/LOW to represent 1/0 and others using duration of the HIGH pulse to indicate 1/0, you can't use a comm port. I have to use bit-banging tying up all microprocessor resources. This means, yes, if you have to update the Face at more than twice a sec, you'll have to use a dedicated processor or don't have any resources left for other control functions.

I shall experiment with your images and do a scrolling text message on the Face and see how it goes during the weekend.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 10, 2018, 04:38 am
The Face is the only device in the chain. Maybe we can optimise a bit by communicating to 1 device instead of 4, no response from non-existent devices anyway. This means that: ((6 + 1) + 18) bytes x 10 bits/byte x 430 us/bit = 107,500 us or roughly 110 ms meaning you can update the Face 9.3 times/sec. With this optimisation, you may not need a dedicated microcontroller for the face if you only need to update the Face 2 or 3 times a second.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 10, 2018, 11:41 am
Tested it. The proposed optimization does not work. The devices will not respond with the device type unless all 4 potential modules on the chain have been polled even though there is only 1 device on the chain.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 11, 2018, 02:00 am
Here is a video on scrolling text to the left at the fastest achievable speed on the MAX. It ties up all resources on the Arduino UNO.

Video too big to upload here. Watch it here instead: https://youtu.be/8_z30KEClWs
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 11, 2018, 08:15 am
I wondered about the need to address all 4 positions on the chain ...

I'll need to look at the data stream when the default pattern is being displayed - that seems to update quite quickly.  I on't remember there being any serial transmissions between the graphics. I'm using Serial1 and INT3 on a Mega - the Nano also has a serial part apart from the USB so may be able to use that.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 11, 2018, 09:37 am
Sending of image from Arduino to Face is not using serial connection. Serial connection can be used like you did in the 6-byte polling of the devices. You are using interrupts to receive data back from the devices. And you can also use interrupts to send data to the Face. Your Arduino Mega has 4 serials which are sufficient to communicate with 4 chains in the MAX. I don't have a Mega, only an UNO and I have to use bit-banging to do all 3: polling devices, reading 1-byte responses and sending image to Face. Using serials and interrupts is more efficient in using resources but more difficult to program and debug. On the other hand, using bit-banging is not making efficient use of the resources.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 11, 2018, 03:41 pm
Even with a Mega I think I'll need a dedicated processor for the LED array to get reasonable performance. The 140 us time interval isn't a lot to do much other processing for the array, and the 3 extra serial ports will allow a LED array and a maximum of 8 other devices.  With 2 smart motors and the IR sensor (thanks for that - I don't know where I got the ultrasound idea from!) and 4 servos, the Mega is going to be a bit limited in what it can handle.

Never mind - at least we now know some of the limitations to be dealt with.  I still think there is quite a bit of potential with the MAX, even with the mix of protocols.  I think I'll have a look at what's involved in interfacing other devices to the protocol while I can't get my hands on the hardware.

Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 12, 2018, 12:26 am
Back to my optimization proposal: I found that initially you need to poll all devices until you get the Face to respond with a device type 6. After that, you can just poll the face by itself without polling the other 3 non-existent devices: 1, 2 and 3. The original savings calculation is still correct. The scrolling text is much smoother and twice as fast as before.

When you are back home having access to your hardware setup and oscilloscope/datascope, could you investigate the following please:

1) IR - at one time, I was able to read the distance by issuing the 0xa0 command to the device and it responds with a value. And I can map the response using a formula to get the distance. I forgot which command has to precede that. But now, I cannot repeat it anymore. Command 0xa0 always returns the same value! Could you investigate what is the command sequence that gives a reliable reading? This one is not as important as the next item because I am planning to dump the MAX IR sensor and use more than 1 Sharp IR Sensors or Ultrasonic sensors in its place. It is such a simple sensor and I don't want the protocol overhead. The replacement sensors are easy to program using Arduino. And I am planning to add a camera to MAX to support computer vision control. Will talk more about this and remote control via WIFI later.

2) The MAX motors - you identified the forward and backward commands. Are there other commands eg, controlling the speed, stop, etc. It appears that if you don't send them forward/backward commands for a while, the motors will stop. There seems to be several commands that stop the motor. I am using 0x30. I have to retest this.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 15, 2018, 12:25 pm
Here is a video  (https://youtu.be/NOOaM0nRsrQ)showing control of the Meccano MAX's Face, Motors and Servos using an Arduino UNO.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 20, 2018, 11:25 am
Submitted this project to hackaday.io (https://hackaday.io/project/160606-hacking-the-meccano-max). You may follow it to see my progress.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 30, 2018, 06:10 pm
I've started to look at what's involved with the Nano for this application.  One slight complication - the Nano doesn't have separate serial and monitor pots as I supposed, so I have to use Software Serial.  I've modded the standard SS library to handle the 8N2 serial format and will try it out when I get home next week.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 31, 2018, 07:20 am
Or you can use your Nano and my Arduino Library for Meccano MAX (https://github.com/MrDreamBot/MeccaChannel) which uses bit-banging instead of a com port to control MAX's face. The com port can then be used for the serial monitor. ;-)

And if you have time, have a look to see how to consistently get the IR sensor to report the distance (value returned by sensor and the distance is not a linear function but we can work it out). And also if there are commands to change the speed of the motors or keep the motors running without having to periodically send them a command.

Getting home sick?
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Aug 31, 2018, 11:42 am
Looks like I've got a month's worth of things to do when I get back ...

btw, I've just found https://github.com/anotherAlex154/MeccanoidForArduino which might be worth looking into - haven't had a chance yet. Perhaps a joint effort may be in order.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Aug 31, 2018, 12:28 pm
I've seen it. You should look at my Arduino Library which is designed for the Meccano MAX instead of the Mecanoid. My library contains an example which exercises all devices except the IR sensor. Run it using your Nano and see how it works.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 16, 2018, 03:29 am
Hi mrdreambot,

I'm back in action.
My first activity has been to look at the signals at low level, and I've had a couple of surprises.  I wrote an app for the Mega that just looks at the times between transitions on the signal line between the Meccabrain and the display module.  I had to use the Mega as there is a LOT of data to be stored - upwards of 2000 items to get useful results.

I first ran the program looking at the start-up sequence - see the file.  (I've deleted a lot of repeats to save space, but nothing of significance.)  I can't see anywhere in there that is a true serial sequence of FF 00 FF 000 FF 00.  There is also no serial transmission between the blank screen for startup and the default sequence.  The different sequences for the various forms of the default follow on one from the other with no serial message between them, which is in line with what I see  with the oscilloscope.

I also managed to get a printout for a change in display using the programming mode to go from LOL! to BYE.  Again, there is no indication in the timing of any serial strings between the two.

I'm currently working on getting the Nano to go - so far I've managed to get a software serial port running with the 2 stop bits needed, and am looking at how to connect up the hardware.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 20, 2018, 11:11 pm
btw, your timings in #29 are based on 10 bits/bye.  There are only 8 bits/byte in the face display.  There are 6 'ticks' needed for the preamble: 18 8-bit bytes at 3 'ticks'/bit = 18 x 8 x 3 = 432 'ticks' for the display itself: and 4 more ticks needed for the stop bit -  a total of 442 ticks.  At 140 us /tick, that is 61 ms - about what I see on the oscilloscope display.  The original has about 32 ms between successive writes to the display - so we should be able to get better than 10 updates/second.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Sep 22, 2018, 12:34 am
Greater than 10 updates per seconds is good. What are the objectives of your project?
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 22, 2018, 03:50 am
I can now report success with sending a display!  Routine is attached.

It just sends the command string in the "configure" routine, then moves on to the wrtDisplay function.  Without the diagnostic Serial.writes I'm getting less than 75 ms between updates - about 14 /sec.

I've set up the display bytes in an array so that I can scroll between them initially, to see if I can get some fairly rapid movement.  The preamble, message, checksum flag and checksum are converted into bits in a bit array, which is then read on each timeout of the 140 us clock and sent to the output port.

This is running in a Mega at the moment - 5000 bytes of program memory, 938 bytes of dynamic memory. (I used the extra capabilities of the Mega to help with diagnostics - now to see if it'll run in a Nano ... )

At this stage, I'm exploring the capabilities of the system to see just what it can be made to do.  Ultimately, I'd like to be able to add other non-Meccano sensors (using simpler interfaces) but use the servos and motors which are much easier to interface mechanically with the Meccano hardware.  I have used my 3D printer to make up some servo mounts for RC-type servos which have the 1/2" mounting holes etc.  I'm keeping an eye on TradeMe (NZ equivalent of eBay) for unwanted products so I can get some more of the smart servos etc.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Sep 22, 2018, 11:24 pm
Interesting. Which 3d printer would you recommended? I'd like to get one!
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 25, 2018, 12:32 am
I've got an XYZ Da Vinci 1.0 - a bit dated now.  It had a few teething issues but seems to be fairly reliable now.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 25, 2018, 10:25 pm
I have the Nano version going.  Video is attached.

In the end, I simply "translated" the code from the Mega (which used pin 18 as TX1 to send the serial, and as a straight digital output to send the PWM,) to the Nano using pin 1 as TXD for the serial comms and as D1 for the PWM.  I'm not using the incoming signal from the module in any way.  I've lost the ability to use the serial monitor for debugging, but have used a LED array (as seen in the video) to see what is going on.

There is a difference between the Nano and the Mega versions which means I have to slow down the refresh rate with the Nano.  However, that will give me about 100 ms between updates to do other things.  I want to see if I can use a Mega as a master, feeding screen displays to the face array on demand (for instance, a left arrow a couple of seconds before doing a left turn.)
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Sep 25, 2018, 11:26 pm
Nice video. I like it. BTW, if you were to buy a new 3D printer, what would you buy? And what is the price range for a usable one, I mean not Micky mouse one.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 27, 2018, 01:34 am
1) IR - at one time, I was able to read the distance by issuing the 0xa0 command to the device and it responds with a value. And I can map the response using a formula to get the distance. I forgot which command has to precede that. But now, I cannot repeat it anymore. Command 0xa0 always returns the same value!
On start-up, after the standard sequence, the command is FF DF FE FE FE 9n.  However, this does not appear to be an active request for info as 0x00 is returned.  It may be a "keep awake" check of some sort.

When I activate the remote controller, the message changes to FF DD FE FE FE 7n, and a value is returned.  The value is to be read as 2 nybbles. The most significant gives the range sensed by MAX's left side sensor, with the less significant giving the range from the right sensor.  So a return of 0xD8 would indicate something about 120 mm away from the right sensor.  Approximate checks give a range of 50 mm for a return of 0x22, 100 mm for 0x66, and 150 mm for 0xAA


2) The MAX motors - you identified the forward and backward commands. Are there other commands eg, controlling the speed, stop, etc. It appears that if you don't send them forward/backward commands for a while, the motors will stop. There seems to be several commands that stop the motor. I am using 0x30. I have to retest this.
The startup sequence for the motors is:
Code: [Select]
...  Starting ...
FF FE FE FE FE A1  - ~~
FF FE FE FE FE A1  - ~~
FF FE FE FE FE A2  - ~~
FF FE FE FE FE A3  - ~~
FF FE FE FE FE A0  - fe
FF FE FE FE FE A1  - ~~
FF FE FE FE FE A2  - ~~
FF FE FE FE FE A3  - ~~
FF FE FE FE FE A0  - fe
FF FC FE FE FE 81  - ~~
FF FC FE FE FE 82  - ~~
FF FC FE FE FE 83  - ~~
FF FC FE FE FE 80  - 5
FF FC FE FE FE 81  - fe
FF FC FE FE FE 82  - ~~
FF FC FE FE FE 83  - ~~
FF FC FE FE FE 80  - 5
FF FC FC FE FE 61  - 5
FF FC FC FE FE 62  - ~~
FF FC FC FE FE 63  - ~~
FF FC FC FE FE 60  - 5
FF 0 FC FE FE 91  - 5
FF 0 FC FE FE 92  - ~~
FF 0 FC FE FE 93  - ~~
FF 0 FC FE FE 90  - 0
FF 0 0 FE FE C1  - 1
FF 0 0 FE FE C2  - ~~
FF 0 0 FE FE C3  - ~~
FF 0 0 FE FE C0  - 0
FF 0 0 FE FE C1  - 1
FF 0 0 FE FE C2  - ~~
FF 0 0 FE FE C3  - ~~


The " 0 0" command group is the quiescent one, with nothing running.
check
The motor control codes are complex, and there appears to be a "keep awake" here.  The static sequence is the FF 00 00 FE FE Cn group as above, but there are occasional appearances of FF 20 20 FE FE 10 as well.

When I use the programming tool to "Roll Motor 0 forward at a slow speed" there is a sequence:

Code: [Select]
FF 0 0 FE FE C0  - 0
FF 0 0 FE FE C1  - 2
FF 0 0 FE FE C2  - ~~
FF 0 0 FE FE C3  - ~~
FF 0 0 FE FE C0  - 0
FF 0 0 FE FE C1  - 2
FF 0 0 FE FE C2  - ~~
FF 45 20 FE FE 93  - ~~
FF 24 0 FE FE 40  - 0
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 20 FE FE 60  - 0
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 8
FF 24 0 FE FE 41  - 2
FF 24 20 FE FE 62  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - e
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 20 FE FE 60  - 14
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 1c
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 20 FE FE 63  - ~~
FF 24 0 FE FE 40  - 22
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 28
FF 24 20 FE FE 61  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 30
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 20 FE FE 63  - ~~
FF 24 0 FE FE 40  - 35
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 20 FE FE 60  - 3c
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 44
FF 24 0 FE FE 41  - 2
FF 24 20 FE FE 62  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 4a
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 0
FF 24 20 FE FE 61  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 8
FF 24 0 FE FE 41  - 2
FF 24 20 FE FE 62  - ~~
FF 24 0 FE FE 43  - ~~


If I start the same motor forward in the "fast"mode, the sequence is:
Code: [Select]
FF 4A 20 FE FE E1  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 24 0 FE FE 40  - 38
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 20 FE FE 63  - ~~
FF 24 0 FE FE 40  - 43
FF 24 0 FE FE 41  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~


For Motor 1 (MAX's right) the initial code is FF 20 45 FE FE 91 for slow; FF 20 4A FE FE
 with the only difference being the initial 4A instead of 45.  So it looks like the rotation direction is given by the ongoing command - 24 for forward, 34 for reverse - with the speed given by a command 4a, where a varies depending on the desired speed. This will need to be checked.


To stop a motor, use a speed value of 40.  The actual sequence to stop motor 1 is:
Code: [Select]

FF 0 24 FE FE 40  - 1e
FF 0 24 FE FE 41  - e
FF 0 24 FE FE 42  - ~~
FF 20 24 FE FE 63  - ~~
FF 0 24 FE FE 40  - 1e
FF 20 40 FE FE 31  - 15
FF 0 20 FE FE F2  - ~~
FF 0 0 FE FE C3  - ~~
FF 0 0 FE FE C0  - 1e
FF 0 0 FE FE C1  - 1a
FF 0 0 FE FE C2  - ~~
FF 0 0 FE FE C3  - ~~


and for Motor 0 :
Code: [Select]

FF 24 0 FE FE 40  - 40
FF 24 20 FE FE 61  - 2
FF 24 0 FE FE 42  - ~~
FF 24 0 FE FE 43  - ~~
FF 40 20 FE FE 30  - 47
FF 20 0 FE FE F1  - 2
FF 0 0 FE FE C2  - ~~
FF 0 0 FE FE C3  - ~~


There's a lot to digest here, and I can't see what the significance of the returned value is.  Perhaps a check in the LIM mode will help.

I hope that makes some sense to you!
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Sep 27, 2018, 10:00 pm
Note:
Just to add to the confusion -
When the programming tool talks about "forward" and "backward" it does NOT refer to the direction of movement. The hex value 0x24 will turn both motors clockwise when viewed from the outside - for motor 0   MAX's left) this will actually move the device backward.  So to get forward motion the code has to be FF 34 24 FE FE ci, and for reverse motion it will be FF 24 34 FE FE ci.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Sep 27, 2018, 11:07 pm
I was yet to absorb the previous post. Information overload !  :smiley-confuse:  :o  :)
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Oct 02, 2018, 04:36 am
It gets worse - if I look at what the standard Meccabrain is sending to the motors, I find a lot of different codes.  The starting sequence is 25 bytes long.  This is followed by 14 groups of FF 00 00 FE FECn, then 101 groups of FF 81 81 FE FE 0n (where n is the module no in the string).  Then 2 groups of FF 00 00 FE FE  for modules 0 and 1.  Instead of 24 and 34 for the motor move commands, it uses 26 and 36.  There is also the odd few groups of FF A0 A0 FE FE.

Anyway, the good news is that I have finally got a program running that does what I want it to do, and allows me to inject commands into the motors from the Mega.  This will let me inject various combinations and see what happens.  It works without any of the extraneous messages involving 45, 4A, etc, so I don't know how these values affect the speed.  I'll see if altering the move command value between 34 and 32 changes the speed.

I am also starting to see some sense in the returned values.  For motor 0 running forward, the returned value decreases.  With the rest value initially 0x42. the sequence after starting is (all hex) 42, 40, 3C, 38, 35, 31, 2E, 2B, 27, ...  Running the motor in reverse, the values increase instead of decrease.  It looks as if the returned value is the position of the motor - I presume it's a stepper of some sort.  The range seems to be from 0 to 4F.
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Oct 02, 2018, 06:12 am
I've just checked the speed thing.  The values from 0x42 to 0x4F set the speed for the motor - 0x41 doesn't do anything.  So each wheel can be set to rotate at a different speed if required.  Speed with 4F is about 0.4 revs/sec: 43 is about 1/4 that speed.  The value is saved so it's probably safer to set the speed for each motor as part of the sequence.  So for maximum forward movement, use 0xFF 0x4F 0x4F 0xFE 0xFE  before the movement.  For consistency it's probably best to clear the speed memory with 0x40 when done - this is what happens with the programming mode.
Title: Re: Meccano MAX and Arduino
Post by: mrdreambot on Oct 02, 2018, 11:25 pm
Who designed such a noisy, messy protocol? Why? My head is exploding >:(  :o
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Oct 03, 2018, 01:51 am
Certainly not in the Frank Hornby tradition!
Title: Re: Meccano MAX and Arduino
Post by: bmd1103 on Oct 04, 2018, 12:22 am
The motor response indicating position can go to 0 - this makes it incompatible with the standard library as that assumes that a 0 response means that there is no module present.