Tag Archives: embedded

Using a SIM800L GSM module with the Raspberry Pi (no battery)

sim800l gsm module with raspberry pi

The SIM800L is a GSM/GPRS modem widely used in electronics due to its very low price and wide availability. It’s an affordable way to send SMS with a Raspberry Pi or an Arduino, to connect to 3G or to implement a GPS.

However, it is almost impossible to find satisfactory explanations on its use and in particular on its connection.

In this tutorial we will therefore see how to connect and power a SIM800L from a Raspberry Pi (note that this also works for an Arduino), without external power supply or battery!

Hardware

We will go into the details and explanations later in this tutorial, but be aware that to connect a SIM800L to a Raspberry some hardware is required. So, you will need:

  • SIM800L GSM Module
  • 100 µF capacitor or more
  • 1N4007 diode
  • Breadboard
  • Jumpers

Of course, you will also need a Raspberry with Raspbian installed and a SIM card with a subscription. Note, the SIM card must be in micro sim format. If yours is a smaller format (nano format), you will need an adapter.

How to use the SIM800L module with a Raspberry Pi?

The SIM800L is a modem. It is the responsible for registering with your operator’s network, etc. Overall it behaves like a phone that you could control directly from your Raspberry.

To be able to control the SIM800L, from the Raspberry, you will have to provide power to the first and physically and software connect the two using a TTL port, more often called a serial port or interface.

From there you can control the SIM800L by sending so-called Hayes commands to the serial port – we actually speak more often of AT commands – which are commands specific to the functions of a modem. For example, send an SMS, enter a PIN code, check the network status, and much more!

In theory, to use a SIM800L with the Raspberry Pi you must do like this:

  • VDD of the SIM800L to +5V on the Raspberry.
  • GND of the SIM800L to GND on the Raspberry.
  • TXD of the SIM800L to RXD of the Raspberry.
  • RXD of the SIM800L to TXD of the Raspberry.

Only here, all that is the theory, but you will see that in practice things are a little more complicated.

Why is so difficult to plug in a SIM800L?

If the theory seems simple, in reality, you will find quite a few tutorials on the internet explaining how to use the SIM800L with a Raspberry. Worse, you will essentially find incorrect tutorials which, at best, will make your installation completely unstable, why not, will damage your SIM800L.

But then, how come there are not more quality resources available for such a well-known module? Because the SIM800L is particularly difficult to power and sensitive.

1. SIM800L is designed for phones and batteries

Originally the SIM800L was designed for use in phones by manufacturers. Its use in consumer electronics is much more recent and was not considered at all by the manufacturer.

As a result of its use in telephones, the module is designed to be powered by lithium-ion batteries, which offer voltages of around 3.6 to 3.7 volts. This feature will pose a first problem for us, because in digital electronics we generally use 3.3 volts or 5 volts, but not 3.6 volts.

2. SIM800L is an energy-intensive module

The second problem, the SIM800L performs radio operations that require large, very punctual current peaks. Typically the operations involved are registering on the operator’s network, sending messages, etc. If during these phases the module does not obtain the necessary current, its behavior becomes completely unpredictable, ranging from the error message to the restart through the loss of network.

Unfortunately, the power supplies in general and the GPIO ports of the Raspberry Pi in particular have a hard time responding to this kind of consumption peaks.

In fact, the amount of energy consumed is so great and over such a short period of time that using power cables that are too long and too thin can be enough to crash the module! This is also typically the case if you connect several Dupont cables in series.

No worries, we will explain how to solve these two problems!

So, how to power a SIM800L directly from a Raspberry?

We have seen so far that two problems arise for us to power a SIM800L from a Raspberry: an incompatible voltage and peaks in power consumption.

To begin, we will tackle the tension problem.

1. Decrease the voltage supplied by the Raspberry Pi

If we read the datasheet (technical sheet) of the SIM800L, we can see that the manufacturer indicates a supply voltage between 3.4 and 4.4 volts, with an optimal voltage of 4 volts.

The Raspberry Pi have two outputs that can supply two voltages, 3.3 and 5 volts. So we should increase our tension a bit or decrease it.

Let’s eliminate the first possibility which is too complicated to implement and look at the second. We are therefore looking for a reliable, simple and very inexpensive way to reduce a voltage by at least 0.6 volts, without reducing the intensity of the current (amperes). Luckily, it turns out that there is an electronic component that does exactly that, and that in addition this component is so widespread that absolutely all electronics technicians know it: the diode.

Diodes are primarily known for passing current in one direction only. But one of their characteristics is also to cause a voltage drop, which is estimated for silicon diodes at 0.7 volts.

So we just need to insert a silicon diode, we will take a 1N4007, between the 5 volt GPIO of our Pi and the VDD (power supply) PIN of our SIM800L. And here we have a voltage of 4.3 volts, MAGICAL RIGHT!!

2. Provide a power source that can meet consumption peaks

Now that we have solved our voltage problem, there remains our consumption peak problem. This time we would need a component allowing us to “store current” and provide it very quickly when the SIM800L needs it. Again, luckily, it exists and it’s called a capacitor!

Capacitors are used in many cases, but one of the most well-known uses is power supply stabilization. They charge when there is too much current and discharge when there is not enough. We will therefore insert an electrolytic capacitor (we will take at least a 100 µF 5 V, if we have more µF or volts no problem) in parallel with the VDD and GND pins of our SIM800L.

Schematics and wiring

Now that we’ve solved our problems, let’s see what our complete assembly looks like before testing everything by sending an SMS.

To hold all our components in place and connect them together we will use a breadboard and some jumpers.

Here is the final connection diagram, the red wire goes to the VDD, the black to the GND.

