Home | Links | Contact |

Printed from www.nzmeccano.com

Top Home Bottom

Controlling Smart Servos with an Arduino

(Author: David Couch)

Controlling Smart Servos with an Arduino

by David Couch
 
This document describes how I set up a test and demonstration of the control of Meccano servos, of the type used in the Meccanoids, by an Arduino microcontroller. In spite of the files provided by Meccano being named MeccaBrain, this is not about programming the MeccaBrain computer in the Meccanoid.

In 2015 three documents were made available on the Meccano web site, at http://meccano.com/meccanoid-opensource The "Smart Module Protocols" button downloads a file named Meccano_SmartModuleProtocols_2015.pdf, which is a description of the communication protocol between a computer, the servos and the LED Module. The "Arduino Library" button downloads a file named meccanoid-library.zip. It contains two files named MeccaBrain.cpp and MeccaBrain.h, which are an Arduino library of code to implement the protocol and control the servos and LED module.
 

Installing the library files

 

Download the file meccanoid-library.zip and store it anywhere. Navigate to the Arduino library folder. In Windows this is normally
DocumentsArduinolibraries. In this folder create a new folder named MeccaBrain. Copy the two files from the downloaded zip file into the new folder.

Wayne Hortensius has kindly provided an additional file named keywords.txt. It is not essential but it is helpful. Its function is to make the keywords, mainly function names, in the library appear in a different colour when you edit code. The file is appended to this document. Select the text with the mouse, copy and paste it into Wordpad or another editor, and save it as keywords.txt in the new MeccaBrain folder.
 

Connecting the servos to the Arduino

 

As a test I connected the three servos in the left arm of my Meccanoid to an Arduino. The connectors used on the Meccano servos are a Futaba proprietary type known as a J connector. I bought an extension cable for this connector, like the one shown here:
http://www3.towerhobbies.com/cgi-bin/wti0001p?&I=LXH447&P=7
The servo connector is unplugged from the MeccaBrain and plugged into the female connector on this cable. I cut off the male connector, and separated and stripped the wires.

The protocols document includes a diagram showing how a servo is connected

Fig 1 The Adafruit Proto Screw Shield with the circuitry described in this paragraph

to an Arduino and a separate power supply. Two resistors are required. I built this simple circuit on an Adafruit Proto Screw Shield, as shown in fig. 1. The positive power supply lead and servo power lead (both red) are connected to the W terminal. A 22k resistor is soldered to the pad for this terminal and to another pad. A 1k resistor is soldered between this pad and a second pad. A wire connects the second pad to the pin 12 terminal. Another wire connects the first pad to the pad for the X terminal. The yellow or white data wire of the servo is connected to the X terminal. The power supply negative lead and the servo ground lead (both black) are connected to the ground terminal.

An alternative would be to solder a three-pin header to the shield, with the required connections, and plug the servo plug on to it, with an extension lead if required. 
 

The example sketch

 

I have written an example sketch which includes the code required to control most of the functions of the servos. It assumes the presence of three daisy-chained servos, as in the arm of a Meccanoid KS, but it will probably work with the two servos of the smaller Meccanoid. After uploading the sketch to the Arduino, open the Serial Monitor to see the output from the sketch.

The sketch does the following:
(1) Establish the communication with the servos. The Serial Monitor displays the values sent to and received from the servos.
(2) Move each servo back and forth three times.
(3) Cycle through the colours of the LEDs in the servos.
(4) Put the second servo in LIM mode and repeatedly read and display its position. If you move the servo by hand you will see the values changing.

For a copy of the sketch file please send email to david.couch46@gmail.com 

 

Module data

 
The list of command and data values given in the protocol document is incomplete. Here is the complete list, from both that document and MeccaBrain.cpp:

FF    Header byte
FE    ID not assigned
FD   Erase ID (resets Smart Module)
FC   Request module type
FB   Reserved
FA   Set LIM mode

Servo colour setting
F7   White
F6   Cyan
F5   Magenta
F4   Blue
F3   Yellow
F2   Green
F1   Red
F0   Off

Values from 00 to EF are defined as position data. However the library will send only values from 18 to E8. The range of reported position values I have seen is 04 to E9.
 

The file keywords.txt

 

#######################################
# Syntax Coloring Map for MeccaBrain
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

MeccaBrain KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

