It started with the idea to make a technical proof of concept combining the Physical Web and WebBluetooth.
The Physical Web is an effort by Google to allow interacting with "things" without fiddling around with installing apps or setting anything up. The basic idea behind that is that the "thing" broadcasts a web URL for the client to interact with it. You can read more about it here: https://google.github.io/physical-web/
WebBluetooth is a JavaScript API currently in the works by a community team. This API allows websites (or WebApps) to interact with BLE devices using the GATT profile. Google has done a reference implementation currently working on Android 6, Chrome OS and Linux in combination with Chrome. (https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web)
Combining these two technologies allows a "thing" to be controllable by a client (e.g. an Android device) without any app installation and without the thing having to be connected to the internet. The presence of the "thing" will result in a notification in Android and tapping on it opens the WebApp in Chrome allowing to control the thing.
A first test was switching a LED controlled by a Raspberry Pi on and off using a website. But that wasn't "cool" enough and no real challenge so we decided to make a Lego technic car remote controllable and do the same thing with it.
This is how this project came to life and now we want to share what we have done so that other technology enthusiasts can use this work to build their own stuff.
The modelsThe first step is to get the Lego Technic model ready. We used the following models:
42035 (Dumper)
This model is relatively cheap and small and given the load area there is plenty of room for the electronics and the battery pack.
We replaced the Lego motor simulation with a Lego M motor using the power transmission the other way around. We also added a Lego differential to have a perfect power transmission to the wheels.
We removed the mechanics to move the load area and made the load area fixed to have space for the servo.
42041 (Race truck)
The race truck is very easy to modify. By setting the semitrailer coupling a bit higher a Lego technic L motor perfectly fits underneath it. The servo can be put next to the steering axis. The Electronics all fit into the driver's cab and the battery pack (a 14500/AA one) fits perfectly between the driver's cab and the heat protection shield.
42039 Model B (Race Jeep)
This model is the most heavily modified one we have. The Main problem is that the model is so heavy that a single L motor didn't have enough power to move it forward (in fact he was but the acceleration has been very bad). So we had to put two L motors to the engine compartment. The power transmission to the back axis hasn't been made for that amount of power so that the gears jumped and had to be strengthened,
The two features of this model (movable front lights and trunk) were modified to be driven by two separate motors without the need for a manual switch.
ElectronicsThe final version of the electronics is a separation of the control part (the part that gets connected via Bluetooth and contains the car specific logic) and the hardware driving part (the part generating the electrical signals to drive the motors, the servo and the LEDs).
Mainboard
The Mainboard has been designed to be car independent. All the car specific parameters are controlled by the control board so that every Lego car uses the same mainboard containing the same software.
We used the same 470 Ohm resistor for every LED that gets plugged into the mainboard. We did this to be color-independent. If you are sure what colors you use for what LED you can solder the appropriate resistor for 5V and the chosen color to the Mainboard.
Control board
The Control board is car dependent. It knows what specialities the model has and defines what features are supported (via profiles).
Making it
Depending on your experience regarding electronics and the amount of time you want to use for this project you have the choice for how to get the electronics done:
1) Build everything your own. You can just use the Fritzing diagram to get the schematics and use a perfboard to wire everything yourself. This can be time consuming and error prone (if you aren't experienced in doing this)
2) Order the mainboard as a pre-made PCB. All the data needed is already inside the Mainboard.fzz (see attachments) Fritzing diagram. We tested DirtyPCB and Elecrow and ordered some mainboard PCBs there. Both are OK. DirtyPCB sent more than ordered but some of them aren't working (you have to test them before you start soldering anything on it) and Elecrow sent fewer but the number of broken ones is much lower. If you want to be on the safe side you can use the built in Fritzing Fab service. It is more expensive but worked really well in test.
The control board only has a few connections so we decided not to order a PCB for it but to use a perfboard and solder the connections ourselfes. The ControlBoard.fzz (see attachments) contains two layouts (one used for the bigger models and one used for the Dumper) but feel free to rearrange it to your needs. Just make sure the connections stay the same :)
For a detailed guide how to flash the right software onto the controllers please refer to the GitHub project. The ReadMe files there explain what you have to prepare and do for getting the software onto the hardware.
Power supplyThe mainboard handles the power conversion for the AVR and the Control Board (as it gets the power via the Mainboard). So basically you can use any Voltage that the D24V6F5 can handle (7-42V). Please keep in mind that the motors and the motor drivers also have to handle this voltage. Lego motors get operated at 9V when used with original Lego parts. We use 3 3,7V cells to power our models which works really well so we recommend doing this.
We also would recommend using 14500 Lithium batteries (protected ones!) because they fit really nice into AA housings and therefore the number of housings available on the market is very high and you can choose whatever housing fits best for your model.
Just make sure that the housing makes a serial connection between the three cells (or modify the housing to do so) so that you get around 11,1V.
5mm LEDs fit exactly into the Lego technic holes. Depending on the model we had to build some options for LED carriers because the model itself didn't have enough free holes pointing to the driving direction.
We decided to not solder the LEDs directly to the cable but to use plugs for every LED connection. This leads to a very high number of plugs to crimp but this way it is much easier to switch broken LEDs or change the color of a special functionality. (White reverse driving lights? Just lets take blue ones today!)
We didn't use a original Lego servo because it is very bulky. The 9g servo we used is really small and has enough torque to handle the steering. It is very cheap also.
Lego Technic axle adapter
To combine the servo with a Lego technic axle to move the gauge we had to find a way to make a robust connection.
For this we used a small Lego technic axle cap (the one that has vertical holes left and right) and used a wire to combine it to a cutted servo horn. The servo horn was cutted to only have one hole on each side. The wire has been put through this hole, around the horn base and back up to the cap. We did this three times (center through the holes, left, right). The end of the wire has been twisted and cut off.
Hold it in place
Most models didn't have a suitable construction to hold the servo in place. So we decided to simply make a plane base for the servo to rest on and use a cable binder to hold the servo in place. Doesn't look very Lego-ish but does its job :)
LED to Mainboard connectionsWith the first models we made the mistake to use double housings for each LED plug that we wanted to plug onto the mainboard. We didn't know that two double housings next to each other are slightly wider than a 2x2 housing.
We had to modify the double housings with a box cutter to have them fit onto the mainboard.
A much better approach is to use a bigger housing for all the LED cables (in this sample we used 4x2 housings)
The Lego motors come with a Lego connection made for the Power Functions set. To use it with your own electronics you have to make another plug to it.
The cables for the motor have 4 wires. The outer two wires aren't relevant for motors. The inner two wires are connected to the motor internals and need to provide the PWM signal for spinning the motor. So you have to make a double housing plug to the end of the motor cable. Just use a box cutter to cut the outer wires around 1cm smaller than the inner wires and cut the two inner wires from each other. Remove the insulation of the inner wires and crimp a plug to them.
To have your own Bluetooth remote controllable Lego technic model you have to
- Choose a model providing sufficient space for a servo, a motor, the mainboard, the control board and a battery pack
- Modify the model so that the servo and the motor fit into it
- Solder / equip the mainboard with the modules needed (ATMega, voltage converter, motor drivers, resistors, plugs
- Solder the control board containing the RedBear DUO and the BLE Nano
- Prepare the ATMega and flash the software to it following this guide (klick)
- Setup the Arduino IDE and flash the DUO software to the DUO following this guide (klick)
- Setup the Arduino IDE and flash the BLE Nano software following this guide (klick)
- Connect the Mainboard and the Control board (be sure to connect RX to TX)
- Connect the servo with the steering mechanics
- Replace the motor plug with a double Dupont plug
- Connect the battery pack, the servo, the motor and as many LEDs as you like to the mainboard
- Use your favorite remote control application and start driving around
The whole project like described here is working but we still want to extend it a bit:
- When AngularJS 2 cli supports the mobile (offline) mode again the application shall become a mobile (offline) application that can be pinned to your Android desktop and then be used as an installed app
- We are currently working on a branch in the source repository that extends the mobile application as well as the embedded application to support dynamic profiles. This means that all the car dependent parameters are no longer coded into the Redbear DUO software but can be configured via the WebApp / Android App the configuration then gets persisted in the car. This allows to have one software stack for the whole car.
Comments