![]() data = ("Temperature: % ".format(temp, hum))Ģ3. Create an object, data, which will store a string / sentence containing the temperature and humidity data using string formatting to insert the data into the sentence. The round() function rounds the values to one decimal place. Create two objects, temp and hum to store the temperature and humidity readings from the DHT11. Note that we are now inside the function and our code is now indented to show that it belongs to the function. We need to do this in order to get the raw data. Create a function, dht11data which will work with the scheduler. Decorators are a means to add additional functionality to a function, without impacting the function. Use a Python decorator to instruct Anvil that the next function is callable from the Anvil web app. Using this object we can interact with the DHT11 and get data. Create an object, sensor, to store a connection from our code to the DHT11 temperature sensor. This is where our Anvil Pico Uplink key will be stored. Create an object UPLINK_KEY, and for now store blank data. The flashing cursor, that’s more of a retro vibe. The backlight is essential as the screen can be hard to read. Turn the LCD backlight on, and set the cursor to blink. There are screens with differing sizes, so adjust this to match your screen. This uses the i2c object, the I2C address, and sets the display to have 2 lines and 16 characters. Create an object, lcd, to make a connection between our code and the LCD display. This line of code will scan the I2C bus for the address and store it in the object. Create an object I2C_ADDR to store the I2C address of the LCD display. Create an object, i2c, to create a connection from our code to the I2C bus. The pico_i2c_lcd enables our code to use the LCD display. The dht module is specific for the DHT11 (and DHT22) temperature sensor and acts as an easier means to get data from the sensor. ![]() The time module enables control over the pace of our code. The third module is machine, and from that we need the Pin (GPIO pins) and I2C classes to communicate with the GPIO and LCD screen. Next, uasyncio creates an asynchronous scheduler on the Pico W, we need this for running concurrent functions in our code. The first is anvil.pico and this enables our Pico W to connect to Anvil’s servers. Import three modules of pre-written code. Open main.py, found on the Raspberry Pi Pico W drive.ġ0. Save the file to the Raspberry Pi Pico as pico_i2c_lcd.py These two files enable the use of the I2C LCD screen with the Raspberry Pi Pico W.Ĩ. Open this link and copy the text from the page.ħ. Save the file to the Raspberry Pi Pico as lcd_api.pyĦ. Open this link and copy the text from the page.Ĥ. Thonny is an easy to use Python editor which has been configured to work with the Raspberry Pi Pico.ģ. Follow the steps in our article on how to set up a Raspberry Pi Pico W. Install Thonny on your computer if you haven’t done so already. A static LED means we are connected to the Wi-Fi and ready for our project. Your Raspberry Pi Pico W should now connect to your Wi-Fi and the onboard LED should stop blinking. Anvil’s firmware uses MicroPython, and presents itself as a USB drive, similar to CircuitPython. Open File Explorer and navigate to the new USB drive. The Raspberry Pi Pico will reboot and will now run MicroPython.Ĥ. Drag and drop the Anvil UF2 file onto the RPI-RP2 drive. Release BOOTSEL once the drive RPI-RP2 appears on your computer.ģ. Push and hold the BOOTSEL button on the Pico, then connect to your computer using a micro USB cable. Download the custom Raspberry Pi Pico W firmware from Anvil.Ģ. Before we can write any code for our project we first need to flash the custom firmware to the Pico W, and connect to our Wi-Fi.ġ. The firmware is based on MicroPython, with the Pico W appearing as a USB drive with two files (boot.py and main.py). Setting up the Raspberry Pi Pico WĪnvil uses a custom firmware image for the Raspberry Pi Pico W, an image which simplifies connecting the Pico W to Anvil’s services. SCL: (Orange Wire) Connect to I2C0 SCL on the Pico W.Ĭheck your wiring before moving onwards. SDA: (Yellow Wire) Connect to I2C0 SDA on the Pico W. VCC: (Red Wire) Connect to VBUS on the Pico W. GND: (Black Wire) Connect to any GND on the Pico W.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |