Variables declared in a function are only accessible within that function and cease to exist afterwards.
If you want to share a variable declare it in module scope and mark it global in each function you want to use it within.
shared = 0
shared = shared + 1
print ("func_1 shared=", shared)
I have installed OpenCV and and access it with Python 2. However, I'm unable to use OpenCV with Python 3.
With python (Python 2) you have installed python-opencv from the repository which is the Python 2 version. If you try to use it with python3 this cannot work. You have to install OpenCV for the Python 3 version. Just do it with:
rpi ~$ sudo apt install ...
CoderMike's Answer addressed the problems in your code, but if you are actually using the relay module pictured and have wired it in a similar manner there are more concerns.
There are a number of similar (poorly-designed) relay modules on the market - they seem to infect ebay!
They may work with Arduino (and TTL logic) BUT ARE A LOUSY DESIGN even for that ...
Firstly does the following turn your relay on then off?
import RPi.GPIO as GPIO,time
You also need to add timeouts to your distance sensing code otherwise your code could get stuck in a while ...
By default Geany runs Python code using Python2. This can be changed under 'Build','Set Build Commands'. Then change Compile from python to python3 and Execute from python to python3.
The serial read commands changed between Python2 (returns string) and Python3 (returns bytes), adding a .decode() converts bytes to string.
If not sure which version of ...
>>> from pythonwifi.iwlibs import Wireless
>>> wifi = Wireless('wlan')
""" Returns Iwscanresult objects, after a successful scan. """
>>> from ...
Hi @bark given you're a math graduate you might like to know that you have a full version of Mathematica 12.0 included as part of Raspbian. Mathematica has a built in benchmarking capability, which may meet your requirements. Mathematica supports parallel computing out of the box, and given the Pi's limited resource I've had more success creating a ...
Move the code that reads the log into your while True: loop. Don't start a new while True: for each LED as it will never terminate.
Now that I'm home and have had a chance to look at this deeper (with a Raspberry Pi to test it on) I've re-written it to use RPi.GPIO (which works).
import RPi.GPIO as g
from time import sleep
The MPU-6050 is a great choice.
To use it on Raspberry Pi 3, you need a python module. Follow instructions:
1. install the python-smbus package
sudo apt install python3-smbus
2. Install this package from PyPi repository
pip install mpu6050-raspberrypi
If you find a problem, post an issue here.
Okay, I have solved my problem. I reinstalled Python 3.6.
Then I used this command sudo apt-get install libhdf5-dev and then sudo pip install tensorflow and installed TensorFlow successfully!
I think the problem was with my Python installation.
Thanks to all of you for your kindness. Cheers!!!
As Julian mentioned, a Pi based solution won't win any calculation benchmark records. That isn't what they are intended for; however, if you are looking simply as a learning testbed then it is an inexpensive way to play with symmetric and asymmetric cluster type computing and algorithms/etc. I use a blend of Pi3s, Pi4s, and AMD64 arch machines operating ...
For a rough measurement, I generated a 2000 x 2000 matrix with random integer entries between 0 and 9, and timed computation of the determinant in SageMath (I did this twice, with similar results). On my Raspberry Pi 4B, the computation took 15 minutes, compared to just over 3 minutes on my 10-year-old desktop with a quad-core i7-860 processor. The least ...
12V pump will require 12V PSU. 20LPM is a pretty reasonable flow rate for a small pump so your pump PSU will need to have enough power to drive the pump - check the max current draw on startup (which will be higher than the running power draw) and size the PSU accordingly.
Check the contact handling voltage/current for your relays.
"5V" relays (as ...
After the helpful keyword from joan, it was indeed a contact bounce and after a few attempts, here's what my loop looks like now.
print("Started loop sequence")
print("Static Button Pressed")
thanks a lot for the reference. Cool stuff, I'll have a look. Meanwhile, I found a way to start reading the TFMini signal. I'm using the following script:
ser = serial.Serial(
baudrate = 115200,
There are dozens of posts (on this and other sites) explaining why rc.local is unsuitable for starting tasks on a modern systemd distribution.
Rather than reposting you should search them yourself.
There are many factors to consider, and unfortunately there seems to be no single guide which covers them all.
You could start with You could start with rc-...
Depending how the ads1115 is connected to the PCA9546 there are several ways to approach.
For example if the 4 ads1115 is pinned out to have different address ( the ads1115 support upto 4 address; 0x48,0x49,0x4a,0x4b)
you may use this line of code to select 1 - 4 channels, assuming the address of the PCA9546 is 0x77
i2c.writeto(0x77, bytes([0x01]), stop=...
How to use Rpi4B to control multiple ADS1115 I2C ADCs, using PCA9546/TCA9548A I2C Multiplexer?
(1) PCA9645 Datasheet Section 6.1 explains the device slave address is 0x70 to 0x77. In other words, 7 PCA9645s can be placed on the same I2C bus. You use A2, A2, A0 address decode pins/bits to select which PCA9685 device (not channel) to use. ...