Added Python GIL information.
Source Link
NomadMaker
  • 1.5k
  • 6
  • 10

If you are using a properly-sized power supply, then I believe this to be a timing issue. Since the distance sensors work when you're only using four threads, then I suspect that it's not a power problem.

The SR04 requires precise timing to calculate distance. If one of the other threads is taking too much of the CPU time, then perhaps the thread that reads the SRO4's doesn't get enough time to read the sensors properly.

The Raspberry Pi is more of an SBC (single-board computer) that typically runs Linux. This means that many other processes are running at the same time as your python program, and they may also work to prevent your program from having enough time to calculate the distance.

For that reason, it's usually better to put sensors which need precise timing onto a microcontroller such as an Arduino. You could communicate between the Raspberry Pi and the Arduino with I2C.

Another way to do this is to use sensors that communicate with I2C or SPI. These sensors don't require the precise timing calculations that the SR04's do.

One possible thing for you to look into is Python's GIL (Global Interpreter Lock) which causes only one thread to run at a time. This might cause a difference between how you think your code is running and how it actually runs.

If you are using a properly-sized power supply, then I believe this to be a timing issue. Since the distance sensors work when you're only using four threads, then I suspect that it's not a power problem.

The SR04 requires precise timing to calculate distance. If one of the other threads is taking too much of the CPU time, then perhaps the thread that reads the SRO4's doesn't get enough time to read the sensors properly.

The Raspberry Pi is more of an SBC (single-board computer) that typically runs Linux. This means that many other processes are running at the same time as your python program, and they may also work to prevent your program from having enough time to calculate the distance.

For that reason, it's usually better to put sensors which need precise timing onto a microcontroller such as an Arduino. You could communicate between the Raspberry Pi and the Arduino with I2C.

Another way to do this is to use sensors that communicate with I2C or SPI. These sensors don't require the precise timing calculations that the SR04's do.

If you are using a properly-sized power supply, then I believe this to be a timing issue. Since the distance sensors work when you're only using four threads, then I suspect that it's not a power problem.

The SR04 requires precise timing to calculate distance. If one of the other threads is taking too much of the CPU time, then perhaps the thread that reads the SRO4's doesn't get enough time to read the sensors properly.

The Raspberry Pi is more of an SBC (single-board computer) that typically runs Linux. This means that many other processes are running at the same time as your python program, and they may also work to prevent your program from having enough time to calculate the distance.

For that reason, it's usually better to put sensors which need precise timing onto a microcontroller such as an Arduino. You could communicate between the Raspberry Pi and the Arduino with I2C.

Another way to do this is to use sensors that communicate with I2C or SPI. These sensors don't require the precise timing calculations that the SR04's do.

One possible thing for you to look into is Python's GIL (Global Interpreter Lock) which causes only one thread to run at a time. This might cause a difference between how you think your code is running and how it actually runs.

Source Link
NomadMaker
  • 1.5k
  • 6
  • 10

If you are using a properly-sized power supply, then I believe this to be a timing issue. Since the distance sensors work when you're only using four threads, then I suspect that it's not a power problem.

The SR04 requires precise timing to calculate distance. If one of the other threads is taking too much of the CPU time, then perhaps the thread that reads the SRO4's doesn't get enough time to read the sensors properly.

The Raspberry Pi is more of an SBC (single-board computer) that typically runs Linux. This means that many other processes are running at the same time as your python program, and they may also work to prevent your program from having enough time to calculate the distance.

For that reason, it's usually better to put sensors which need precise timing onto a microcontroller such as an Arduino. You could communicate between the Raspberry Pi and the Arduino with I2C.

Another way to do this is to use sensors that communicate with I2C or SPI. These sensors don't require the precise timing calculations that the SR04's do.