Adafruit MPRLS - Pressure Sensor Using Visuino Custom Code

by RonFrtek in Circuits > Arduino

95 Views, 2 Favorites, 0 Comments

Adafruit MPRLS - Pressure Sensor Using Visuino Custom Code

2024-02-18_12-32-13.jpg

In this tutorial we are going to read the values from a Pressure Sensor Adafruit MPRLS by using a Custom Code component in Visuino Pro.

Custom Code component in Visuino Pro allows us to add any Arduino code to the Visuino project.


Custom Code component in Visuino Pro is very useful if you need to add some sensor that is not yet supported in Visuino but you already have the code for it, or to just experimenting by adding your own code to the project.

Custom code in Visuino PRO is solving nearly 100% of all the missing functionality in Visuino Standard version.

More about Visuino Pro here

Here are also some very good tutorials on how to use a Custom Code component:

Getting started with the Custom Code component

Visuino Custom Code Tutorials

What You Will Need

2024-02-18_12-32-13.jpg
FZEK4WBK3XGYAP0.LARGE.jpg
VisuinoAdvrtisemenM5StackCoreS3.jpg
breadboard.png
F5OFEUQJJ4ZYFKY.LARGE.jpg


The Circuit

adafruit_products_image.png
  • Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
  • Connect GND to common power/data ground
  • Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
  • Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2

The MPRLS has a default I2C address of 0x18 and cannot be changed!

More here

Install Arduino Libraries

FICD5OCLNRH8ICB.jpg
2024-02-18_12-43-18.jpg

Go to https://github.com/adafruit/Adafruit_MPRLS and download Adafruit_MPRLS Arduino Library

Extract the to your Arduino Libraries folder, usually it looks something like this: C:\Users\User\Documents\Arduino\libraries

You can also find the Path if you in Visuino click on the Menu>Arduino>Configure and see it under "Arduino Library Directory" (see attached screenshot)

Start Visuino Pro, and Select the Arduino UNO Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add Components

FU2VC1ULNUC4MJR.jpg
2024-02-18_12-48-54.jpg
  • Add "Custom Code" component
  • Add "Clock Generator" component

In Visuino Set Custom Code Output

2024-02-18_12-52-09.jpg
  • Double click on the "CustomCode1" and in the "Outputs" window drag "Analog" to the left side
  • close the "Outputs" window


In Visuino Set Custom Code Component

F4ORKFYLNUC4IR8.jpg

Select "CustomCode1" and in the properties window select "Includes" and Click on the 3dots button

In the "Includes" window add this code:

#include <Adafruit_MPRLS.h>

And Close the "Includes" window


Select "CustomCode1" and in the properties window select "Members" and Click on the 3dots button

In the "Members" window add this code:

double pressure_hPa;
Adafruit_MPRLS mpr;

And Close the "Members" window


Select "CustomCode1" and in the properties window select "On Init" and Click on the 3dots button

In the "On Init" window add this code:

mpr.begin();

And Close the "On Init" window



Select "CustomCode1" and in the properties window select "On Execute" and Click on the 3dots button

In the "On Execute" window add this code:

{
double pressure_hPa = mpr.readPressure();
Analog1.Send( pressure_hPa); 
}

And Close the "On Execute" window


In Visuino Connect Components

2024-02-18_12-49-12.jpg
pressure-sensor.png
  • Connect "ClockGenerator1" pin [Out] to "CustomCode1" pin [Clock]
  • Connect "CustomCode1" > "Analog1" pin [Out] to "Arduino" Serial pin [In]


Generate, Compile, and Upload the Code

FBR42I2KXBU01YW.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

2024-02-18_13-21-53.jpg

If you power the Arduino module, at the bottom click on the "Serial" Tab, make sure you selected the correct port and click "Connect" button. You should start to see the pressure values in the serial monitor.

Since the "ClockGenerator1" frequency is 1Hz we are getting values every second, you can adjust the Frequency of the "ClockGenerator1" in the properties window.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here and open it in Visuino: https://www.visuino.eu