Using an ADC on Raspberry Pi 3B and displaying data on Superchart

Hello, I am trying to work on a project and I’ve found some difficulties using Blynk to read values that come from an Analog to Digital Converter (ADC) ADS1115.

I am using Raspberry Pi 3 Model B and my target platform is Android. I have the newest Blynk Library version installed and I even succeeded to make an LED light up using Blynk (the LED connected on a breadboard to my RPi). My problem is after I’ve done testing Blynk and it worked out fine, I am having a problem reading the value of the ADC inputs. I am not sure how to do it, I was told the SCL/SDA (connected to pin 2 and pin 3 on the RPi) somehow multiplex the values of analog inputs 0, 1, 2 and 3 and they’d be displayed on either SCL or SDA. However, I tried many widgets on Blynk to try and display these values like the numeric value but it didn’t show up anything but “High” the whole time no matter how much I changed it.

My aim is to display an ECG signal that should be read from the ADC. So I figured I need to use the Superchart widget but I can’t seem to get it work on the ADC. The Superchart worked for the light bulb (being on and off was shown in the plot). However, it doesn’t show anything for the ADC pins 2 or 3 (stays 0 the whole time no matter how many different combinations of A0-A3 I tried).

To make sure that the ADC is not faulty, I tried the Adafruit guide for the ADS1115 and the python code, and it worked fine, the values were displayed in real time on the RPi (even if it was trash values, it still worked).

I am not sure about what do I need to do. I didn’t alter anything in the “main.cpp” file.

TL;DR:
I want to read values from the ADS1115 ADC and display it on a Superchart on Blynk.

Blynk will NOT directly read the sensor, so you will need to first get your code working and properly showing data, at least on the terminal monitor or something.

With the RPi, your best language options are NodeJS and possibly Python as then the compatible Blynk library can be used alongside to hopefully send the final data to the App for display.

Search this forum for other ECG attempts.

I have a Python code that correctly displays the Analog input data of the ADC on the terminal. I just don’t know how to pass that info to Blynk.

Look at the link I provided, particularly the python library, add the Blynk python library and connection commands to your sketch and get that working at least. Then instead of… or as well as… displaying your data via whatever method used now, you use the python version of the Virtual Write command.

E.g. blynk.virtual_write(3,'Hello World') # Print text to Display Widget on V3

So I tried installing the Python version of Blynk, and when I try to run the code (shown below) or any other python code that uses Blynk (like the one in the examples of the library) the server starts then shuts down immediately the pictures after the code explain what I mean, I don’t know what’s the problem because in CPP I didn’t have this problem.


import BlynkLib
import time

BLYNK_AUTH = 'IActuallyTypedMyOwnToken'

blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
      print('Current V1 value: {}'.format(value))

@blynk.VIRTUAL_READ(2)
def my_read_handler():
    blynk.virtual_write(2,time.ticks_ms() //1000)

blynk.run()

And finally this is how it looks like on my RPi terminal after I run the code:
python

As you can see it immediately shuts down, and I can’t tell why. Do you happen to know the reason? Thank you in advance.

EDIT: I am using RPi 3 with Wi-Fi option on Blynk.

I have no idea… but it does seem we are running different versions of Blynk Python, based on the internal messages provided with the logo, mine must be slightly older? Whether that has any bearing??

I made slight changes to account for my Local Server…

@vshymanskyy Even after update/upgrade all I can get is version 0.1.3 with your install command

pi@raspberrypi3:~ $ pip install blynk-library-python
Collecting blynk-library-python
Installing collected packages: blynk-library-python
Successfully installed blynk-library-python-0.1.3
pi@raspberrypi3:~ $ 

Meanwhile, I guess I need to learn how to manually download and install it :stuck_out_tongue:

Also… conflicting info here…

image image

Hmmm. I wonder if I need to run mine on a local server for it to work.

Shouldn’t matter at all.

However, FYI, in another topic I ran into issues configuring Blynk Python ver.0.2.0 with my Local Server IP. Not sure if there is a different way to do it (from ver.0.1.3), or simply due to my method of “upgrading” from ver.0.1.3 (AKA simply copy/pasting the ver.0.2.0 Blynklib.py over the older one :stuck_out_tongue: )

git clone GitHub - vshymanskyy/blynk-library-python: Blynk library for Python. Works with Python 2, Python 3, MicroPython. gave me version 2.0.

Same here, it states only 2 arguments accepted.

1 Like

Hack line 216 of BlynkLib.py with local server details.

1 Like

Thanks for the git clone suggestion… something new learned… now retain it I must :stuck_out_tongue:

Just like I didn’t remember/think about the whole “edit the library” thing. But in my defence, I like the option of flipping back and forth between servers from a simple sketch edit.

@Gunner is version 2.0 working for you?

I’m going to try dropping back to the latest official release.

I never actually tested it since it didn’t like my local server syntax… so I don’t know.

1 Like

Version 1.3 works ok.

@Costas @Gunner Even the cloned version on my RPi gives the same result, and they all seem to be version 0.2.0 for me. It just terminates immediately after starting.

@Peril use the latest release (0.1.3) at https://github.com/vshymanskyy/blynk-library-python/releases

For me the connection works but as soon as I move a slider I get:

Blynk connection successful, authenticating...
Access granted, happy Blynking!
Current slider value: 152
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    blynk.run()
  File "C:\blypy\v1.3\blynk-library-python-0.1.3\BlynkLib.py", line 390, in run
    msg_type, msg_id, msg_len = struct.unpack(HDR_FMT, data)
struct.error: unpack requires a string argument of length 5

@Costas
After installing that version here’s what happens. I tried different example folders:

image

And when I tried to run my own examples shown in the previous reply, this happens:

image

So the old version is uninstalled, I used pip unsintall, and used sudo python setup.py install on the 0.1.3 version. The resutls are shown above. Any idea what’s the problem?

EDIT: Note that I had to manually stop the terminal using CTRL+C because it was going like that forever. Connecting and disconnecting.

Do you have the correct token?

1 Like

Ohhhh snap, I forgot to edit it totally went over my mind that I reinstalled it, thanks it works now :).

image