Node-Red Beginner needing a little help!

Hi there,

I've been on the Node-Red forums for the past week trying to solve my problem however I don't know if I am doing it correctly. I am currently building a Soil Moisture sensor with;

Pi 3 Model B
Dfrobot Capacitive Soil moisture sensor

I've managed to set up my node red flow, and I'm receiving readings between 350 and 850. Closer to 350 is when the sensor is dipped into water, and closer to 850 is when it is out. I'm hoping to convert these to a percentage from 0-100% to measure the soil moisture and then upload it to Google Sheets.
I have pasted my existing script below in hopes of anyone being able to assist me (please note I am in my 4th week of learning any sort of programming).

import sys
import time

# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

# Software SPI configuration:
CLK  = 18
MISO = 23
MOSI = 24
CS   = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)

# Read all the ADC channel values in a list.
values = [0]*8
for i in range(8):
    # The read_adc function will get the value of the specified channel (0-7).
    values = mcp.read_adc(0)
# Print the ADC values.
a = 2108
b = 376
sys.stdout.write("%d" % (values))

Not quite sure what that code is... Node-RED uses Javascript and there is a node to help read the MCP3008 directly.
However if you already have values being read in ok then you could use a range node to change the range of numbers to 0 - 100.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.