Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino sensor logging #4

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
a4be536
Added sensorlogger.ino
quinnc0 Mar 27, 2022
fbbc5ad
Update sensorlogger.ino
quinnc0 Mar 27, 2022
8f38c42
Update readme with sensorlogger.ino instructions
quinnc0 Mar 27, 2022
4bfd3a3
Make .csv default output type
quinnc0 Mar 27, 2022
3788985
Rename sensorlogger.ino to simplelogger.ino
quinnc0 Mar 31, 2022
078f578
Update README.md
quinnc0 Mar 31, 2022
9281fdc
Add sensorlogger.ino
quinnc0 Apr 2, 2022
be15cdd
Update readme for sensorlogger.ino
quinnc0 Apr 2, 2022
75eb44a
Clarify some commenting
quinnc0 Apr 2, 2022
322d667
Add support for voltmeter
quinnc0 Apr 4, 2022
817f208
Add BME280 support
quinnc0 Apr 8, 2022
5259155
Add ADS1015 support
quinnc0 Apr 9, 2022
202af30
Add adafruit anemometer support
quinnc0 Apr 9, 2022
b21f8e5
Add INA219 support
quinnc0 Apr 20, 2022
a1b58cc
update ads1115 and bme 280 support
quinnc0 Apr 30, 2022
983cbe6
Add support for multiple ds18b20s
quinnc0 Apr 30, 2022
97716fe
Add comments to help with configuration
quinnc0 May 11, 2022
4cfe03f
log column labels, i2c address choice added
quinnc0 May 21, 2022
8709f4c
Create ds18b20AddressFinder.ino
quinnc0 May 21, 2022
07aa120
Add DS18B20 addressing options
quinnc0 May 22, 2022
266907f
add detailed instructions for sensorlogger.ino
quinnc0 Jun 6, 2022
0b1b7d3
Add error msg, change INA reading
quinnc0 Jun 7, 2022
843fd6e
Add phototransistor specific support
quinnc0 Jun 23, 2022
d4eab7f
Update DS18B labels, activate all sensors
quinnc0 Jun 27, 2022
168e37d
added 3 second delay at start of program
quinnc0 Jul 3, 2022
f0d1899
Create README.md
quinnc0 Jul 5, 2022
a9123ce
Added fusion 360 source files
quinnc0 Jul 5, 2022
4dd2fc9
added shelter mock up design
quinnc0 Jul 5, 2022
b4aa9b5
add more 3d print source files
quinnc0 Jul 5, 2022
1a7f75c
Add screenshot of design
quinnc0 Jul 5, 2022
893cf8d
Update README.md
quinnc0 Jul 5, 2022
9931b17
Add files via upload
quinnc0 Jul 25, 2022
5c292c5
Rename sensorSerial.ino to sensorserial.ino
quinnc0 Jul 25, 2022
676f72d
Update readme for new files
quinnc0 Jul 26, 2022
229f809
Added logging of sensor data
quinnc0 Jul 27, 2022
a4e4f3f
remove vestigal code pertaining to SD
quinnc0 Jul 29, 2022
2ffb18c
add argument parser
quinnc0 Sep 2, 2022
849e1cc
prevents failed sensor from rebooting nodeMCU
quinnc0 Sep 22, 2022
984d709
added clarifying comment
quinnc0 Sep 22, 2022
6126763
Added retries to SD init and SD write
quinnc0 Oct 4, 2022
1e3751e
add error blink code info
quinnc0 Oct 4, 2022
9f9a770
rename a sensor and activate LED
quinnc0 Dec 26, 2022
f9e1d66
create readme
quinnc0 Dec 30, 2022
3d3147e
add source files
quinnc0 Dec 30, 2022
4e42035
Update README.md
quinnc0 Dec 30, 2022
317c902
Add files via upload
quinnc0 Dec 31, 2022
c113e07
Delete sensorlogger-nodemcu/ads1115anemometerwrap directory
quinnc0 Dec 31, 2022
8572023
Delete sensorlogger-nodemcu/ads1115phototransistorwrap directory
quinnc0 Dec 31, 2022
eb324e5
Delete sensorlogger-nodemcu/ina219wrap directory
quinnc0 Dec 31, 2022
f13cd88
Add files via upload
quinnc0 Dec 31, 2022
82fbe10
Update voltmeterwrap.h
quinnc0 Dec 31, 2022
67aa54d
Update sensorwrap.h
quinnc0 Dec 31, 2022
04be9db
move ifndef
quinnc0 Dec 31, 2022
ac38c4b
move ifndef
quinnc0 Dec 31, 2022
61bd192
move ifndef
quinnc0 Dec 31, 2022
dac59d3
disable sensor classes
quinnc0 Dec 31, 2022
4de8b4f
switch case bug fix
quinnc0 Jan 13, 2023
71fb178
clean up comments
quinnc0 Jan 13, 2023
c32ae37
Move sensorserial to its own folder
quinnc0 Jan 13, 2023
88370a2
add instructions for gopro_as_webcam_on_linux
quinnc0 Jan 27, 2023
fffd71a
Add Station M1 armbian setup instructions
quinnc0 Mar 9, 2023
90ab502
add all weather station logs
quinnc0 Apr 20, 2023
bf8869b
Add most recent logs
quinnc0 Apr 20, 2023
01be395
readme for logs
quinnc0 Apr 20, 2023
8247636
Update README.md
quinnc0 Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 159 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# ecs
Environmental control systems