A few notes on assembly:

  • unplug the power supply of your Raspberry Pi while wiring. Only plug it in after checking everything and being sure that your circuit is good to go.
  • Connect the capacitor as close as possible to the VDD and GND pins of the SIM800L, ideally as shown in the diagram.
  • Capacitors are a polarized component, you must connect theme in a precise direction, anode on the VDD, cathode on the GND. The cathode is marked by a white band on the side.
  • Just like the capacitor, the diode is a polarized component. Again the cathode is marked by a white band.

Once the assembly is complete, you will be able to insert the SIM card into the slot provided on the SIM800L.

You must tuck the card on the contact side against the printed circuit, the corner cut at an angle towards the opening (it protrudes a little). If you insert the card upside down you will get a SIM not inserted type error when using the module.

Once the assembly is finished, turn on your Raspberry Pi, we will be able to test by sending an SMS!

Your first SMS from the Raspberry with a SIM800L

To finish this tutorial, we will send a first SMS to check that everything is working. We will not go further on the use of the SIM800L, but be aware that it offers many other features. For more advanced use, refer to the AT commands guide for the SIM800.

To begin, you will have to follow our tutorial to activate the serial port of the Raspberry Pi. Once you have finished activating the serial port we can connect to the SIM800L via the serial port.

To do this, open a connection to /dev/serial0 with minicom using the command line below:

sudo minicom -b 115000 -o -D /dev/serial0

Type the AT command (often the first line is not displayed when you type, this is normal) then make a line break to validate. You should get an OK response message.

Now we are going to check that the SIM card is unlocked (the PIN code is entered). To do this type the command AT+CPIN?. You should have an answer:

+CPIN: READY
OK

If you get an answer like the one below, you need to enter your card’s PIN code.

+CPIN: SIM PIN
OK

To do this, use the command AT+CPIN=0000 replacing 0000 with your own PIN code. You should then get a response of the form:

AT+CPIN=0000
OK
+CPIN: READY
SMS Ready
Call Ready

That’s it, you are connected to your operator’s network. All we have to do is send an SMS. To do this, use the commands AT+CMGF=1 to activate the text mode (it allows us to write the SMS in a format understandable for a human), then AT+CMGS="+213XXXXXXXXX" replacing +213XXXXXXXXX by the number to which you want to send the SMS.

A character > will appear, type your SMS then once you finish, press Ctrl+Z.

In the end you should have something like this:

AT+CMGF=1
OK
AT+CMGS="+213XXXXXXXXX"
> My Fist SMS with SIM800L using Raspberry Pi
+CMGS: 29

OK

There you go, you have sent your first SMS with a Raspberry Pi and a SIM800L! if you need to see more tutorials, check this link.

Machine Vision with Raspberry Pi using TensorFlow and OpenCV4

artificial vision with raspberry pi tensorflow and opencv

Do you want to implement a CCTV camera that can identify several different elements? Or maybe optimize your robot and give it the ability to detect objects?

The Raspberry Pi 4 offers enough performance to perform machine learning. In this tutorial you will see the steps to get TensorFlow working on your Raspberry Pi 4, as well as a demonstration of detecting objects with a PI Camera or USB Webcam.

Required Hardware/software

  • Raspberry Pi 4.
  • 3000mA power supply with its USB-C cable.
  • micro-SD card (minimum 32 GB).
  • Picamera (or USB webcam).

What is TensorFlow ?

TensorFlow is an open source machine learning framework for solving complex mathematical problems. It allows researchers to develop experimental learning architectures and turn them into software. TensorFlow was developed by Google Brain team in 2011 and made open source in 2015. Since then it has gone through more than 21000 changes and upgraded to version 1.0 in February 2017. Currently version 2.8.0 is available on the TensorFlow website.

This library notably makes it possible to train and run neural networks for the classification of handwritten digits, image recognition, models for machine translation, and natural language processing. An application’s code is written in Python but executed in high-performance C++. Here, the raspberry and its camera will be able to detect a hundred different objects! In addition, good results are obtained at night with an IR camera equipped with LEDs.

On the software side, the micro-SD has been flashed with the latest version of Raspbian Buster downloadable from the official website. Python3 is installed there by default, to launch a program from the command line, you will have to type in a terminal:

$ python3 my_program.py

Here, the Object_detection_picamera.py program will need several elements to work:

  • The mscoco_label_map.pbtext file corresponding to the list of 100 detectable objects, it is located in the data folder.
  • The “ssdlite_mobilenet_v2_coco_2018_05_09” folder where the training model files are stored.
  • The utils folder (utilities) containing the classification modules for the various objects.

Installing TensorFlow

Start by updating the Raspberry Pi:

sudo apt-get update
sudo apt-get dist-upgrade

Next, install TensorFlow with the pip3 command.

sudo pip3 install tensorflow

TensorFlow needs a library named Atlas, type the following command:

sudo apt-get install libatlas-base-dev

Finally, it will be necessary to install the dependencies necessary for the detection of objects.

sudo pip3 install pillow lxml jupyter matplotlib cython
sudo apt-get install python-tk

That’s it for TensorFlow. Let’s move on to OpenCV.

Installing OpenCV

TensorFlow’s object detection examples typically use matplotlib to display images, but OpenCV is preferred because it’s easier to use and less error-prone. The object detection scripts in the GitHub repository in this guide use OpenCV. To make OpenCV work on the Raspberry Pi, many dependencies need to be installed via apt-get.

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev 
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev 
sudo apt-get install libxvidcore-dev libx264-dev 
sudo apt-get install qt4-dev-tools libatlas-base-dev
sudo pip3 install opencv-python

If all went well, OpenCV is installed on your Raspberry.

You can check if the installation is successful and the installed version. Open a terminal and launch the Python3 interpreter.

The TensorFlow object detection API uses Protobuf, a package that implements Google’s Protocol Buffer data format. Before, you had to compile the Protobuf source code (a bit tedious), but now the installation is very simple, thanks to the multiple contributions of the community.

sudo apt-get install protobuf-compiler

In order to check the version installed, run the command:

protoc --version

