Comments (2)
This really looks like a great use of that byte. We'll try it out and add it in the next firmware version.
from grovepi.
Nice! Tnx.
Sent from my iPhone
On Nov 17, 2015, at 7:01 AM, joemarshall [email protected] wrote:
Quite a few sensors take a long time to return. This means if you have (say) two ultrasonic sensors, 3 analog sensors, you're limited to about 1hz sampling.
The way grovepi currently handles this is by just sleeping for ages (e.g .2 of a second for ultrasonic read, .1 for analogRead).We can make those sleeps tighter (.06 is the minimum for full range on ultrasound I think, and analogRead can live with .02), but what would be ideal would be if it was possible to tell if a value had been read yet by the sensor, so you didn't have to wait.
Thanks to a quirk in the current firmware, this would be pretty trivial to implement, because for most slow commands, it returns a buffer b, which always has byte zero ignored, which could instead be used as a status byte.
So,in receivedata, where it sets index=0, it could set b[0]==0xff. Then in the analogread handling, once it has read the value into the buffer, it could zero b[0].
void receiveData(int byteCount)
{
while(Wire.available())
{
if(Wire.available()==4)
{
flag=0;
index=0;
run_once=1;
b[0]=0xff; // mark that we haven't read the value yet
}
cmd[index++] = Wire.read();
}
}else if(cmd[0]==3)
{
aRead=analogRead(cmd[1]);
b[1]=aRead/256;
b[2]=aRead%256;
b[0]=0; //value is ready for consumption
}
This would allow the python side code to be much faster, like:def fasterAnalogRead(pin):
bus.write_i2c_block_data(address, 1, aRead_cmd + [pin, unused, unused])
while True:
time.sleep(.01)
bus.read_byte(address)
number = bus.read_i2c_block_data(address, 1)
if number[0]==0:
return number[1] * 256 + number[2]
It's not a massive difference with analogread, but ultrasound read speed really slows down things for our students. Ultrasonic read time is dependent on distance, slower for longer distances. We could also take advantage of the knowledge that if we're only interested in say up to 50cm, we can just put a very short delay in, and set to maximum if no value is returned in time..def fasterUltrasonicRead(pin):
write_i2c_block(address, uRead_cmd + [pin, unused, unused])
while True:
time.sleep(.01)
read_i2c_byte(address)
number = read_i2c_block(address)
if number[0]==0:
return (number[1] * 256 + number[2])def shortUltrasonicRead(pin):
write_i2c_block(address, uRead_cmd + [pin, unused, unused])
time.sleep(.05)
read_i2c_byte(address)
number = read_i2c_block(address)
if number[0]==0xff:
return 50
else:
return (number[1] * 256 + number[2])
—
Reply to this email directly or view it on GitHub.
from grovepi.
Related Issues (20)
- NodeJS I2C error HOT 1
- Installing GrovePi: ./install.sh: command not found HOT 4
- Installing on balena.io or docker HOT 1
- No such file or directory -- bash firmware_update.sh HOT 2
- Home Weather Station -- Runtime Error HOT 5
- The GrovePi sensor connection is unstable!! Under Python. Can you help me?
- Help me!My GrovePi’s RST often light up after hours of work HOT 4
- Grove-LCD RGB Backlight V4.0 can't find i2c address on grovepi
- digitalRead not working HOT 1
- GrovePi+ D4 port question--differences among ports or faulty port/pi?
- Ruby test code doesn't run, i2c-devices library problem? HOT 1
- No more need the buffer tools module
- Can I use Tinker board to connect Grove Pi?
- oops: unable to determine board revision from /proc/cpuinfo
- grove_co2_lib.py not compatible with python3 HOT 1
- Hightemperature not reading
- di_i2c module missing ?
- RFR_Tools: Couldn't add Nodejs repo to source because it's not available for "bullseye" distribution
- Error: "pybind11" must be installed before running the build. HOT 4
- compatible with Banana Pi M2 Berry / M5 or Radxa Rock 3 A / Rock 4 C+ ? HOT 1
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 grovepi.