lego ir receiver problem

lego ir receiver problem

lego ir receiver instructions

Lego Ir Receiver Problem

CLICK HERE TO CONTINUE




You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.Some while ago I started using a Raspberry Pi to control my Lego. It all started when we wanted to figure out if we could run standard Java on the Raspberry Pi. Instead of writing “Hello World” – we wanted to do something cooler. We decided to use Java and later Scala with Akka on the Raspberry Pi to control Lego trains. In the end we could control the speed of the trains, play train sounds, get a live video feed from the train and retrieve the location of the train based on a RFID reader and some RFID cards. Later we expanded it even further by automating track switches, ferris wheels, Lego technic cars and planes. I noticed there was quite some interest in the setup so I started giving presentations about it at conferences. By now I don’t even know how many times I presented the session. You can watch the Devoxx UK video if you want to learn more.




One of the questions I often get from the audience was whether or not the code is available as open source. Unfortunately quite some parts of the code were written under time pressure and I didn’t dare to release it to the public. Another challenge was the fact that you need to execute quite a few commands in Raspbian to enable infrared and other functionalities. In the end I decided to make the software available and easy to install for everyone. Recently I made a start and published parts of my work to two GitHub repositories. One repository has a Spring Boot application that offers REST endpoints. The other repository contains the scripts to enable the infrared and camera. In the rest of this post I will explain how you can convert your Raspberry Pi to a device that can control your Lego. With “Lego” I mean any Lego that has a Lego infrared receiver; so you can control trains, cars, planes etcetera. Before you start you need to get some ingredients. To make it easy for you I made a shopping list.




It will cost you around 40 euro if you haven’t got any of the ingredients. If you have the Raspberry Pi Zero, you need the following extra ingredients: Optionally you can also buy an official Raspberry Pi Camera Module and connect it to your Raspberry Pi. Bear in mind that if you have a Raspberry Pi Zero you need a special adapter. Lego offers two standard Lego infrared remotes, you can see one of them in picture 2. These remotes have some disadvantages. The reach is quite poor, I could no longer control my train when I drove it from my living room to the kitchen. Next to that there are only 8 channels available which basically means that the number of devices you can control is limited. The solution is quite simple, we replace the standard Lego infrared remotes. The replacement for the standard infrared remote is a Keyes infrared transmitter as shown in picture 3. The pins from left to right are GPIO17, 5V and GND. Connect those pins to the respective Raspberry Pi GPIO pins with jumper cables as shown in picture 4.




The best solution to enable our Lego devices to move freely is to use an USB WIFI dongle and a small powerbank. Connect them as shown in picture 5. With our power bank we can power a Raspberry Pi for quite some hours. Optionally you can connect an official Raspberry Pi camera as shown in picture 6. That camera enables you to stream full HD video for instance from the top of the train. Actually the RPi Cam Web Interface application used in my scripts does not stream video, it refreshes pictures. However you probably won’t notice it as it goes really quick. When you want to stream video from a Raspberry Pi you have two options: a delay of a few seconds, or a solution that requires specific software. As I didn’t wanted to have around 5 seconds delay or a solution that only worked with VLC, I ended up with this solution. I can highly recommend the RPi Cam Web Interface application if you want to do something with a Raspberry Pi camera. After assembling the Raspberry Pi and the other hardware it’s time to setup our electronic Lego components.




The Lego infrared receiver is shown in picture 7. The orange bar indicates which channel the infrared receiver is listening on. If you have only one receiver it’s best to select the channel at the top, which is channel 0. This enables you to use a simpler way of calling our application. In picture 8 you can see how you can select another channel, in this case channel 1. The back of the infrared receiver in picture 9 has two connectors, these are called outputs. The connector to the left with the engine connected to it is output 1. The connector to the right with the LEDs is output 0. If you only have 1 channel and 1 output, use output 1 as it enables you to use a simpler variant of the application. Don’t forget to connect a battery box as shown in picture 10. Lego has a few different types of battery boxes, it doesn’t really matter which one you use. At some point you have to configure your wireless settings in Raspbian. I’ve opted to install all the software via a wired connection and configure wireless after everything is ready.




But you can also opt to configure the wireless now and don’t use a wired connection. To configure wireless open the wpa_supplicant file on the Raspberry Pi (sudo nano /etc/wpa_supplicant/wpa_supplicant.conf) and add the following section. Don’t forget to change it to match your routers configuration. Install Raspian on a SD Card and use SSH to connect to the Raspberry Pi. The default username is ‘pi’, the default password is ‘raspberry’. If you don’t know the IP address of the Raspberry Pi then you can use something like ‘Advanced IP Scanner’ to figure it out. After logging in to the Raspberry Pi you can install all the software with the command below. After installing the software it’s best to reboot the system. After a reboot, the Spring Boot application will automatically start. /johanjanssen/LCCInstallScript.git && sh LCCInstallScript/script.sh If you only have one infrared receiver (configured at channel 0) and one output (configured at output 1) than you can use the Spring Boot application in a simplified form.




From any computer that can access the Raspberry Pi you execute the call http://[IP]:8080/intensity/[x],for instance in the browser, where X can be any number from -7 up to and including 7. Don’t forget to replace ‘[IP]’ with your IP address. will make an engine go forward or make a led shine. http://[IP]:8080/intensity/0 will stop the engine or the light. If you have multiple infrared receivers and or multiple outputs than you need to specify the channel and the output in the call. The call then has the following form http://[IP]:8080/intensity/[x]?channel=[y]&output=[z] where x is the intensity again, y is the channel and z is the output. So for instance http://[IP]:8080/intensity/-2?channel=3&output=0 will make an engine go backward with speed 2 or make a led shine if the device is connected to channel 3 and output 0. It’s possible to watch the camera feed within a browser by entering the following address: http://[IP]. Or at the default location http://[IP]/html in case the scripts are modified.




Picture 11 shows an example use case of our Raspberry Pi Lego controller with a Lego train. Picture 12 shows the same train, but now with the optional camera. You can automate more or less any Lego, especially Technic Lego. This is easy to automate as it often already contains electronic parts like engines, lights, infrared receiver and a battery box. I automated a Ferris wheel, a racecar, an airplane and a wheel loader. The wheel loader in picture 13 already contained two infrared receivers, four engines and a battery box. I just added a Raspberry Pi Zero with the infrared transmitter inside the wheel loader and I could make it move around and make it pickup items. With these instructions together with the script and the Spring Boot application it’s relatively easy to control your own Lego. You can use the setup to code/play together with kids, or just by yourself ;). It’s still work in progress, so if you have any questions or additions please contact me for instance on Twitter: @johanjanssen42.

Report Page