You should have in response libprotoc v3.20.0 (latest version.)
Create a TensorFlow directory and navigate to it (/home/pi/tensorflow).

mkdir tensorflow
cd tensorflow

Download the TensorFlow repository from GitHub by typing:

git clone --depth 1 https://github.com/tensorflow/models.git

Next, you need to modify the PYTHONPATH environment variable to point to certain directories in the TensorFlow repository you just downloaded. PYTHONPATH needs to be set each time a terminal is opened, so the .bashrc file needs to be edited.

sudo nano ~/.bashrc

Go to the end of the file, and add this line:

export PYTHONPATH=$PYTHONPATH:/home/pi/tensorflow/models/research:/home/pi/tensorflow/models/research/slim

Now we need to use protoc to compile the Protocol Buffer (.proto) files used by the Object Detection API. The .proto files are in /research/object_detection/protos, but we need to run the command from the /research directory.

cd /home/pi/tensorflow1/models/research
protoc object_detection/protos/*.proto --python_out=.

Next, move into the object_detection directory:

cd /home/pi/tensorflow/models/research/object_detection

Now download the SSD_Lite model. Google teams have developed a series of pre-trained object detection files, with varying levels of speed and accuracy. The Raspberry Pi has a relatively weak processor for the recognition application, so a model should be used that takes less processing power. Here we will use SSDLite-MobileNet, which remains well suited for our Raspberry Pi. Download the file and unzip it into the object_detection directory.

wget http://download.tensorflow.org/models/object_detection/ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
tar -xzvf ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz

Finally, copy/paste the python program from this Github link in a file named Object_detection_picamera.py

If you want to port the application to other Raspberry Pi with OpenCV and TensorFlow installed, simply download the .ZIP of the necessary files available on GitHub.

Your application is now ready to work!

Conclusion

Once your application is operational, all possibilities are open. For an autonomous application, based on solar panels, it would suffice to perform a calculation of the power consumed by the entire installation, and to determine the appropriate type of battery.

Still at the battery level, the Lion-i technology seems well suited, because of its small size and its autonomy, the price is higher than a lead battery, but offers good results in an environment subject to cold or heat. heat.

Programming Arduino with Visual Studio Code

program arduino with vscode

Every hobbyist generally start programming on Arduino using its official IDE. For advanced programmers, it may be interesting to change the code editor to have access to a larger number of features. In this article, you will learn how to program your Arduino using of the Visual Studio Code software which is a nice alternative to the Arduino IDE.

Introducing Visual Studio Code

Visual Studio Code is an extensible and lightweight code editor developed by Microsoft. VSCode brings many features compared to the Arduino IDE:

  • Auto-completion.
  • Syntax highlighting.
  • Debug functionality.
  • Programming in several languages (C++, C#, Java, Python, PHP, etc.).
  • Project management.
  • Git repository management.

It is open source and available on Windows, Linux and MacOS platforms.

Installing Visual Studio Code

Go to the Visual Studio Code download page and download the latest version corresponding to your OS. Launch the installer and follow the usual steps.

Communicating with Arduino

To be able to communicate with Arduino, you must install the corresponding extension.

Click on the “Extensions” icon it the left of your screen or use the shortcut (Ctrl+Shift+X).

Then search for Arduino and select “Arduino for Visual Studio Code”.

install it then Restart VSCode.

Setting up VSCode for Arduino

Click on the Manage icon (gear icon on the bottom left) and select “Command Palette”. You can use the shortcut (Ctrl+Shift+P).

Search for Arduino, then you have access to several commands related to Arduino.

Select Arduino Board Config then select board type.

At the bottom right, click on Select Serial Port, then select the serial port corresponding to the Arduino (here, COM5).

At the bottom right, click on Select Programmer then select “AVRISP mkII”.

Code compilation and upload

In the command palette (Ctrl+Shift+P), search for “Arduino: Examples” then choose “Blink” or another example.

You can then upload the code by pressing “Upload” in the top right.

The console indicates if the code is loading and you can verify that the code is loaded on the Arduino board by looking at the status of the LED.

By modifying the code a bit we send text to the serial monitor.

int led = 13;

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("Led is High");
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("Led is Low");

  delay(1000);               // wait for a second
}

Upload the modified code to the Arduino board.

To open the serial monitor, press the Serial Monitor icon just to the right of the board type at the bottom right.

You can then select the desired Baudrate in the Arduino board configuration bar at the bottom right (115200).

Send commands to the serial monitor

Just like the Arduino IDE, it is possible to send commands via the Serial port.

In the Arduino command palette, search for “Send text to Serial Port”. An input bar appears.

It is possible to create a keyboard shortcut to open this command more easily. Press the gear icon to the right of the control.

Under the Keybinding tab, you can customize your shortcut.

Now you are ready to use use VSCode with your Arduino boards. Try this tutorial of the 16×02 LCD using VSCODE.

The 16×02 LCD with Arduino

LCD 16x02 with Arduino

It is often useful to display numerical or textual information produced by an Arduino board (a measurement made by a sensor, for example). As long as the Arduino is plugged into a computer, we can use the serial monitor built into the IDE to display this information. But if we want to develop a stand-alone device that can work away from the computer, a liquid crystal display (or LCD) is a practical and relatively simple solution. In this tutorial, we will learn how to use the 16×02 LCD with the Arduino board.

Equipment

  • Arduino UNO.
  • USB cable to connect the Arduino to the computer.
  • 16×2 LCD screen.
  • 220 Ohms resistor.
  • 1k Ohms potentiometer.
  • Jumpers.

What is a 16×2 LCD ?

Liquid crystal displays (LCD) use the light modulating property of liquid crystals. Liquid crystal displays are composed of two layers of polarizers, with perpendicular polarization directions,. These displays contain two glass plates between which the liquid crystals are placed. On the glass plates is an array of electrodes for each pixel. A voltage applied between the electrodes of a pixel causes a change in orientation of the molecules and therefore the transparency of the pixel which can then let, or not, pass the light of the backlight.

Wiring and explanations

Pins 1 and 2 are used to power the display:

  • Pin1 of the display — GND of the Arduino board.
  • Pin2 of the display — 5 V of the Arduino board.

Pin3 is used to adjust the contrast of the display: it is connected to a 10 kΩ potentiometer which allows its voltage to be adjusted to a value between 0 and 5 V.

  • Pin3 of the display — Cursor of the 1k Ohms potentiometer whose two other pins are connected respectively to GND and to 5 V.
  • Pin4 “RS” of the display — Pin12 of the Arduino
  • Pin5 “R/W” of the display — GND of the Arduino
  • Pin6 “Enable” of the display — Pin11 of the Arduino

Pins 7, 8, 9 and 10 of the display are not connected, because we will use the display in 4-bit mode rather than in 8-bit mode (which saves the inputs/outputs of the Arduino ).

  • Pin11 “D4” of the display — Pin5 of the Arduino.
  • Pin12 “D5” of the display — Pin4 of the Arduino.
  • Pin13 “D6” of the display — Pin3 of the Arduino.
  • Pin14 “D7” of the display — Pin2 of the Arduino.

Pins 15 and 16 are used to power the backlight. On some display models, the backlight is not essential (except to read the display in the dark), while for other models the display is unreadable if the backlight is not activated.

  • Pin15 from display — 5 V from Arduino through a 220 Ohms resistor.
  • Pin16 of the display — GND of the Arduino.

The Liquid Crystal Library

To display the information on the display, we will use the “LiquidCrystal” library, which was specially designed for this purpose. No need to install it, since it comes with the IDE.

To quickly check that your display is indeed functional, download the “Hello World” example to your Arduino. You should see the message “Hello, world!” appear on the first line of the display, while on the second line a counter is incremented every second.
If nothing is displayed, don’t panic! Turn the potentiometer knob that controls the contrast. Or you might need recheck your wiring.

To display a text, we use the “print” command. The text always starts at the cursor position. When you write something, the cursor automatically moves to the position immediately following the displayed text.

The position of the cursor is set using the “setCursor(column, row)” command. It is important to note that the first line at the top has the number 0, and the first column on the left has the number 0. The instruction “lcd.setCursor(0,0)” will therefore position the cursor at the top left.

If you want the user to enter text that will appear on the display, it may be useful to show a blinking symbol that indicates the cursor position, using the “blink” command.

Example code

Once your module is correctly connected, you can modify the following code to obtain the desired functionality. In the following example, we are creating a countdown timer.

As mentioned before, to manage the 16×2 LCD screen in the program, you can use the LiquidCrystal.h library.

  • LiquidCrystal lcd(rs, en, d4, d5, d6, d7): set 4bit i2c communication
  • lcd. begin(16, 2): displays text on both lines.
  • lcd.print(): display a character string in ASCII.
  • lcd.write(): display data, one byte at a time.
  • lcd.setCursor(x, y): set cursor (column x: 0-16, row y:0-2).
  • lcd.clear(): clear what is displayed on the screen
/*
The Liquid Cristal counter
www.bekyelectronics.com/
*/

// Library
#include <LiquidCrystal.h>

// Library initialization
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

long timeInit = 0; //min
int timeHour = 1;
int timeMin = 26;
int timeSec = 35;

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);
 analogWrite(8, 15);

 // Display a message
 lcd.print("Next alarm in: ");
 timeInit=timeToCount(timeHour, timeMin, timeSec);
}

void loop() {
 // Digital time display
 countTo(timeInit);
 
 // places the cursor at the 1st character of the 2nd line
 lcd.setCursor(0, 1);

 lcd.print(timeHour);
 lcd.print(" h");  
 lcd.print(timeMin);  
 lcd.print(" m");
 lcd.print(timeSec);
 lcd.print(" s");
 
 // Wait 1 second
 delay(1000); 

 timeInit=timeInit - 1;
}

void countTo(long cntr){
 timeHour=(cntr / 3600);
 timeMin= (cntr % 3600) / 60;
 timeSec = ((cntr % 3600) % 60);
}

int timeToCount(int h,int m,int s){
 return h * 3600 + m * 60 + s;
}

Congratulations, you just made your first clock.

If you want to see more of our tutorials, make sure to visit this link.

You may be interested in this article which shows how to use IMU MPU6050 with the Raspberry Pi Pico.

Raspberry Pi Pico and MPU6050 with MicroPython

Raspberry Pi Pico and MPU6050 with MicroPython

The MPU6050 is an inertial unit that combines an accelerometer and a gyroscope. It is used to measure acceleration, inclination and angular velocity. In this tutorial, we will try to explain how to use an MPU6050 with a Raspberry Pi Pico using MicroPython.

The accelerometer makes it possible to know the acceleration and/or the gravitational field according to 3 axes: x, y and z. If you take a closer look, you can see a drawing of the x and the y axes on the module, while the z axis is perpendicular to the plane of the module. When the module is stationary, flat on a table, it will measure an acceleration of 1 g along the z axis, due to the force of gravity acting downwards. If the measured acceleration is zero along the 3 axes, the MPU-6050 module is in free fall!

The gyroscope measures the angular speed along the 3 axes. When the module is immobile, the 3 components of the angular velocity are, in principle, zero (a calibration is however necessary for the result to be exact).

Connections

The MPU-6050 module has 8 connectors, but only 4 of them are necessary for its operation (2 for power supply, and 2 for data transmission by I2C):

  • VCC pin (MPU-6050) => 3.3V output pin (Raspberry Pi Pico).
  • GND pin (MPU-6050) => GND pin (Raspberry Pi Pico).
  • SCL pin (MPU-6050) => GP9 pin (Raspberry Pi Pico).
  • SDA pin (MPU-6050) => GP8 pin (Raspberry Pi Pico).