## sensorlogger.py
---

# sensorlogger.py
Used for logging temperature data to a raspberry pi's SD card. Requires DS18B20, DHT11, or DHT22 sensor.
### Super basic instructions

- Write raspberry pi OS to an SD card
Expand All @@ -15,12 +18,10 @@ Requires python 3

Requires 1-wire interface to be enabled in raspi-config for ds18b20 sensor https://www.raspberrypi-spy.co.uk/2018/02/enable-1-wire-interface-raspberry-pi/

To install dependencies:

To install dependencies:</br>
`pip install -r requirements.txt`

Usage:

Usage:</br>
`python3 sensorlogger.py [GPIO pin #] [Sensor type] {-f output filename}`

GPIO pin # and sensor type required. When -f is used, an output filename can be specified for the log file, defaults to [sensorname].log when -f is not used
Expand All @@ -32,8 +33,159 @@ Sensor type is all lower case. dht11, dht22, or ds18b20
## quickcsvplotter.py
Plots the data collected by sensorlogger.py

Usage:

Usage:</br>
`python3 quickcsvplotter.py [csv filename 1] [csv filename 2] ... [csv filename n]`

Providing filenames in command line is optional. If no filenames are specified, all csvs in current directory will be plotted.

---

# sensorlogger.ino
Used to log data from a variety of sensors to an SD card, using a NodeMCU ESP8266 devkit. Other devices can be used, but some cannot fit the full program onto the flash memory. Also prints data to serial (115200 BAUD) , so can be monitored while running as well. A continuously flashing LED indicates an error with either the SD card or one of the sensors.

### Supported sensors:
- DS18B20
- BME280
- Phototransistor (like PT334-6C)
- INA219
- Anemometer

### Log file:
The first line acts as column headers for the rest of the file. Each of the following lines consist of comma separated values for each of the measurements being taken. Each line is a seperate set of measurements.

### Error blink code:
- 2x blink: SD initialization error
- ~10x blink: SD init ok, but SD write error

## Flashing the NodeMCU ESP8266
To add support for NodeMCU board to Arduino IDE:

1. Go to File -> Preferences -> "Additional Boards Manager URLs:", and paste https://arduino.esp8266.com/stable/package_esp8266com_index.json into the box. Click OK.
2. Now click Tools -> Board: -> "Boards Manager...". In the seach bar, type "esp8266". Click on the esp8266 package, then click "Install".
3. Restart Arduino IDE. Click Tools -> Board: -> ESP8266 Boards -> NodeMCU 1.0 (ESP-12E Module)

To install required libraries:

- Click Tools -> Manage Libraries..., then enter [library name] into search bar. Click "Install". If you are asked if you also want to install missing dependencies, click "Install All".

Do the above step for the following libraries:
- Dallas Temperature
- Adafruit BME280 Library
- Adafruit ADS1X15
- Adafruit INA219

Now you should be able to open the sensorlogger.ino sketch in the Arduino IDE and upload it to the NodeMCU ESP board.

## sensorlogger.ino parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## sensorlogger.ino parameters
## sensorlogger.ino parameters

There's a typo here, you need to remove the space at the beginning of the line

Near the top of sensorlogger.ino, there is a list of parameters than can be changed according to your own hardware setup.

**LOG_FILENAME** -> This is a string indicating the name of the log file. It must fit the 8.3 short format, so it can have a maximum of 8 characters, a period, and then 3 more characters. Each time the program is restarted, a new file is created, so if your LOG_FILENAME = "log.txt", log.txt will be created on the SD card. On subsequent runs, an underscore and a numeral will be appended to the filename.

**POLL_INTERVAL** -> This is how long to wait between sensor readings, in milliseconds.

**NO_SD** -> This is a boolean that allows the program to run without an SD card connected. Set to "true" to run program without SD card, "false" if you want to write data to SD.

**SENSORS** -> This is an array that represents which sensors to take readings from. Each element is a struct of {(enum)[sensor type], (uint8_t)[pin number or hardware address]}. Valid sensor types are: ds18b20, voltmeter, bme280, ads1115, ads1115anemometer, and ina219. For the INA219, the second field will need to contain the hardware address. If you have not altered the INA219 module at all, the address is 0x40. For the BME280, the second field is irrelevant and any int works. For the devices connected through the ADS1115, the second field is the pin on that board.

**DS18B20ADDRESSES** -> This is an array of the addresses of DS18B20 sensors being used and a corresponding label for each one. The addresses are device-specific, so will need to found by running ds18b20AddressFinder.ino with each of your sensors. The label will appear at the column header in the log file so we know which temperature readings come from which sensors.

