Skip to content

Instantly share code, notes, and snippets.

Avatar

Simen Sommerfeldt sisomm

View GitHub Profile
@sisomm
sisomm / Python_comms.py
Created Feb 23, 2014
The python/raspi side in arduino communication
View Python_comms.py
## How it was with Serial
if(not commands.empty()):
command=commands.get()
if(args.verbosity>0):
print("DISPATCHER: sending to Arduino: "+command)
start=time.time()
arduino.write(command)
# wait until we get OK back
@sisomm
sisomm / Arduino_comms.ino
Last active Aug 29, 2015
Arduino side with Serial and SoftSerial
View Arduino_comms.ino
// How it was with Serial:
// *** Receive ***
byteCount = -1;
byteCount = Serial.readBytesUntil('\n',buffer,bSize);
if (byteCount > 0) { // Really simple parsing
strcpy(command,strtok(buffer,","));
@sisomm
sisomm / leverfilter.awk
Created Jan 24, 2014
Checks for Minecraft locations in a stream of MQTT topics and converts into ARDUINO commands using the payload
View leverfilter.awk
/251/ { print "LED, 0,", ($2=="UP") ? "0" : "1" }
/250/ { print "LED, 1,", ($2=="UP") ? "0" : "1" }
@sisomm
sisomm / lever_pulled_mqtt.js
Last active Jan 4, 2016
How to send changes to a lever in Minecraft to a MQTT broker - and listen for changes in an Arduino
View lever_pulled_mqtt.js
var mqtt = require('sc-mqtt');
var client = mqtt.client(); // local host is default. Otherwise use host, user/pwd
client.connect();
//Subscribe to changes in the state of the Arduino
client.subscribe('/arduino/1/status');
var player; // To remember who pulled the switch
// Here we tell Minecraft to give us control after certain events
events.on('player.PlayerInteractEvent', function (listener, event) {
@sisomm
sisomm / lever_pulled.js
Created Jan 22, 2014
ScriptCraft skript som skriver til en fil hver gang en spak blir trukket i
View lever_pulled.js
//Her gir vi beskjed om å kalle en funksjon når visse hendelser skjer i Minecraft
events.on('player.PlayerInteractEvent', function (listener, event) {
// Vi må finne ut om det var en "Lever" (altså en spak) som ble trukket i. Nå gjelder det ALLE spaker :-)
// Du kan hente ut spakens posisjon vha. block.location om du vil se etter en spesiell
var block = event.getClickedBlock();
var type = block.getType();
if(type==org.bukkit.Material.LEVER) {
if (block.data==3){
writeStatus('commands.txt','DOWN');
@sisomm
sisomm / tail command
Created Dec 30, 2013
Hvordan sende endringer i en fil til en port
View tail command
tail -f commands.txt > /dev/cu.usbserial-A702MUZO
@sisomm
sisomm / startup
Created Dec 30, 2013
Send text from computercraft
View startup
filehandle=fs.open("commands.txt","w") or error("Cannot open file ", 2)
while true do
os.sleep(0.1)
h = redstone.getAnalogInput("front")
if h>0 then
filehandle.writeLine("Down");
else
filehandle.writeLine("Up");
end
filehandle.flush();
@sisomm
sisomm / displayserial
Created Dec 30, 2013
Arduino Scetch to display what´s coming on the serial port
View displayserial
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
char commandbuffer[100];
int readserial()
{
int i=0;