Installing imu.py and vector3d.py libraries

You can find the necessary libraries on this Github repository. Also, you need to copy the “imu.py” and “vector3d.py” files to the flash memory of the Raspberry Pi Pico.

First script

This script displays the measurements from the accelerometer and the gyroscope. From the data of the accelerometer, the script tries to determine if one of the 3 axes (x, y or z) approaches the vertical. Based on the data from the gyroscope, the script indicates whether the MPU-6050 module is spinning.

Run this script, and orient the MPU-6050 module in different ways to see how the displayed values vary.

'''
Using the MPU6050 inertial unit (accelerometer + gyrometer) with a Raspberry Pi Pico.
For more info:
bekyelectronics.com/raspberry-pi-pico-and-mpu-6050-micropython/
'''

from imu import MPU6050  # https://github.com/micropython-IMU/micropython-mpu9x50
import time
from machine import Pin, I2C

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
imu = MPU6050(i2c)

# Temperature display
print("Temperature: ", round(imu.temperature,2), "°C")

while True:
    # reading values
    acceleration = imu.accel
    gyroscope = imu.gyro
    
    print ("Acceleration x: ", round(acceleration.x,2), " y:", round(acceleration.y,2),
           "z: ", round(acceleration.z,2))

    print ("gyroscope x: ", round(gyroscope.x,2), " y:", round(gyroscope.y,2),
           "z: ", round(gyroscope.z,2))

# data interpretation (accelerometer)

    if abs(acceleration.x) > 0.8:
        if (acceleration.x > 0):
            print("The x axis points upwards")
        else:
            print("The x axis points downwards")

    if abs(acceleration.y) > 0.8:
        if (acceleration.y > 0):
            print("The y axis points upwards")
        else:
            print("The y axis points downwards")

    if abs(acceleration.z) > 0.8:
        if (acceleration.z > 0):
            print("The z axis points upwards")
        else:
            print("The z axis points downwards")

# data interpretation (gyroscope)

    if abs(gyroscope.x) > 20:
        print("Rotation around the x axis")

    if abs(gyroscope.y) > 20:
        print("Rotation around the y axis")

    if abs(gyroscope.z) > 20:
        print("Rotation around the z axis")
    
    time.sleep(0.2)

Second script

In this second example, the Raspberry Pi Pico’s built-in LED lights up when you shake the MPU6050 module.

'''
Using the MPU6050 inertial unit (accelerometer + gyroscope) with a Raspberry Pi Pico.
The Pico LED lights up when the MPU6050 is shaken.
For more info:
bekyelectronics.com/raspberry-pi-pico-and-mpu-6050-micropython/
'''

from imu import MPU6050  # https://github.com/micropython-IMU/micropython-mpu9x50
import time
from machine import Pin, I2C

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
imu = MPU6050(i2c)

# LED initially off
Pin(25, Pin.OUT).value(0)

while True:
    # acceleration reading
    acceleration = imu.accel.magnitude
    print (acceleration)
    
    # value at rest is 1
    if abs(acceleration - 1) > 0.1:
        print("It is moving!")   
        Pin(25, Pin.OUT).value(1) # turn on the LED
    else: 
        Pin(25, Pin.OUT).value(0) # turn off the LED
        
    time.sleep(0.2)

That’s it, this is how you can use the MCU6050 unit with your Paspberry Pi Pico. You can check other tutorials from this link. If you want to establish wireless communication between two of your Picos using NRF24L01, click here.

Release date and information on the Raspberry Pi 5

Release date and information on the Raspberry Pi 5

After many releases of new products from the Raspberry Pi Foundation, it has been less active in recent months. However, everything seems to show that the foundation is already working on the next Raspberry Pi. That includes the Raspberry Pi 5. Check out our article about the Raspberry Pi and its uses if you don’t know what it is.

The Raspberry Pi 5: In preparation but no release date yet

Although the Raspberry Pi Foundation has not yet announced the release date of the Raspberry Pi 5, it is indeed part of its plans.

Eben Upton, CEO of the Raspberry Pi Foundation has already announced a new Raspberry Pi with a more powerful and faster SoC. Also, the next Raspberry Pi should have a better USB input/output chip, more RAM memory and improved network connectivity (Ethernet/Wifi).

SoC: System on a Chip (Chip present on the processor)

Like each new version of the Raspberry Pi, this one will be even closer to a classic computer by being even more powerful than the Raspberry Pi 4. On the other hand, the foundation should keep the system set up with the Raspberry Pi 4, that is to say several versions of the Raspberry Pi 5 available, having a different RAM size and a different price as well.

Regarding the release date of the Raspberry Pi 5, we have no information yet but it should not see the light of day before mid 2022, or even early 2023 if an improved version of the Raspberry Pi 4 were to be released in the meantime.

Before the Pi 5 Released: An Improved Version of the Raspberry Pi 4

The release of the Raspberry Pi 4 is starting to date and many users are asking for a revision of the latest model from the Raspberry Pi foundation.

Based on the history of the foundation, we should see an update to the Raspberry Pi 4 (the Raspberry Pi 4A).

According to rumors concerning this new Raspberry Pi 4, improvements should be made to the SoC and to the USB ports which could give way to PCIe connectivity. The latter is already in place on the Compute Module 4.

What does the community want for the Raspberry Pi 5?

The best way to find out what the Raspberry Pi 5 will include is to ask what the community wants to see for the next Raspberry Pi 5.

1. Fix the bugs present in the Pi 4

The Pi 5 is expected to alleviate issues that the current versions have, such as:

  • USB-C power issues

There are many USB-C power adapters with fast charging technologies such as QuickCharge, DashCharge or SuperCharge. A hardware design flaw in the Raspberry Pi 4/4B is known to cause some adapters to misinterpret the device type. As a result, these adapters will provide more than 5V to power our Pi. This can sometimes burn out the board’s power supply or worse, the entire CPU .

