Skip to content

Instantly share code, notes, and snippets.

View futureshocked's full-sized avatar

Peter Dalmaris futureshocked

View GitHub Profile
@futureshocked
futureshocked / BME280.py
Created February 25, 2021 22:27
MicroPython driver for the BME280 sensor on the Raspberry Pi Pico
from machine import I2C
import time
# BME280 default address.
BME280_I2CADDR = 0x76
# Operating Modes
BME280_OSAMPLE_1 = 1
BME280_OSAMPLE_2 = 2
BME280_OSAMPLE_4 = 3
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("techexplorations/test")
byte encodebool(boolean* arr)
{
byte val = 0;
for (int i = 0; i<4; i++)
{
val <<= 1;
if (arr[i]) val |= 1;
}
return val;
}
@futureshocked
futureshocked / led-pm-expreriment.ino
Created June 29, 2020 05:26
This sketch will blink the LED at GPIO5 once per second and then go to sleep.
// Written by Peter Dalmaris from Tech Explorations.
// Used to find out how long an ESP32 can last on a LiPo battery.
// This sketch will blink the LED at GPIO5 once per second and
// store the number of blinks in an EEPROM location.
// In between blinks, the ESP32 goes to sleep.
#include "EEPROM.h"
#include <DeepSleepScheduler.h>
#ifdef ESP32
@futureshocked
futureshocked / led-no-sleep-experiment.ino
Created June 29, 2020 05:25
This sketch will simply blink an LED at a 1Hz frequency and increment the counter in EEPROM address 0.
// Written by Peter Dalmaris from Tech Explorations.
// Used to find out how long an ESP32 can last on a LiPo battery.
// This sketch will simply blink an LED at a 1Hz frequency.
// It will increment the counter in EEPROM address 0 every time it blinks.
// https://techexplorations.com
#include "EEPROM.h"
int addr = 0;
#define EEPROM_SIZE 32
@futureshocked
futureshocked / EEPROM-Reader.ino
Created June 29, 2020 05:22
This sketch will initialise the long counter in address 0.
// This sketch will initialise the long
// counter in address 0.
// Written by Peter Dalmaris from Tech Explorations.
// Used to find out how long an ESP32 can last on a LiPo battery.
// https://techexplorations.com
#include "EEPROM.h"
int addr = 0;
#define EEPROM_SIZE 32
@futureshocked
futureshocked / EEPROM-Reader.ino
Last active July 18, 2021 23:22
This sketch will read the long in EEPROM address 0.
// This sketch will read the long in EEPROM address 0.
// Written by Peter Dalmaris from Tech Explorations.
// Used to find out how long an ESP32 can last on a LiPo battery.
// https://techexplorations.com
#include "EEPROM.h"
int addr = 0;
#define EEPROM_SIZE 32
@futureshocked
futureshocked / rf24_receiver.service
Created June 10, 2020 04:05
rf24_receiver.service with Twilio code
# Start the rf24 listener script as a service at startup
# Copy this file into /etc/systemd/system as root, for example:
# sudo cp myscript.service /etc/systemd/system/rf24_receiver.service
# Once this has been copied, you can attempt to start the service using the following command:
# sudo systemctl start rf24_receiver.service
# Stop it using following command:
# sudo systemctl stop rf24_receiver.service
# When you are happy that this starts and stops your app, you can have it start automatically on reboot by using this command:
# sudo systemctl enable rf24_receiver.service
#
@futureshocked
futureshocked / rf24_receiver.py
Created June 10, 2020 04:02
rf24_receiver.py with the Twilio code
#!/usr/bin/env python
# The Twilio code in this script was written by Billy Hare as an extension of the Raspberry Pi Full Stack project.
# With this extension, your Raspberry Pu Full Stack application will be capable
# of sending and receiving text messages via the Twilio service.
# More information: https://techexplorations.com/so/rpifs/
#
# Simplest possible example of using RF24Network,
#
# RECEIVER NODE
# Listens for messages from the transmitter and prints them out.
@futureshocked
futureshocked / env_log.py
Created June 10, 2020 04:00
env_log.py with the Twilio code
#!/usr/bin/env python
'''
FILE NAME
env_log.py
# The Twilio code in this script was written by Billy Hare as an extension of the Raspberry Pi Full Stack project.
# With this extension, your Raspberry Pu Full Stack application will be capable
# of sending and receiving text messages via the Twilio service.