Comments (37)
Guy,
I have a python utility that I made to check the overall configuration. I'll fool with that and see how it behaves.
I'll also try it as a standalone pigpio build.
We are kind of crushing to get this out to distributed clients before the April 8th eclipse in the US for Doppler-shift experiments.
Thanks,
Dave
from pigpio.
Full source code is TL;DR, but available on request.
from pigpio.
Is your code running in multiple threads; ie, do you have multiple sockets open to the daemon?
from pigpio.
No, my code (especially my test code) is run in a single thread.
I do use wait_for_edge() in my main loop to trigger on a rising edge from a GPS/GNSS pulse per second (PPS) input to align my measurements. But even that is not present in the test code, and these i2c_open() calls are made before that loop is begun.
from pigpio.
Also, I guess that I didn't answer your question completely.
I am not aware of any way that I might have more than one socket open to the daemon process. There are internals of pigpio that I don't completely grok, but I only call pigpio_start() one time, and I assume that this is what opens the socket(s).
from pigpio.
[CHILD] i2c_open(RM3100) Magnetometer OK. Reg: 32, Handle: 5
[CHILD] i2c_open(MCP9808) Local Temp OK. Reg: 24, Handle: 1
[CHILD] i2c_open(MCP9808) Remote Temp OK. Reg: 25, Remote Handle: 1
Please break these down to show the actual parameters supplied to the API.
from pigpio.
Gladly.
Essentially these:
#define RASPI_I2C_BUS1 1
#define MCP9808_LCL_I2CADDR_DEFAULT 0x18
#define MCP9808_RMT_I2CADDR_DEFAULT 0x19
#define RM3100_I2C_ADDRESS 0x20
p->pi = pigpio_start(NULL, NULL);
p->magHandle = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) RM3100_I2C_ADDRESS, (unsigned) 0);
p->localTempHandle = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) 0x18, (unsigned) 0);
p->remoteTempHandle = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) 0x19, (unsigned) 0) >= 0);
My full test code is attached.
tests.zip
from pigpio.
I'll take a look at this later on this weekend. If I don't see anything obvious then I would need to replicate the test locally. I'm not inclined to do this as it will require finding suitable i2c devices and so forth. I could be persuaded, however, if you can confirm your issue is replicated on a normal OS install. I'm not sure how your system is configured but it didn't sound like it was the standard image.
from pigpio.
I am running :
$ hostnamectl
Static hostname: Grape2-Pi32
Icon name: computer
Machine ID: 7d6c88b41ced4ce484be513a17843c50
Boot ID: c1936883fcca47c4beb71618a786baf6
Operating System: Raspbian GNU/Linux 11 (bullseye)
Kernel: Linux 6.1.21-v8+
Architecture: arm64
Also:
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
But I (at least) thought that I had used a 32 bit version . This problem has been replicated on other systems used by the project and I am waiting to hear exactly what they are working with. In my case there should be no other major wierdness, as I set up this Pi 4 for building and testing this code. I don't believe I have done much beyond run occasional apt updates in the last 2-3 months.
from pigpio.
Yep, the code is pretty straight forward. Maybe something to do with the pigpio_if2 client. Can you try other clients? I'll take a look at it in the next few days.
from pigpio.
Are you running on only pi4 or other versions as well?
from pigpio.
from pigpio.
You can just use PIGS:
pigs i2co 1 20 0
pigs i2co 1 18 0
pigs i2co 1 19 0
from pigpio.
from pigpio.
You might also want to turn on more verbose debug level:
pigs csi 4
Then show the messages from the error pipe:
cat /dev/pigerr&
from pigpio.
from pigpio.
So if I'm reading this correctly, the three handles returned were 19, 20 and 21. (You can probably turn off the verbosity since there are no errors.)
I would also suggest you restart the daemon and repeat these pigs commands. The results should be 0, 1 and 2.
from pigpio.
from pigpio.
Pigs is executing the same socket interface API as the pigpiod_if client: i2c_open()
. The return value is the handle.
from pigpio.
from pigpio.
I think I can try your test script on my pi4b locally without and i2c devices. But I won't be able to do so until tomorrow.
from pigpio.
Does it do it through pigpio_if2 of some other way?
It shouldn't but I need to look at that code as well.
from pigpio.
from pigpio.
from pigpio.
I have not played much with all the i2c apis. Looking at the documentation it does say the SMBus apis are denoted with some text describing the actual bus cycles occuring. Or something to that affect. I and believe i2c_read_i2c_block_data is one of them.
from pigpio.
Well, I'm not sure about my last statement. It seems i2c_read_i2c_block_data is standard. Sorry I'm not an i2c expert.
from pigpio.
In any case, it shouldn't matter for the open method. I think.
from pigpio.
I just ran your test script and I get the same failure:
[CHILD] pigpio_start(RM3100) OK. p->pi = 0
[CHILD] i2c_open(RM3100) Magnetometer OK. Address: 0x20, Handle: 0
[CHILD] i2c_open(MCP9808-0) Local Temp OK. Address: 0x18, Handle: 1
[CHILD] i2c_open(MCP9808-1) Remote Temp OK. Address: 0x19, Handle: 1
from pigpio.
If I'm not mistaken, it appears you have a single ctlList structure instantiated but you update the same handle member each time you call ic2_open(). Am I missing something?
from pigpio.
from pigpio.
Oops, I think I need more coffee this morning. They are individual elements of the same structure.
from pigpio.
from pigpio.
from pigpio.
Still too early for me to see why, but if I break our the i2c_open() calls from the if statement then it seems to work:
//=========================================================================
// test_pigpio_opens.c
//
// A command line interface for the RM3100 3-axis magnetometer from PNI Sensor Corp.
//
// Author: David Witten, KD0EAG
// Date: March 8, 2024
// License: GPL 3.0
// Note: replaces i2c.c (using file system calls to read(), write(), etc.
// with calls to pigpio.
//=========================================================================
#include <pigpiod_if2.h>
#include "main.h"
int initGPIO(volatile ctlList *p);
void termGPIO(volatile ctlList *p);
void showPIGPIOErrMsg(int rv);
struct tm *getUTC();
ctlList ctl;
//---------------------------------------------------------------
// main()
//---------------------------------------------------------------
int main(int argc, char** argv)
{
// ctlList ctl;
ctlList *p = &ctl;
int rv = 0;
//-----------------------------------------
// Setup magnetometer parameter defaults.
//-----------------------------------------
if(p != NULL)
{
memset(p, 0, sizeof(ctlList));
}
p->pi = 0;
p->i2cBusNumber = RASPI_I2C_BUS1;
p->magHandle = 0;
p->magnetometerAddr = RM3100_I2C_ADDRESS;
p->localTempHandle = 0;
p->localTempAddr = MCP9808_LCL_I2CADDR_DEFAULT;
p->remoteTempHandle = 0;
p->remoteTempAddr = MCP9808_RMT_I2CADDR_DEFAULT;
p->doBistMask = 0;
p->cc_x = CC_400;
p->cc_y = CC_400;
p->cc_z = CC_400;
p->x_gain = GAIN_150;
p->y_gain = GAIN_150;
p->z_gain = GAIN_150;
p->tsMilliseconds = 0;
p->TMRCRate = 0x96;
// p->Version = Version;
p->samplingMode = POLL;
p->readBackCCRegs = FALSE;
p->CMMSampleRate = 400;
p->NOSRegValue = 60;
p->DRDYdelay = 10;
p->magRevId = 0x0;
p->usePipes = USE_PIPES;
// p->pipeInPath = fifoCtrl;
// p->pipeOutPath = fifoData;
p->readBackCCRegs = FALSE;
rv = initGPIO(p);
termGPIO(p);
exit(rv);
}
//---------------------------------------------------------------
// initGPIO()
//---------------------------------------------------------------
int initGPIO(volatile ctlList *p)
{
//-----------------------------------------
// Try to connect to pigpio daemon.
//-----------------------------------------
if((p->pi = pigpio_start(NULL, NULL)) >= 0)
{
fprintf(OUTPUT_PRINT, " [CHILD] pigpio_start(RM3100) OK. p->pi = %i\n", p->pi);
fflush(OUTPUT_PRINT);
}
else
{
fprintf(OUTPUT_PRINT, " [CHILD] pigpio_start(RM3100) FAIL. p->pi = %i\n", p->pi);
fflush(OUTPUT_PRINT);
return -1;
}
//-----------------------------------------
// Register the Magnetometer address.
//-----------------------------------------
int rv;
rv = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) RM3100_I2C_ADDRESS, (unsigned) 0);
p->magHandle = rv;
if ( p->magHandle >= 0)
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(RM3100) Magnetometer OK. Address: 0x%X, Handle: %i\n", RM3100_I2C_ADDRESS, p->magHandle );
fflush(OUTPUT_PRINT);
}
else
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(RM3100) Magnetometer FAIL. Address: 0x%X, Handle: %i\n", RM3100_I2C_ADDRESS, p->magHandle );
fflush(OUTPUT_PRINT);
return -1;
}
//-----------------------------------------
// Register the Local Temp Sensor address.
//-----------------------------------------
// if((p->localTempHandle = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) MCP9808_LCL_I2CADDR_DEFAULT, (unsigned) 0) >= 0))
rv = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) 0x18, (unsigned) 0);
p->localTempHandle = rv;
if(p->localTempHandle >= 0)
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(MCP9808-0) Local Temp OK. Address: 0x%X, Handle: %i\n", MCP9808_LCL_I2CADDR_DEFAULT, p->localTempHandle );
fflush(OUTPUT_PRINT);
}
else
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(MCP9808-0) Local Temp FAIL. Address: 0x%X, Handle: %i\n", MCP9808_LCL_I2CADDR_DEFAULT, p->localTempHandle );
fflush(OUTPUT_PRINT);
showPIGPIOErrMsg(p->localTempHandle);
return -1;
}
//-----------------------------------------
// Register the Remote Temp Sensor address.
//-----------------------------------------
// if((p->remoteTempHandle = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) MCP9808_RMT_I2CADDR_DEFAULT, (unsigned) 0) >= 0))
rv = i2c_open(p->pi, (unsigned) RASPI_I2C_BUS1, (unsigned) 0x19, (unsigned) 0);
p->remoteTempHandle = rv;
if(p->remoteTempHandle >= 0)
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(MCP9808-1) Remote Temp OK. Address: 0x%X, Handle: %i\n", MCP9808_RMT_I2CADDR_DEFAULT, p->remoteTempHandle );
fflush(OUTPUT_PRINT);
}
else
{
fprintf(OUTPUT_PRINT, " [CHILD] i2c_open(MCP9808-1) Remote Temp FAIL. Address: 0x%X, Handle: %i\n", MCP9808_RMT_I2CADDR_DEFAULT, p->remoteTempHandle );
fflush(OUTPUT_PRINT);
showPIGPIOErrMsg(p->remoteTempHandle);
return -1;
}
return p->pi;
}
//---------------------------------------------------------------
// void showPIGPIOErrMsg(int rv)
//---------------------------------------------------------------
void showPIGPIOErrMsg(int rv)
{
char utcStr[UTCBUFLEN] = "";
struct tm *utcTime = getUTC();
strftime(utcStr, UTCBUFLEN, "%d %b %Y %T", utcTime);
#if(CONSOLE_OUTPUT)
fprintf(OUTPUT_PRINT, " [Child]: { \"ts\": \"%s\", \"lastError\": \"%s\" }\n", utcStr, pigpio_error(rv));
fflush(OUTPUT_PRINT);
#else
char errstr[MAXPATHBUFLEN] = "";
sprintf(errstr, " [Child]: { \"ts\": \"%s\", \"lastError\": \"%s\" }\n", utcStr, pigpio_error(rv));
write(PIPEOUT, errstr);
#endif
}
//------------------------------------------
// getUTC()
//------------------------------------------
struct tm *getUTC()
{
time_t now = time(&now);
if(now == -1)
{
puts("The time() function failed");
}
struct tm *ptm = gmtime(&now);
if(ptm == NULL)
{
puts("The gmtime() function failed");
}
return ptm;
}
//---------------------------------------------------------------
// void termGPIO(volatile ctlList p)
//---------------------------------------------------------------
void termGPIO(volatile ctlList *p)
{
// Knock down all of the pigpio setup here.
p->magHandle = i2c_close(p->pi, p->magHandle);
p->localTempHandle = i2c_close(p->pi, p->localTempHandle);
p->remoteTempHandle = i2c_close(p->pi, p->remoteTempHandle);
pigpio_stop(p->pi);
}
from pigpio.
from pigpio.
from pigpio.
from pigpio.
Related Issues (20)
- Initialization issue on debian 12 bookworm HOT 2
- `git pull` or `git clone` actions return 'https://github.com/joan2937/pigpio/': SSL certificate problem: certificate is not yet valid HOT 1
- Possible issue with wave function on PI 4 8GB bullseye 64bit HOT 39
- 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 23
- 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
- Scheduling repetitive SPI writes HOT 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.