Skip to content

Instantly share code, notes, and snippets.

View didasy's full-sized avatar
🤔
Really makes me think

Andida Syahendar didasy

🤔
Really makes me think
  • Indonesia
View GitHub Profile
@didasy
didasy / square_wave_generator.ino
Last active August 9, 2017 15:12
1Hz - 1MHz Frequency Generator Using Arduino
// Taken from https://forum.arduino.cc/index.php?topic=116094.15
// "Here's my code to set up timer 1 "
// dynamic frequency generator
// for timer2
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned long frequency = 1000000 ; // in hertz
void setup(){
pinMode(9,1);
@didasy
didasy / bme280_influxdb.js
Created August 4, 2017 15:48
NodeJS script to save bme280 data into InfluxDB
const SensorName = "bme280";
const Location = "duren_seribu";
const Influx = require("influx");
const SerialPort = require("serialport");
const port = new SerialPort("/dev/ttyUSB0");
const parser = new SerialPort.parsers.Readline();
const influx = new Influx.InfluxDB({
host: "localhost",
@didasy
didasy / bme280_json.ino
Created August 4, 2017 15:45
Arduino sketch for BME280 to spew JSON data
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
@didasy
didasy / haversine.ino
Created July 31, 2017 19:18
Calculate distance between two GPS point
// Calculate distance between two points
float distanceCoordinates(float flat1, float flon1, float flat2, float flon2) {
// Variables
float dist_calc=0;
float dist_calc2=0;
float diflat=0;
float diflon=0;
// Calculations
@didasy
didasy / mpx4250ap.ino
Created May 18, 2017 10:55
MPX4250AP to PSI for Arduino
float getPressure(int raw) {
// raw 0-1023, get from analogRead();
// 0.004887585532746823 is from 5v/1023
// General info:
// range of voltage reading is 0v-5v
// the sensor outputs MPV to (MPV + 4.692v), while the range is (0.133v - 0.204v - 0.274v) to (4.826v - 4.896v - 4.966v)
// each KPa is 20mV or 0.02V
float voltage = raw * 0.004887585532746823;
// Typical MPV is 0.204v@20KPa
// Maximum pressure is 250KPa
@didasy
didasy / mpx5700ap-stm32.ino
Created May 18, 2017 09:23
MPX5700AP to PSI for STM32Duino
float getPressure(int raw) {
// raw 0-4095, get from analogRead();
// 0.001221001221001221 is from 5v/4095
// General info:
// range of voltage reading is 0V-5v
// the sensor outputs 0V or +ZPO to (0v or ZPO)+4.5V, while the range is 4.587v - 4.7v - 4.813v
// each KPa is 6.4mV or 0.0064V
float voltage = raw * 0.001221001221001221;
// Initializing pressure variable as float
float pressure = 0.0;
@didasy
didasy / mpx5700ap.ino
Last active May 18, 2017 09:21
MPX5700AP to PSI for Arduino
float getPressure(int raw) {
// raw 0-1023, get from analogRead();
// 0.004887586 is from 5v/1023
// General info:
// range of voltage reading is 0V-5v
// the sensor outputs 0V or +ZPO to (0v or ZPO)+4.5V, while the range is 4.587v - 4.7v - 4.813v
// each KPa is 6.4mV or 0.0064V
float voltage = raw * 0.004887586;
// Initializing pressure variable as float
float pressure = 0.0;
@didasy
didasy / fast_pwm.ino
Created January 14, 2017 18:16
Fast PWM for ATMega328
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
pinMode(3, OUTPUT); // output pin for OCR2B, this is Arduino pin number
// In the next line of code, we:
// 1. Set the compare output mode to clear OC2A and OC2B on compare match.
// To achieve this, we set bits COM2A1 and COM2B1 to high.
@didasy
didasy / bearing.js
Created January 10, 2017 10:45
Helpers to get vertical and horizontal bearings given two GPS points with altitude data
function toRadian(num) {
return num * (Math.PI / 180);
}
function toDegree(num) {
return num * (180 / Math.PI);
}
// North is 0 degree, South is 180 degree
function getHorizontalBearing(fromLat, fromLon, toLat, toLon, currentBearing) {
@didasy
didasy / ring.js
Last active November 11, 2016 08:28
Ring data structrure in JavaScript.
class Ring {
constructor(...data) {
this.position = 0;
if (data instanceof Array) {
this.data = data[0];
return;
}
this.data = data;
}