outputByteInfo KEYWORD2
inputByteInfo KEYWORD2
inputBytesInfo KEYWORD2
checkSumByteInfo KEYWORD2
servoPositionsInfo KEYWORD2
moduleTypeInfo KEYWORD2
moduleNumInfo KEYWORD2
getLEDorder KEYWORD2
getLEDbyte1 KEYWORD2
getLEDbyte2 KEYWORD2
setLEDColor KEYWORD2
setServoColor KEYWORD2
setServoPosition KEYWORD2
setServotoLIM KEYWORD2
getServoPosition KEYWORD2
communicate KEYWORD2
sendByte KEYWORD2
receiveByte KEYWORD2
calculateCheckSum KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

 

If you have any interesting information or comments about this page, please add them here:


Your name:
Your message:
Security check: (Please type in the text to prove you're a person!)
 
Login status:  You have not yet entered your user name and password. You cannot create or edit documents until you do.
Enter your user name and password to log in

Remember me

If you click on the box marked 'remember me next time', you will not have to log in again on this computer for three months.

If you don't have a user name yet, please click here

On this page...

Latest documents:

 
103rd Meeting Model Report 
 
by Peter Stuart, Meccano Modellers Association Sydney Inc 
(Richard Smith and Neil Bedford)
Midlands Meccano Guild
102nd Meeting Model Report 
into a forum thread 
(John Rogers & Colin Bull)
Midlands Meccano Guild
101st Meeting Model Report 
Spanner Challenge 
(John Rogers and Neil Bedford)
Midlands Meccano Guild
100th Meeting Model Report 
 
A G gauge model 
(Colin Bull & Richard Smith)
Midlands Meccano Guild
99th Meeting Model Report 
98th Meeting Model Report 
 
97th Meeting Model Report 
(David Couch)
The Little Tram
An introductory Arduino project 
(G. Eiermann and M. Schild)
A Short History of MARKLIN Metall
 
96th Meeting Model Report 
83rd Meeting Model Report 
 
82nd Meeting Model Report 
Picks up three golf balls 
(Roger Marriott)
Midlands Meccano Guild
95th Meeting Model Report 
The Spanner Challenge 
 
 
 
94th Meeting Report 
(Andre Theberge)
Meccano Segway
Instructions 
(Andre Theberge)
A Meccano Segway
Arduino code 
(Andre Theberge)
A Meccano Segway
Assembly instructions 
(Michael J. Walker)
Meet the new MMG President
Geoff Wright 
The Spanner Challenge 
(Michael Walker)
Midlands Meccano Guild
93rd Model Report 
Report by Michael J. Walker. 
92nd Model Report 
(Stan Knight)
Minimal Meccano
Pocket Meccano Sets of the 1970s 
Little Lever, Bolton 
The Spanner Challenge 
91st Model Report 
(Bob Thompson)
Back to the beginning
Shop Display Model 
90th Meeting Report 
(Old Blue Gold)
Getting Old
A screwy story 
The Spanner Challenge 
Model report written by Michael J. Walker 
76th Meeting Report 
Exhibition in Nelson, New Zealand 
(Barry Gerdes)
Meccano Radio
 
 
How to flatten  
(Rod Socket)
Dear Mrs Spanner
Survival techniques for the Meccanoman's wife 
(Stan Knight)
The Top Ten Tools
Indispensable Tools for the Meccanoman 
A call for help 
The Spanner Challenge 
 
For small brass and nickel parts. Also for stripping paint and rotted zinc plating. 
(Stephen Heafield)
Waterslide Transfers
Refurbishing 0 & 00 Aero Models 
Construction details 
or Put Your Hammer Away 
Mobile Morris Crane from 1968 MM 
Bert Love's Blocksetter in colour 
The dangers of internet auctions 
(Rob Thompson pp Terry Bullingh)
BlockSetter Tower
Built by Terry Bullingham 
(Rob Thompson pp John Reid)
Captain Robert Falcon Scott
1912 Polar Sledging Party 
(Niels Gottlob)
Bucket Wheel Excavator
Transcribed from typed document with photos 
Selected Spanner messages 18th to 24th January 
Selected Spanner messages 11th to 17th January 
Selected Spanner messages 4th to 10th January 
 
(Norbert Klimmek)
Hulett Ore Unloader
A 1 to 32 Scale Model 
 
(Joe Attard of Malta)
A model ship
 
 
 
(Arup Dasgupta (ISM 652))
My E15R Motor
A repair story 
(Charles)
About Meccano
What is Meccano? 
Thoughts about modern Meccano 
Not many in this condition I'll bet! 
Some hints and tips 
 
 View all | Chat | Models | Hints and Tips | Opinion | Reviews | Mine