代写ECPS 206 Lab 2 Hardware Setup代写留学生Python语言

ECPS 206
Lab 2
Hardware Setup
● Recommend to install the heat sinks
○ https://www.youtube.com/watch?v=E-4GaAz7XNM
● Recommend to install t
he case and power the fan with 3.3V or 5V.
● Connect 4 LEDs with wires and resistors (to protect LEDs)
● Connect a T-type extension board and cables
○ https://www.youtube.com/watch?v=RCIL35e47mk
RPi 4: Connect with Breadboard and LEDs
RPi 4: Layout
● Board & Intro:
https://www.etechnophiles.com/raspberry-pi-4-gpio-pinout-specifications-and-sc
hematic/
● Pins: https://pi4j.com/1.4/pins/rpi-4b.html
● Datasheet: https://datasheets.raspberrypi.org/rpi4/raspberry-pi-4-datasheet.pdf
● Pick some GPIO XX for LED connections
RPi 4: Connect RGB Light Sensor TCS34725
From To Description
RPi / G TCS34725 /GND Ground for I2C Light Sensor
RPi / 3V3 (PIN 1) TCS34725 / 3V3 3.3V Power for I2C Light Sensor
RPi / SDA1 I2C (PIN 3) TCS34725 /SDA SDA for I2C Light Sensor
RPi / SCL1 I2C (PIN 5) TCS34725 /SCL SCL for I2C Light Sensor
TCS34725 / LED TCS34725 / INT Connectng these two pins together allow for softwarecontrol of bright LED on TCS34725 board
ESP8266: Ambient Light sensor (photoresistor)
● Follow the instructions and example code to test connection.
○ https://www.instructables.com/id/NodeMCU-With-LDR/
ESP8266: Ambient Light sensor (photoresistor)
● Example code (link from
previous slide, or check similar
one in File > Examples > Analog
> AnalogInOutSerial) utilizes
analog signal read function.
Software Setup
● Recommend to use Raspberry Pi Imager to pre-configure OS
● Refer to the link to download the Imager on your laptop to write OS image into SD card:
https://www.raspberrypi.com/software/
● How to use Imager: https://www.youtube.com/watch?v=ntaXWS8Lk34
● If you have monitor & keyboard & mouse, choose the Raspberry Pi OS (32-bit).
● Configure WiFi: https://www.seeedstudio.com/blog/2021/01/25/three-methods-to-configure-raspberry-pi-wifi/
● If you don’t have monitor and would like to work on SSH Linux console with cellphone hotspot, you can follow these
steps in Imager: https://www.pragmaticlinux.com/2021/08/raspberry-pi-headless-setup-with-the-raspberry-pi-imager/
● Note that after pressed Ctrl-Alt-X for Advanced options, these are recommended:
● Checked “Set hostname”. Optional to change the “raspberrypi” to preferred name.
● Checked “Enable SSH”. Select “Use password…” and type any password
● Checked “Configured WiFi”. Type your hotspot WiFi SSID & password. Change WiFi country to US
(faster by delete it and type)
● Checked “Set locale settings”, choose America/… and us
● Checked “Skip first-run wizard”
● Unchecked “Play sound…”, “Eject media…”, “Enable telemetry”.
● Save to close options
● Press Write and wait for it.
RPi 4: Install the Raspberry Pi OS
Logged in Raspberry Pi OS via either GUI desktop or SSH.
Open console:
1. Turn on I2C Interface
● sudo raspi-config
● Choose Interfacing Options > I2C > Yes
2. Install the necessary packages
● sudo apt-get update
● sudo apt-get install -y git build-essential python3-dev python3-setuptools python3-pip python3-smbus
3. Reboot
● sudo reboot
4. Install Adafruit Python TCS34725
● git clone https://github.com/adafruit/Adafruit_Python_TCS34725.git
● cd Adafruit_Python_TCS34725/
● sudo python3 setup.py install
5. Run the simpletest.py example in examples/ folder: python3 simpletest.py
RPi 4: Install the TCS34725 python library
Network issue
● Using “UCInet Mobile Access”
○ Find the MAC address of ESP8266
■ https://techtutorialsx.com/2017/04/09/esp8266-get-mac-address/
○ Find the MAC address of RPi 4
■ In the terminal or SSH, Type the command “cat /sys/class/net/wlan0/address”
○ Register the MAC addresses to UCI
■ http://apps.oit.uci.edu/mobileaccess/registration/
● Or use your cellphone hotspot function to setup manageable and isolated
network
○ Recommend and it allows broadcast for other HWs.
Python UDP examples for RPi
● Basic Python UDP echo client example:
○ https://pymotw.com/3/socket/udp.html
● Python UDP Send/Recv examples:
○ https://stackoverflow.com/a/27893987
○ set the timeout to know the 5 seconds is up.
C UDP Example for ESP8266
● Reference:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.h
tml
● Example: https://siytek.com/esp8266-udp-send-receive/
● Or, you can also check in IDE: File > Examples > ESP8266Wifi > Udp.
change the “your-ssid” to the Wifi network name and “your-password” if there
is a password or empty otherwise.
#define STASSID "your-ssid"
#define STAPSK "your-password"
○ Try using RPi 4’s terminal with the following command to confirm the network is working:
○ nc -u 8888
C UDP Example for ESP8266
● Example to get IP address from socket and blink the IP address on ESP8266
○ https://github.com/rin67630/Blink-my-IP
Hint
● Design your message format to send
○ When ESP8266 receives first message, keep the IP and port of RPi globally for later use.
○ Use sprintf and strncmp to deal with string type messages on ESP8266.
○ On ESP8266’s side, lux value can be converted to bytes buffer before sending (use itoa () )
○ On RPi’s side, recv length is recommended to be equal to buffer length set in ESP8266. Then
actual value is decoded from bytes buffer.
● The values from TCS34725 have different range (based on the settings) than the value from analog
photoresistor (0-1024). It is easier to scale the value of one side to meet the yellow LED condition
under normal ambient light.
○ If initially photoresistor senses 850 and TCS34725 senses 150, you can calculate like (lux -
850) / (1024-850) * (1024) + 150 on ESP8266 side.
○ Suggested settings: TCS34725_INTEGRATIONTIME_101MS and TCS34725_GAIN_4X
■ Relevant constants in python library:
https://github.com/adafruit/Adafruit_Python_TCS34725/blob/996396cd095522d788b7b1
5d20fd44e566c8464e/Adafruit_TCS34725/TCS34725.py#L77
● Onboard LEDs on ESP8266 are OFF only when HIGH value is digitalWrite.
● Use threading to create threads or shorter socket timeout with counter to control the blink white
LED.
Demo Video for HW2
https://uci.yuja.com/V/Video?v=3759002&node=12858963&a=1832739861
When started, RPi should
turn on the white LED and
send a UDP message to
ESP8266 to initiate the
communication.
After receiving the first UDP
message from RPi, ESP8266
should flash its onboard LED
every 500 ms, collect the light
sensor value every 500 ms, and
send the average value in the
last 5 seconds back to the RPi
every 2 seconds via UDP.
ESP8266 prints the sliding
window every time it collects a
sensor value. ESP8266 also
prints the average when it is
time to send the average value.
Whenever RPi receives a
message containing the remote
light reading, RPi should turn off
the white LED. It will turn on the
green LED if the local light value
is higher, or the yellow LED if
the local value is within ±20%
of the remote value, or the red
LED if the local value is lower
than the remote value.
Whenever RPi receives a
message containing the remote
light reading, RPi should turn off
the white LED. It will turn on the
green LED if the local light
value is higher, or the yellow
LED if the local value is within
±20% of the remote value, or the
red LED if the local value is lower
than the remote value.
Whenever RPi receives a
message containing the remote
light reading, RPi should turn off
the white LED. It will turn on the
green LED if the local light value
is higher, or the yellow LED if the
local value is within ±20% of the
remote value, or the red LED if
the local value is lower than
the remote value.
If RPi hasn't received a message from ESP8266 for 5 seconds, RPi flashes the
white LED on and off every 500 ms to indicate an error condition (e.g. ESP8266 is
accidentally turned off). It keeps flashing until another light value is received and goes
back to Step 4.
If RPi hasn't received a message from ESP8266 for 5 seconds, RPi flashes the white
LED on and off every 500 ms to indicate an error condition (e.g. ESP8266 is accidentally
turned off). It keeps flashing until another light value is received and goes back to
Step 4.



热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图