So hopefully the Pi 5 doesn’t have the same design flaws.

  • The USB hub and the Ethernet chip

The 4-ports USB hub & the Gigabit Ethernet controller of the Raspberry Pi 4 have sometimes become hot. Even when no device is plugged in.

This problem has only been encountered by some users and no specific reason has been found.

Result, an increase in standby temperature means a decrease in the life time of the components.

  • The low voltage warning

It happened that a window appeared in the office asking to check the power supply. This problem may appear even when the power supply is new and after checking it has no problem.

In the Raspberry Pi 5, this should be fixed. It can only be triggered if the Pi is really struggling to draw enough current from the power supply.

2. Take over some features of the Raspberry Pi Pico in the Raspberry Pi 5?

Not too long ago, Raspberry Pi introduced its own microcontroller, the Raspberry Pi Pico. With a host of features such as the programmable IO state machine subsystem.

We know that being a microprocessor-based system, Raspberry Pis are not designed to perform critical tasks. For example, they can’t generate PWM signal, DAC and ADC functions, let alone handling interrupts.

Therefore, how about an integration of some of the Pico functions into the Raspberry Pi 5 such as:

  • Analog inputs (ADC).
  • Hardware PWM outputs.
  • IO programmable state machine system.
  • Additional hardware UART interfaces.
  • On-chip accelerated floating point and integer libraries.
  • Hardware Interrupts.
  • RTC & low power modes supported by the microcontroller part of the system.

Another subject is the design and size of the Raspberry Pi 5. This subject is debated because not all users agree: some want change while others strongly oppose it.

And you, what do you expect from the Raspberry Pi 5? Let us know in the comments below.

Launch a Python script when starting your Raspberry Pi

Launch a Python script when starting your Raspberry Pi

There are many projects where, to work, you had to run a Python script. For example for a control station, a Jukebox with RFID chip, or a security alarm system.

The problem is that it is quite annoying to have to launch it by hand each time the Raspberry Pi starts… Because that means always having a keyboard, a mouse and a screen plugged in, or logging in by SSH to launch it.

One solution is to start the Python script as soon as the Raspberry Pi boots up, and we’ll see how to do that in this article.

Don’t know what a raspberry pi is? check this link.

Create a shell script

In the user folder, you have to create a shell file that will contain the commands to run to launch the Python script.

cd /home/pi
nano launch.sh

Code explanation:

The first line “cd /home/pi” allows you to move into your user directory.

The command “nano launch.sh” will create the file “launch.sh” and will open the nano text editor so that we can write in the file.

In the file, write the commands to run your Python script:

cd /home/pi/my-program
python3 my-program.py

Save the file by pressing ”Ctrl + X”, confirm by pressing “O” and validate you choice by pressing Enter.

Make the file executable

Before you can use this shell file, you have to make it executable:

chmod 755 launch.sh

Test your file and check that your python script is launched with the command:

sh launch.sh

If everything works, you can move on to the next step.

Create a log file

In your user directory, create a “logs” folder which will contain the various log files of your programs. They will be used to have a written trace in you have an error in your program.

mkdir /home/pi/logs

Add your file to crontab

crontab is a process for running scripts in the background. It will execute scripts and commands at specific times or during specific events.

To add a new command in crontab:

sudo crontab -e

At the bottom of the file, add the line:

@reboot sh /home/pi/launch.sh > /home/pi/logs/log.txt 2>&1

This line will allow you executing the command “sh /home/pi/launch.sh” when starting the Raspberry Pi, and will save error messages and logs in the file “/home/pi/logs/log.txt ”.

Save with the shortcut “Ctrl + X“.

Check that everything is working

Reboot your Raspberry Pi:

reboot

If your program did not launch or there is a problem, check the log file to see if any errors have occurred.

That’s the end of this tutorial, I hope that tutorial could help you!

Write a comment below and tell us what will you use this script for?

DIY relay board

DIY relay board

In this tutorial, you’ll learn how to make a power automotive DIY relay board. This board allows the control of DC motors or other power devices for robotic, industrial, automotive or on-board electronics applications.

Printed circuit with the 12 volt relay on its plug-in support

Presentation

When designing the board, it was intended for the production of an industrial test bench in the automotive world.
The forty power controls needed were made with relays mounted on brackets. Control is performed by the logic outputs of a measurement PC with Labview® type software. The relays actuate DC motors used in cars and also perform the necessary galvanic isolation function between computer equipment and power devices.

Other possible applications

  • Current inverter: using a N.O.-N.C. contact relay. (5 pins).
  • Control of: fog lights, additional headlights, 12-volt spotlight, siren.
  • Control for robot motors: robot mower, R2D2 robot, exploration robot.

Diagram and electrical design

Circuit diagram of the board

The relay

Detailed view of the relay terminals

According to the final application, you can choose the quality of the relay. The breaking capacity of the contacts (in amperes), the rise or fall times of the contacts (in milliseconds), the number of operations and the operating temperature (°C) are parameters that directly influence the service life of the relay (coil, mechanics and contacts). The relay terminals are of the male “6.35 faston terminal” type.
The relay used is form C and identified by five terminals. The coil has numbers 85 (+) and 86 and contacts 30 (common), 87 (NO) and 87a (NC). See the pinout and terminal identification in the following illustration.

Identification and numbering of relay terminals

The orthographic reform of 1990 proposed to return to the spelling relay (on the model of delay), but this one did not impose itself and relay remains despite everything the most common.

The relay support

The relay soldering support.

You can use this “6.35 faston” relay support to avoid soldering your relay directly to the board. Using this support, you can plug and unplug your relay anytime easily.

Protective devices