**CS_PIN** -> This is the chip select (CS) pin for the SPI interface af the SD card.

**LED_PIN** -> This is the pin for the indicator LED. By default it is one of the built-in LEDs on the NodeMCU, but can be an external one if desired.

# ds18b20AddressFinder.ino
Use this to find addresses of all DS18B20 sensors being used. Make sure to mark each sensor as well so they don't get mixed up. It only requires the DallasTemperature library, which should have already been installed.

## ds18b20AddressFinder.ino parameters

**ONEWIRE_PIN** -> This is the pin that the data wire of the DS18B20 is connected to.

## Getting your device addresses
1. Connect first sensor to NodeMCU with ds18b20AddressFinder.ino.
2. Connect NodeMCU to computer with Arduino IDE (or other serial monitor).
3. Open serial monitor and make sure it's at 115200 BAUD.
4. Every 5 seconds, the sensor's address will be printed. Copy that to sensorlogger.ino or just record it for later.
5. Repeat for each DS18B20 you intend to use. Remember to indicate somehow which sensor corresponds to which address.

---

# sensorserial.ino and get_data_from_mcu.py
Used to send data from a variety of sensors to a PC via USB, using a NodeMCU ESP8266 devkit. A continuously flashing LED indicates an error with either the SD card or one of the sensors. This program is very similar to sensorlogger.ino, but it sends data to a PC running a python script rather than log to SD, and the python script controls the timiing of the sensor polls.

## Setting up NodeMCU ESP8266
Follow the same steps as for sensorlogger.ino. Then plug the NodeMCU via USB into a computer that will run the python script.

## get_data_from_mcu.py
To be run from terminal on a PC, Raspberry Pi, etc:</br>
`python3 get_data_from_mcu.py [poll_interval]`

[poll_interval] is the time in seconds between sensor polls, and is an optional argument. Default poll interval is 3 seconds.

Whenever restarting script, NodeMCU should be restarted as well.

# Station M1 setup

## Installing armbian on station m1

- Get the CLI version from here:
https://www.armbian.com/station-m1/

- Write the image to an SD card with something like BalenaEtcher

- Create password for root.
- Create username and password.

### Set up wifi:
- Load the armbian-config utility:</br>
`sudo armbian-config`

- Choose Network->Wifi, then find your wifi network and enter the password.

## Set up autologin:

- Create autologin.conf file:</br>
`sudo nano /etc/systemd/system/[email protected]/autologin.conf`

- Fill it with this (change "wetfish" to whatever your username is):
```ini
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin wetfish --noclear %I $TERM
```

- then:
`sudo systemctl daemon-reload`

- then reboot to confirm it works

## Install kernel headers

- Get the kernel version:
`uname -r`
It should be "6.1.11-media"

- Find all kernel headers packages:
`sudo apt search linux-headers-`
The one we want is linux-headers-current-media. the description says it's for 6.1.11-media. If your kernel is different, find the right one.

- Then install the headers
`sudo apt install linux-headers-current-media`

## GoPro as webcam setup
https://github.com/jschmid1/gopro_as_webcam_on_linux

- Install gopro_as_webcam_on_linux:</br>
`sudo su -c "bash <(wget -qO- https://cutt.ly/PjNkrzq)" root`

- Install dependencies:</br>
`sudo apt install ffmpeg v4l2loopback-dkms curl vlc`

- Plug in gopro via usb and power it on (single press of power button on left). The screen should show a charging icon.
This process needs to continue running, so open a new terminal and type:</br>
`sudo gopro webcam -n -a`

This starts gopro in webcam mode using auto settings (-a), and no input from user (-n).

Once everything gets initialized, near the bottom of the output, look for a line like this:</br>
`Output #0, video4linux,v4l2, to '/dev/video42'`</br>
This means my gopro's device id is 42. remember this.
Binary file added design_assets/Enclosure drain v15.f3d
Binary file not shown.
Binary file added design_assets/INA219_mount v14.f3d
Binary file not shown.
Binary file added design_assets/LM2596_mount_double v5.f3d
Binary file not shown.
Binary file added design_assets/MCU_PCB_mount v14.f3d
Binary file not shown.
5 changes: 5 additions & 0 deletions design_assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<img width="623" alt="shelter assembly" src="https://user-images.githubusercontent.com/101291273/177421951-75a0e291-674e-4229-bc82-77fb8233faad.png">

## 3D Printed Parts
All 3D printed parts should be printed in PETG or other plastic that can withstand some heating.
Binary file added design_assets/ads1115_mount v10.f3d
Binary file not shown.
Binary file added design_assets/battery shim v4.f3d
Binary file not shown.
Binary file added design_assets/battery_clip v1.f3d
Binary file not shown.
Binary file added design_assets/cable gland inserts v3.f3d
Binary file not shown.
Binary file added design_assets/header_bus_mount v4.f3d
Binary file not shown.
Binary file added design_assets/mount_and_shelter_design v5.f3z
Binary file not shown.
Loading