Daily Archives: September 17, 2018

How to Simulate the Raspberry Pi?

You may have an urgent project that requires the use of a Raspberry Pi (RBPi), but do not have immediate access to a physical kit or the SBC. However, that should not hamper your progress with the project, as Microsoft is now offering an online RBPi simulator. The online RBPi simulator allows users to write code for controlling emulated hardware. Therefore, for the present, users can interact with a sensor to collect data from it and control an LED.

On the simulator, the user has a graphic of an RBPi wired on a breadboard to a combined humidity, temperature, and pressure sensor, along with a red LED. On a side panel, the user can enter JavaScript code as Node.js, with which, they can control the LED while collecting dummy data from the simulated sensor. A command line at the base of the panel allows execution of the code.

When loaded, the simulator starts with a sample program, which the user can use to collect temperature from the sensor and display it on the command line. Tutorials are available from Microsoft on running this code, and for this, the user has to first sign into Microsoft’s Azure IoT Hub, and select the free tier service option. Microsoft has designed the simulator to be compatible with a real RBPi. Therefore, anyone can test their code for controlling hardware using the RBPi, before they are ready to transfer their code it to a real device.

According to a Microsoft employee, Xin Shi, the simulator is presently in preview, offering only basic functionality. That means the embedded image of the RBPi is static, allowing only a limited interaction with the sensor and the LED. There are plans for emulating new devices and sensors, but there is no timeline. Moreover, the simulator’s code being open-source, anyone is free to work on expanding the simulator.

However, this is not the first time a simulator has been designed for simulating RBPi controlled hardware. Working with the US startup Trinket, the Raspberry Pi Foundation had created a web-based emulator for Sense HAT. This is an RBPi compatible add-on board bundled with several sensors, a joystick, and a matrix of LEDs.

Just as the Microsoft simulator does, the emulator for the Sense HAT also allows users to work with Python codes for interacting with the add-on board. Compared to the Microsoft simulator, the emulator from the Foundation offers users a greater number of sensors to interact with, and allows the user to have more control over the simulated version of the LED matrix on the board.

On the website, users have a choice of four Python programs. The first one allows selecting temperature, pressure, or humidity sensors, and manipulating the sliders to change the readout of the LEDs. The second is a game of rock, paper, and scissors, which the users can play using arrow keys to select while competing against the RBPi. The third is another game where a small bird has to fly through obstacles, and the fourth is a game of Astro Bug, which has to eat the food, while avoiding enemies.