This will print the light level on the built in light sensor and the current range, in cm. Range3 = (range1 << 8) + range2 return range3 It is more complex, becuase you have to write a command to the sensor to get it to begin reading. You will then need the following python file. Note that I have left the compass module connected. Run i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f You can even leave the compass module in as well, because I2C can handle multiple devices on one line. I found that this sensor would not work off 3.3V, but again, I bear no responsibility for you putting 5V through your Pi pins. Wire it in in exactly the same way as before, with power, SDA and SCL connected to the Pi. The second example is the SRF08 range sensor, with built in light sensor. in the meantime, drink a good cappuccino. sudo apt-get update -y & sudo apt-get upgrade -y Wait a good few minutes. Update the dependencies Connect to your Raspberry Pi and update the dependencies. Wait a few minutes until the disk is ready. Then, run the command with sudo python whateveryoucalledit.p and you should get values written to your screen in a long list. Prepare Raspbian First, flash your SD drive from Etcher or another application. This program should be saved as anything, but add ".py" on the end. You then need the following python file: import smbusīearing = bearing3599() #this returns the value to 1 decimal place in degrees.īear255 = bearing255() #this returns the value as a byte between 0 and 255. This shows that the module is on address 0圆0. The Raspberry Pi Imager will work if you don’t already have one. Raspberry Pi Pico RP2040 Waveshare Pico-ResTouch-LCD-3.5 ( manufacturer wiki) According to the manufacturer, the board is equipped with a ILI9488 controller for the LCD (interestingly, it says ST7789 at some place) XPT2046 for the Touch function The sample code does not work, if no SD-card is present. In my case, this returned: 0 1 2 3 4 5 6 7 8 9 a b c d e fĦ0: 60 - You’ll also need software to image the Pi’s SD card. When you have connected it, run the command "i2cdetect -y 0". Then, connect the SDA and SCL lines to the Pi SDA and SCL, and you are ready to roll. I used the 5V line, which they recommend not doing because it might damage your pi, It worked for me, and has caused now damage, but I am not responsible if your's fries. To use the CMPS03 compass module, connect the power to V+ and 0V, from the Pi. We now have everything ready to start using I2C! On my setup, it returned this output, because there was nothing connected: 0 1 2 3 4 5 6 7 8 9 a b c d e fĠ0: -ġ0: -Ģ0: -ģ0: -Ĥ0: -ĥ0: -Ħ0:. To test the software, run the command i2cdetect -y 0 to see if there is anything connected. Now run sudo reboot to reboot, and test the new software. To configure the software, we will add the Pi user to the I2C access group, by running the command sudo adduser pi i2c. The other package needed can be installed by running sudo apt-get install python-smbus. If this fails, try running sudo apt-get update and try again, else run crying to your nearest nerd. The first command to run is sudo apt-get install i2c-tools. There are a few packages that will need installing to use I2C.
0 Comments
Leave a Reply. |