Skip to content

Instantly share code, notes, and snippets.

View pavelmetrokhin's full-sized avatar

pavelmetrokhin

View GitHub Profile
@pavelmetrokhin
pavelmetrokhin / rfid-access-control.py
Last active April 17, 2018 18:24
Control the Electromagnetic Lock using RFID & NFC EXpansion
import sys, os, time
from OmegaExpansion import oledExp
from OmegaExpansion import relayExp
import subprocess
import json
#initializing the Relay and Oled Expansions, and block the lock if it's open
def initial_setup():
#initializing the Relay and Oled Expansions
status_oled = oledExp.driverInit()
@pavelmetrokhin
pavelmetrokhin / index.html
Created December 22, 2017 21:55
A web page that displays the current position of the potentiometer
<!DOCTYPE html>
<html>
<head>
<title>Omega Dial</title>
<script src="jquery.min.js"></script>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script>
<script src="jquery.knob.min.js"></script>
</head>
<style>
body {
@pavelmetrokhin
pavelmetrokhin / potentiometerServer.py
Created December 22, 2017 21:22
Connects to MQTT topic, hosts the HTTP server and hosts the Web page with the most recent potentiometer position
import os, sys, getopt, json
import paho.mqtt.client as mqtt
from SimpleHTTPServer import SimpleHTTPRequestHandler
import SocketServer
position = 0
class PotentiometerHTTPHandler(SimpleHTTPRequestHandler):
def __init__(self, request, client_address, server):
SimpleHTTPRequestHandler.__init__(self, request, client_address, server)
@pavelmetrokhin
pavelmetrokhin / get_potentiometer_reading.ino
Created December 22, 2017 20:51
continuously obtain a potentiometer reading and send it to Omega via Serial
// analog pin for reading the potentiometer value
int potPin = A0;
// resistance value
int potValue = 0;
// delay between sensor reads for stability
int readDelay = 100;
// code to be run once at the start of the program
@pavelmetrokhin
pavelmetrokhin / mqtt_get_angle_publish.py
Last active December 18, 2017 22:44
Receive a servo angle from the Arduino and publish it to MQTT
import os, sys, getopt
import paho.mqtt.client as mqtt
from motors import Servo
# Main program to obtain the servo angle and publish to MQTT
def __main__():
#Setup MQTT and Instantiate the Servo Motor
mqttc = mqtt.Client()
servoMotor = Servo(0, 500, 2500)
## Define the MQTT Callbacks
@pavelmetrokhin
pavelmetrokhin / motors.py
Created December 13, 2017 23:06
Servo Expansion class for the Omega
from OmegaExpansion import pwmExp
class OmegaPwm:
"""Base class for PWM signal"""
def __init__(self, channel, frequency=50):
self.channel = channel
self.frequency = frequency
# check that pwm-exp has been initialized
@pavelmetrokhin
pavelmetrokhin / get_servo_angle.ino
Last active December 18, 2017 23:03
Obtaining a servo angle and send it to the Omega
// analog pin for reading the potentiometer value
int potPin = A0;
// angle of the servo to be send to Omega
int angle = 0;
// delay between sensor reads for stability
int readDelay = 100;
// code to be run once at the start of the program
@pavelmetrokhin
pavelmetrokhin / request_and_receive.py
Created December 8, 2017 22:08
A python program to request and receive the data back from the slave (arduino)
from OmegaExpansion import onionI2C
#initializing I2C communication
i2c = onionI2C.OnionI2C(0)
#initializing Slave's device address and a degree sign for printing
devAddres = 0x08
degree = unichr(176)
#reading and storing the value of the 0x00 register
@pavelmetrokhin
pavelmetrokhin / arduino_i2c_slave.ino
Last active December 12, 2017 21:49
A C sketch to receive voltage reading from the analog sensor, convert to Celsius and Fahrenheit values, receive the special registers from the master device (Omega) and transmit the data back to the master
//the scale factor of TMP36 (temperature sensor) is 10 mV/°C with a 500 mV offset to allow for negative temperatures
#include <Wire.h>
// the analog pin number connected to the TMP36
#define slaveAddr 0x08
// defining global flags as actual registers
#define RD_REG_TEMP_INT_CEL 0x00
#define RD_REG_TEMP_FRA_CEL 0x01
#define RD_REG_TEMP_INT_FAR 0x02
@pavelmetrokhin
pavelmetrokhin / talk_to_tmp36.ino
Last active December 8, 2017 22:06
A C sketch to receive a command from the Omega, obtain the temperature value from the Analog sensor TMP36 and send back the results back to the Omega
//the scale factor of TMP36 (temperature sensor) is 10 mV/°C with a 500 mV offset to allow for negative temperatures
// the analog pin number connected to the TMP36
int sensorPin = A0;
void setup()
{
//initializing serial communication with the Omega2 for sending sensor data
Serial.begin(9600);
}