Across the coil terminals, you must wire a free-wheeling diode (therefore pay attention to the polarization of the wiring). It acts as an “energy absorber” when de-energizing the coil, which avoids propagating an overvoltage on the component that drives the relay (transistor or dry contact) and also limits the emission of transients on the cable which connects the logic output of the measurement PC to the relay card. As a precaution, we recommend protecting the output transistors of the logic board of the PC. You must find out about the equipment from the manufacturer or the instructions provided.
You can use other components to protect the relay contact controlling the inductive load. For example, if you choose to use a diode, it must be able to carry the same nominal current of the motor (or of the load in general). A varistor or an RC circuit (100 ohms + 0.1 mF for example) may be suitable in some cases.
The motor must also be protected from overcurrent with a fuse to be inserted in the power circuit (which will also protect the relay contact).

BOM

Here you can find the list of the electronic components:

  • 1N4005 diode (D).
  • MR751 diode (D2).
  • Automotive relay 12V (inverter) – form C (RL1).
  • 5-pin relay support – form C PCB version (RL1) plus the 5 terminals.
  • 4-point terminal block, 5 mm pitch (J1).
  • 5-point terminal block, 5 mm pitch (J2) with copper cages.
  • printed circuit REL12 70 to 105 μm, single-sided FR4, solder-side varnish, 40×60 mm.

The circuit board “PCB”

The recommended thickness of copper traces is 70 to 105 µm with a minimum trace width of 2.5 mm for a current of 20 amps. Additional tinning of the copper tracks may be necessary in the case of higher currents. Solder side varnish is preferable. The circuit board has four fixing holes, so you can fix it in a horizontal or vertical position.

The printed circuit artwork.

The wiring

It will be necessary to respect the direction of implantation of the diodes and the cage connectors. Solder the components in the following order:

  • Diode D1.
  • Diode D2.
  • Terminals J1 and J2.
  • The relay support.
Top view of the fully wired board.

check our latest tutorials from here.

What is arduino ?

what is arduino

Arduino® is a hardware and software package that allows you to learn electronics (while having fun) while becoming familiar with computer programming. Unlike other boards, Raspberry Pi for example, Arduino is open source, so you can download the original schematic and use it to build your own map and sell it without paying royalties.

The Hardware

They are programmable electronic cards (therefore equipped with a processor and memory) on which we can connect temperature, humidity, vibration or light sensors, a camera, buttons, adjustment potentiometers, contacts electric… There are also connectors for connecting LEDs, motors, relays, displays, a screen…

An Arduino board is a brain that makes electronic systems intelligent and animates mechanical devices.

The image below shows an the Uno board which is widely used for beginners.

An Arduino Uno board with its connectors.

In writing related to Arduino you will often see the words “microprocessor”, “micro-controller”, “MCU”, “AVR”, “ATMega168”, “ARMCortex-M3”…

In a very simplified way: all these terms designate a processor. The processor is the calculation unit (CPU) contained inside the integrated circuit designated by one of the terms previously mentioned (example: MCU, ATmega168, etc.)

The Software IDE

The creators of Arduino have developed software to make programming arduino boards visual, simple and complete at the same time.
This is called an IDE, which stands for Integrated Development Environment.

The Arduino IDE is the software used to program Arduino boards.

The IDE displays a graphics window that contains a text editor and all the tools needed for programming activity.
You can therefore enter your program, save it, compile it, check it, transfer it to an arduino board…
At the time of writing this page, the most recent version of the Arduino IDE is 1.8.10. The look is pretty much the same on every platform (Windows, Mac, and Linux). The following image shows the initial screen that appears when launching the IDE.

Types of Arduino Boards

Over the years, the designers at Arduino.cc have come up with a number of board designs. The first Arduino board, the Diecimila, was released in 2007. And since then, the Arduino family has evolved to take advantage of the different types of Atmel microprocessors.

The Due, released in 2012, is the first Arduino to use a 32-bit ARMCortex-M3 processor. It stands out from the rest of the family in terms of processing power and board pinout configuration.
Other boards, like the LilyPad and the Nano, don’t have the same pinout as well and are aimed at a different range of rather “mobile” applications.
In the case of the LilyPad it is for easy integration into clothing and fabrics.
The Esplora integrates sensors and actuators and the compact size of the Mini, Micro and Nano predestines them for miniature, light and discreet applications.

When several types of microcontrollers are indicated, it means that an early version was produced with the first type and later with the other (generally more powerful).
For example, an older version of the Duemilanove will have an ATmega168, while newer models will have the ATmega328. Functionally, the ATmega168 and ATmega328 are identical, but the ATmega328 has more internal memory.

The latest additions to the Arduino family, Leonardo, Esplora, Micro and Yún, all use the ATmega32U4 microcontroller. If the latter is similar to an ATmega328, it also integrates a USB serial interface component, which eliminates an integrated circuit (easier routing) like the one present on the Uno and Duemilanove boards (ATmega16U2, FT232RL).

Arduino naming convention

Although the design of the Arduino circuit and its software is open source, the Arduino team has reserved the use of the term “Arduino” for its own designs.
The Arduino logo is a registered trademark.

You will sometimes find builds that look like official Arduino boards, but are not produced by the Arduino team. Some manufacturers use “-duino” or “-ino” in the product name, such as Freeduino, Funduino, Diavolino, Youduino, etc. Some, like boards made by SainSmart, use only the model name (Uno and Mega2560 for example).

Due to a dispute between the company created by the original founders (Arduino LLC) and a different company created by one of the original founders (Arduino SRL), Arduino LLC uses the Arduino trademark in the United States and Genuino elsewhere.

Some “manufacturers” claim to be selling an Arduino board, but are actually just a copy using the trademark without permission.
Massimo Banzi has dedicated a section of his blog to these blatant unauthorized copies.

The main point to remember here is that you can copy the schematics, the bootloader code, the Arduino IDE code and use them to create your own version (open source principle) .
Just don’t call it ‘Arduino’.

What can you do with an Arduino?

