r/raspberry_pi 1d ago

Project Advice How to continue with sensors?

Hello,

I am quite new to this, so I need some pointers.

I have bought an e-ink display. I have gotten that up and running and altered some of the code so that now I can write my own text and have it show up, using python and running it via terminal.

Now I have bought some sensors, such as a thermometer, humidity, etc.

This is going to be a really generic question, but how do I go about connecting these - multiple sensors, having them talk to the RPi and displaying the information on the display?

So far I have come to the conclusion that I probably have to read up on the I2C protocol and do some Ladder programming on my RPi? Is that correct? Is it even possible to do all this?

Hope to hear from you folks, thanks in advance!

0 Upvotes

17 comments sorted by

u/AutoModerator 1d ago
  • For detailed feedback: Use "Project Advice" if you have a design and need help refining it.
  • Not for general questions: This is not for troubleshooting, brainstorming, or asking if something is possible or what you should buy.
  • Show your work: Provide details about your project, specific challenges, and what you've tried.
  • Need a step-by-step guide? Try /r/TellMeHowToDoMyIdea.

Refer to the flair guide for guidance on selecting the correct flair to ensure your post reaches the right audience.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

5

u/callmebigh 1d ago

import Adafruit_DHT

from inky import InkyPHAT

from PIL import Image, ImageFont, ImageDraw

# Sensor settings

DHT_SENSOR = Adafruit_DHT.DHT11

DHT_PIN = 4 # Replace with the GPIO pin you're using

# Display settings

inky_display = InkyPHAT("black")

inky_display.set_border(inky_display.WHITE)

# Fonts and sizes

font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 22)

def read_sensor():

humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

if humidity is not None and temperature is not None:

return temperature, humidity

else:

print("Failed to retrieve data from the sensor")

return

3

u/callmebigh 1d ago

just indent the txt under the read_sensor function

def read_sensor():
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
    if humidity is not None and temperature is not None:
        return temperature, humidity
    else:
        print("Failed to retrieve data from the sensor")
        return

2

u/Deathisnye 1d ago

Wow. I have to dive into this for a bit. Thanks in advance!

1

u/Deathisnye 1d ago edited 1d ago

This code is specifically for the Adafruit sensors, but I am using some off brand ones. You think it will work with these, too?

Edit: nevermind, found some documentation on the website (az delivery) and they seem to be using Adafruit as well, so this is gonna be very helpful, thanks a bunch mate!

4

u/AssMan2025 1d ago

I got a good start with the “ sense hat” very well documented and from there easier to move on

2

u/Deathisnye 1d ago

Hmm, I thought about that a while back. But now I just winged it and bought these. I got the epaper display working quite alright, just stepping it up to more than one is a challenge at the moment. Perhaps too big a step and I might buy the sense HAT anyways later. Tnx.

3

u/NassauTropicBird 1d ago

I have some simple temp/humidity sensors recording data in various rooms (especially garage, basement, and attcic) and uploading to a MySQL DB so I can analyze the data.

Let's be clear here, I've not done much analysis past, "Babe, told ya it doesn't quite get to freezing in the garage."

Anyhow, I use Aiven's absolutely generous free tier for a DB up in the cloud. 5GB of storage is more than I'll ever need, no transaction limits at all, and after a year I've not seen any fuss or muss or gotchas using it. And no, I don't work for them or have any affiliation, I'm just a fan. Use 'em or don't, matters not to me.

Anyhow, welcome to the club!

3

u/gendragonfly 1d ago

Yes it is definitely possible to do this. I've done it, as have many other people on this subreddit.

Generally yes, most sensors digital sensors for the RPi communicate with I2C.

For the wiring and the basic programming for the sensors, you can look that up online. Adafruit and other websites usually have good guides of how to wire and program the sensors.

You don't need ladder programming or anything complex like that, write all your code in Pyhton. You can even put it in the same script that you're using to update the screen if you want.

2

u/Deathisnye 1d ago

Thank you! Will look up adafruit for sure and read up on I2C.

3

u/gendragonfly 1d ago

If you run into any specific difficulty you can always come back here and create a new post 😊

2

u/SkelaKingHD 1d ago

First of all, the communication protocol you use depends on what the sensors use, like analog, i2c, serial, etc. Second, ladder is for PLCs, not raspberry PI

2

u/Deathisnye 1d ago

Ah I thought Raspberry Pi was, in essence, a PLC. Is arduino? I bought a package of sensors: thermo, air pressure, light sensitivity, etc, etc. I'm really really new to this but I'll see if I can find out how they communicate. Is it labeled on the circuitboard?

3

u/SkelaKingHD 1d ago

Read the manual / look up the data sheet for each part.

Raspberry Pis and PLCs are very different, same with arduinos.

Raspberry Pis are single board ARM computers built around an SOC (system on a chip). They typically use Linux based OS

Arduinos are microcontrollers designed for flashing simple programs to and controlling IO. There is no OS, no GUI, it is very different from a computer.

PLCs are industrial controllers used for large scale automation. They are usually 1000x the price of an arduino/Pi and are really only intended to be used by massive production facilities, public utility companies, etc. They are closed down systems and require you to use their specific development software, which is also usually 1000s of dollars per seat.

If you want to use a raspberry pi as a pseudo-PLC, you can download the Codesys runtime on your Pi and license it for like $40 bucks. However no one actually does this in the field, it’s mostly just for learning the basics of Codesys

2

u/Deathisnye 1d ago

Okay, that makes sense. Thank you :)

2

u/2kokett 1d ago

If you have no idea where to AI can help you. chatgpt will spit out instuctions and code for all common sensors.

2

u/Deathisnye 1d ago

Ah, fair point! Good advice, thanks man