I have a Raspberry Pi in my boat that uses I2C to read a number of voltages and currents (using ADS1115 A2D) so I can monitor the battery condition etc.
At present various different scripts (i.e. processes) just read the values using the I2C bus whenever they need to but I'm pretty sure this (quite rarely) results in false readings because two processes try to read at the same time. Thus I'm looking for ways to prevent simultaneous access. One fairly obvious way is to have single process/script which reads the A2D values continuously and writes them to a file. All other scripts then read from the file as needed, a simple file lock can then be used to prevent simultaneous access (well, simultaneous access when the writing process is writing). Is this the simplest approach? Are there better ways using multiprocess? (They look more complicated though). The I2C bus itself has a mutex but I don't think this guarantees that (for example) an A2D reading is atomic because one reading takes more than one I2C bus access. Would a mutex of some sort around each I2C transaction (i.e. complete A2D reading) be a better way to go? -- Chris Green ยท -- https://mail.python.org/mailman/listinfo/python-list