Comments (9)
If the command 0xAA is meant to return two bytes send [0xAA, 0, 0] or three bytes. The returned value should be in the second and third returned bytes. SPI works by transferring bits, you send a bit and receive a bit.
(count, rx_data) = pi.spi_xfer(hndl, [0xAA, 0,0])
if count == 3:
print(rx_data[1], rx_data[2])
from pigpio.
Briliant! That did the trick. Thanks!
👍
from pigpio.
I'm still having some problems.
I can now read the contents of an address on the device but I can't seem to figure out how to send it a command by writing data to an address. Well, at least when reading back the result I get the wrong data.
I see that the python script that uses RPi.GPIO just does some bitbanging and that seems to work like a charm.
from pigpio.
Do you have a script which demonstrates a fault?
from pigpio.
I've prepared the scripts test1.py
and test2.py
to demonstrate the problem. They use the modules pigbmp183.py
and bmp183.py
respectively (available in the same repo).
$ ./test1.py ; sudo ./test2.py
TEST 1
Reading value stored at 0xAA
Value stored at 0xAA : 8600
Writing value 0x2E into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 42211
Writing value 0x34 into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 42211
TEST 2
Reading value stored at 0xAA
Value stored at 0xAA : 8600
Writing value 0x2E into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 26311
Writing value 0x34 into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 42212
Note, that TEST1 displays the value previously obtained from running TEST2. So, it seems that (at least sometimes) pigpiod is unable to write bytes into the BMP183 register.
Rebooting sometimes alleviates the problem for a while, but it is no guarantee for success.
from pigpio.
In the spirit of full disclosure 😄
I also have a 1-wire DS18B20 connected:
# Sensor pin : R-Pi B+ pin
# =================:==============
# VIN (red) = 01 - 3v3
# Data (yellow) = 07 - GPIO04
# GND (blue) = 09 - GND
being interrogated (every 12s) by reading the kernel file somewhere in /sys/bus/...
And a DHT22 connected:
# Wiring (facing frontside of DHT22, left to right):
# Sensor pin : R-Pi B+ pin
# =================:==============
# PWR = 01 - 3v3
# data (digital) = 12 - GPIO18 & R=4k7 > 3v3
# NC = not connected
# GND = 14 - GND
being read (every 12s) using your wonderful DHTXXD
binary (as discussed in issue #60).
Both are performing near perfectly.
from pigpio.
I've had a quick look at the BMP183 datasheet. The first thing which leaps out is that the device requires SPI mode 3. Your code appears to be using the default (SPI mode 0). The first thing to try is opening in SPI mode 3. e.g. pi.spi_open(0, 34000, 3) rather than pi.spi_open(0, 34000).
from pigpio.
Well that completely escaped me.
But thanks to your suggestion I got to read the datasheet again and came across par. 5.2 which states:
In the SPI protocol, the MSB of the register address remains is not used. For example, register 0xF7 is addressed by 0x77 in SPI mode. Bit 7 is replaced by an R/W bit (read: „1‟, write: „0‟).
This never made much sense to me ... until now. (Learn something every day 😉 )
So, I changed the code around a bit. Instead of instructing 0xF4, I instruct 0x74 (clearing the top bit) to write to 0xF4.
print("Writing value 0x2E into address 0xF4")
pi.spi_write(hndl, [0x74, 0x2E, 0])
Now I get this output:
$ ./test1.py ; sudo ./test2.py
TEST 1
Reading value stored at 0xAA
Value stored at 0xAA : 8600
Writing value 0x2E into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 26426
Writing value 0x34 into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 42046
TEST 2
Reading value stored at 0xAA
Value stored at 0xAA : 8600
Writing value 0x2E into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 26423
Writing value 0x34 into address 0xF4
Reading value stored at 0xF6
Value stored at 0xF6 : 42049
Which is the expected output. 🎉 🎈 🍰
Regarding the SPI mode: I tried pi.spi_open(0, 34000, 3)
and pi.spi_open(0, 34000)
which both yield the same results. But, pi.spi_open(0, 34000, 1)
gives erroneous values. I'll force the mode 3 just to be on the safe side.
Again, thank you so very much. Your assistance is greatly appreciated.
from pigpio.
Closing because the system has been running for about 24 hours without issues.
from pigpio.
Related Issues (20)
- pigpio probably won't work on Pi5 (or later Pi's) HOT 4
- Allow get/set of slew rate and hyst bits for gpio HOT 3
- Uninstalling pigpiod attempted to remove /opt
- pigpio will not run on a Pi 5 HOT 16
- Failed on Rpi2 and AlpineLinux HOT 2
- Unclean PWM at certain frequencies. HOT 1
- i2c (am2320) works with pigpio and not pigpiod - could definition of i2c_open() be wrong?
- C pigpio timer inaccuracy on raspbery pi 4 with raspian
- Pigpio BB Serial Read CPU Resource vs. RPI version HOT 4
- Is there a way to flush an open gpioSerialRead buffer? HOT 9
- event_callback with 0 bytes
- Issue with pigpio Initialization on Raspberry Pi 5 Model B HOT 1
- Understanding pigpiod command implementation HOT 9
- Glitch filter active while doing bbSerialRead? HOT 3
- SPI Slave - BSCX not consistently working RPi4B HOT 6
- i2c_open() returns the same handle for two devices on the same bus HOT 37
- Scheduling repetitive SPI writes HOT 3
- Isr doesn't work on raspberry os 12.5 HOT 2
- Continuous Wave Program Concept HOT 6
- SPI6 mode 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pigpio.