In addition to the ease of programming made possible by the Arduino IDE, the other great feature of an Arduino is the capability of the microcontroller on which it is based.
With a few extra shields readily available, a wide selection of inexpensive sensor modules and actuators, there really isn’t much you can’t do with an Arduino.
The condition is to keep in mind a few basic constraints: memory, clock frequency, peripheral output currents and voltage levels.

Here are some possible applications for an Arduino:

Measurement and detection

  • Automated Weather Station.
  • Lightning detector.
  • Tracking of the sun for orientation of the solar panels.
  • Radiation monitor.
  • Automatic wildlife detector.
  • Home or business security system.

Control

  • Little robots.
  • Rocket or airplane model.
  • Multi-rotor drones.
  • Simple CNC for small machine tools.

Automating

  • Automated greenhouse.
  • Automated aquarium.
  • Laboratory sample shuttle robot.
  • Precision thermal chamber.
  • Automated electronic test system.

What is a Raspberry Pi ?

What is a Raspberry Pi

The Raspberry Pi is a small, inexpensive system consisting of a circuit board of approx. 9 × 6 cm on which all the necessary components are located to be able to use it as a computer. Use an SD card and connect a power pack for the power supply and you are ready to go. Depending on the intended use, this can already be the minimum configuration of this single board computer if the system has previously been programmed accordingly for a specific task, which is commonly understood as an embedded system.

A monitor can also be connected to the board. A USB keyboard and USB mouse can be connected as input devices. A network and an audio connection complete the Raspberry Pi hardware to a normal and usable computer. A special Linux distribution is used as the operating system for this. In contrast to other systems, this OS is quite frugal to be able to deal with relatively limited hardware resources. This limitation is mainly because of the processor performance, memory size, and the board’s graphics system. The OS “Twister”, can also be used as the main OS for the Raspberry Pi.

Origins

The origin of the single board computer dates back to 2006 at the University of Cambridge. The intention was to be able to provide the students and anyone interested with a cost-effective system in order to bring them closer to programming computers.

Almost everyone knows how to work with personal computers and primarily with the Windows operating system. Over the years, however, it has become more and more difficult and confusing to understand and program a PC, which applies in particular to the hardware and the programming of the same for your own applications. Even considering that PCs have become cheaper and cheaper for what they offer in terms of performance and functionality, they still cost a lot of money in relative terms.

In earlier times, many PC users actually took it for granted that their own programs and hardware extensions were also implemented for the computer, which is why the PC was still regarded as a device for specialists such as computer scientists or electronics engineers. It hasn’t had this status for a long time. The fact that it can basically be used intuitively by anyone for all sorts of tasks is ultimately due to the software, which is becoming ever easier for the user.

For a programmer, this user-friendliness leads to more and more complex processes, which require the appropriate know-how and a large number of special tools, development environments, and programming languages. It is not uncommon for the Windows operating system and the corresponding programs to give the impression that an enormous amount of superfluous program code is »carried along« that is seldom or never called, which is partly due to the universal compatibility of the personal computer with Windows so that even Decades-old programs still work with the latest Windows version, which leads to quite high performance and memory requirements. For these reasons, a standard PC seems unsuitable as learning, experimenting, and programming system for beginners.

A home computer with a 6502 CPU (2 MHz) was developed at Cambridge University in the early 1980s, which served as a teaching model in British schools and was supported in a series of broadcasts by the BBC. This home computer, known as the BBC Micro, was manufactured by the English company Acorn, which later made a name for itself as ARM (see Chapter 3.2). One of the developers was Jack Lang, who was also involved in the Raspberry Pi development, which makes it clear that the idea for creating a “teaching system” was also the inspiration here.

In contrast to the BBC Micro, however, the Raspberry Pi was supposed to be much cheaper. This was certainly achieved with a price of around €25 (model A). In addition, the Raspberry Pi is designed from the outset to also be able to run office applications and games. Features such as the internet access and video playback in HD quality show that this is a “real” computer in small format.

The development was largely based on the ideas of David Braben. David had already developed the well-known space game “Elite” as a student in Cambridge in 1984. He also founded the development studio Frontier Developments. Together with two other computer scientists from Cambridge (Alan Mycroft, Rob Mullins) and Eben Upton, a Cambridge graduate who was now Technical Director at Broadcom, and entrepreneur Pete Lomas (Norcott Technologies, Electronic Design). also a Cambridge graduate, developed the Raspberry Pi Foundation established as a non-profit foundation to fund the project and attract open source software developers.

When naming this single-board computer, the Foundation wanted to continue the tradition of naming computers after fruits. A perfect example will be Acorn (acorn) or Apricot (apricot). Both of which have a Cambridge/ARM tradition. With the most well-known Apple, whose products Interestingly enough, such as iPad or iPhone also work with ARM processors. After long discussions, it was then agreed on Raspberry (raspberry). The Addition Pi identifies the main programming language of the system, Python.

Contrary to the original idea, the distribution of the Raspberry Pi boards was not taken over by the Foundation itself. It was transferred to the two global distributors RS-Components and Farnell. After the start of sales on February 29, 2012, the distributors were able to sell +10,000 boards within an hour. The demand was so great that the sale had to be suspended. Interested parties had to register for a single copy per buyer before it was available again weeks to months later. Within a year (2012), the two companies then sold over 800,000 of them.

The Raspberry Pi allows connection to various peripherals, which allows for a wide range of possible uses.

The Raspberry Pi has triggered a “hype” worldwide. Not only due to the low price, but rather to the overall concept. A concept in which the aim is not maximum profit, but the fact that maximum performance at minimum price with the open Source ideas are combined. Every interested (young) person – with a tight budget – can afford to program and experiment on current hardware and engage in lively exchange with other developers in the open source community. It is actually remarkable how many uses and applications for the Raspberry Pi have been created in a very short time. Thanks to open source, these do not cost any money and are constantly being further developed.