Skip to content

Instantly share code, notes, and snippets.

View dirkjanfaber's full-sized avatar

Dirk-Jan Faber dirkjanfaber

View GitHub Profile
@dirkjanfaber
dirkjanfaber / ledblink.ino
Created July 6, 2016 19:58
blink a led on either an arduino or an esp8266 (with platform.io)
@dirkjanfaber
dirkjanfaber / strftime.c
Created September 1, 2016 08:48
Using LC_TIME with strftime
/*
* The manualpage of strftime notes:
* "The environment variables TZ and LC_TIME are used."
*
* What it does not say is that in order to get the locale
* to actually work in your program is that 2 things are
* needed in the code:
* #include <locale.h>
* and
* setlocale(LC_TIME, "");
@dirkjanfaber
dirkjanfaber / readtempfromfile.c
Created September 20, 2016 19:59
Reading a value from file in c
/*
This example program reads a value from a file. This file can be updated
from another program, while this main program never needs to stop.
gcc -O2 -Wall -o readtempfromfile readtempfromfile.c
*/
#include <stdio.h>
#include <stdlib.h>
@dirkjanfaber
dirkjanfaber / blinkspeak.c
Last active September 26, 2016 18:50
Blink(1) on value increase of thingspeak channel
/*
Program that keeps an eye on a (private) thingspeak channel + field and
acts upon change in value of that field. When the value increases,
a system call to blink1-tool is called to colour the blink(1) led
pumpkin orange.
There are some commandline options:
-v for VERBOSE
-a for the apikey
-c for the thingspeak channel
@dirkjanfaber
dirkjanfaber / spotify_catcher.ino
Created October 24, 2016 19:16
Catch spotify song and display it on an esp98266 OLED
/*
Spotify catcher
Functions as a "man in the middle" for the Spotify Client scrobbles that
go to post.audioscrobbler.com (last.fm).
Works on an esp8266 (Arduino IDE). Connect an oled to pin 3 (SDA) and
pin4 (SCL) to show the currently playing song.
Make sure you put the IP of the esp9266 into /etc/hosts with the name
@dirkjanfaber
dirkjanfaber / commandline_param.c
Created June 1, 2017 09:31
split a commandline into command and paramters
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
typedef struct
{
char *command;
char *parameter1;
@dirkjanfaber
dirkjanfaber / sine.c
Created September 12, 2017 19:40
In order to generate sine tabs for stepper motors
/*
Compile: gcc -o sine sine.c -lm -Wall
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define PI 3.14159265
@dirkjanfaber
dirkjanfaber / bitbangspi.c
Created October 11, 2017 07:32
Bitbang MLX90316 on SPI1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdint.h>
#include <math.h>
#include "pigpio.h"
/*
@dirkjanfaber
dirkjanfaber / as5047d.c
Created October 15, 2017 20:00
Read as54047d sensor from c on raspberry pi
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <stdint.h>
#include <stdio.h>
@dirkjanfaber
dirkjanfaber / servopwm.sh
Created March 15, 2018 12:49
Drive a servo via pwm on the Raspberry Pi from bash
#!/bin/bash
# https://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/software
gpio -g mode 18 pwm
gpio pwm-ms
gpio pwmc 192
gpio pwmr 2000
while [ 1 -gt 0 ]
do