Raspberry Pi as a dedicated “Twitch Plays Pokemon” Viewer

Update: 12 October 2016

Thanks to commenter Fishscene for pointing out the following:

livestreamer for twitch is broken. Twitch made a change to require an OAUTH token and disallow annonymous viewing. livestreamer hasn’t been updated in over a year. Project was forked to streamlink and includes twitch fix:

https://github.com/streamlink/streamlink

I’ll leave this for prosperity, it has been linked to several time.

I’m not too proud of this but my laptop couldn’t handle streaming ‘Twitch Plays Pokemon’ and me doing day to day tasks and I can’t stop watching now. I’ve decided to use a spare Raspberry Pi have to keep the stream open 24/7 on a spare monitor I have.

Here’s a video:

Thanks to Livestreamer it is unbelievably easy to view this stream.

The following command will install Livestreamer:

To make things even simpler, I have also written the following python program that will open the stream to HDMI. You can set the line that runs this program as a cron job to run at boot if you wish.

Which you can get on your pi with:

Once it is downloaded you can run it with:

And it will open on your HDMI monitor.

Accessing both SPI ports on the raspberry pi using python

Turns out it’s not that hard at all! Here’s a video of the whole thing working:

This basically works around concepts I first explained here. It’s still really cool though! SPI is really fast and really easy to use, perfect for a novice like me.

Here are the physical representations and schematics of the setup seen on my desk:

Images generated by fritzing.

Here’s the code that makes it all work!

Here is some further reading:

http://www.megaleecher.net/sites/default/files/images/raspberry-pi-rev2-gpio-pinout.jpg

http://hertaville.com/2013/07/24/interfacing-an-spi-adc-mcp3008-chip-to-the-raspberry-pi-using-c/

http://tightdev.net/SpiDev_Doc.pdf

Thanks for reading!

Using a pair of Arduinos to mimic a keyboard

Here’s a video:

So in my last post I showed you a way that I used a single arduino to talk to a Raspberry Pi (or any other computer) over HID. I’ve updated the project a bit and now I can input any number of things into the pi. Basically this is how it works.

Serial Console on computer -> Arduino Mega -> software serial port -> Arduino micro -> HID on other second computer (in this case the Pi)

There are two buttons that handle pressing the enter key and the delete key as those are hard to send over serial.

There are a few bits of relevant code, both for the arduino. Here’s the mega’s code:

And here’s the side for the arduino micro, that writes as an HID.

Using Arduino Micro as a USB keyboard for Raspberry Pi

Greetings from WPI! Here’s a video:

Desperate times call for desperate measures. I recently found out that a club at my school is essentially a hackerspace equipped with 3D printers so I could finally print enclosures for the PiPlanter and the DSFU. But that means I would need to finial the designs for both of them. I needed to find a way to interface with this thing here. So being the idiot that I am, I forgot a USB keyboard, I forgot an analog video cable, I forgot a monitor for the pi and forgot to update the Pi to the latest Raspian build.

What I did bring was an Easy Cap Capture Card in addition to my standard idea-kit which among other things consists of an Arduino Micro, some buttons, some resistors, and wire.

Essentially all I needed to do was connect the Pi to the EasyCap, and be able to send 4 different phrases to it over the keyboard. I needed to be able to send ‘pi’,’password’ (not my actual password), ‘ifconfig’ and enter. I realized that I could easily send this data to the Pi via the Micro as it has the Keyboard. functions built in.

As you can see in the video it worked! And I’m kind of stunned that it did. I can now SSH into the Pi.

Here’s the code for the Arduino:

Thanks for Reading!

My Mobile Raspberry Pi Setup

So I’m on vacation, and I needed a way to do some raspberry pi work while I’m away from my primary workstation.

I don’t have a wireless dongle, and running an ethernet cable isn’t an option, so I decided to go with an EasyCap capture card and a usb keyboard.

Here’s a video explaining my setup:

http://youtu.be/kOcaFUv2BV0

Simple ADC with Raspberry Pi using MCP3008

Hello!

So for my own benefit, here’s the steps you need to take to get analog inputs working with a Raspberry Pi.

I’m grabbing most of this from: http://scruss.com/blog/2013/02/02/simple-adc-with-the-raspberry-pi/

The first thing you’ll need is an MCP3008. Using jumper wires, hook it up to your pi using this diagram.

Power your RPi up and run the following commands to get it all set up.

First thing’s first, you’ll need to enable SPI in the kernel so:

Comment out the spi-bcm2708 line so it looks like this:

Then run this to make it more permanent.

Now for the real meat of it. You’ll need these packages for SPI and the WiringPi library makes things a whole lot easier for us.

Now everything should be good to go, now for the python.

You can debug this any way you like, but my favorite way to do it is using the program geany. I like to start up a VNC server with root so I don’t get into any trouble with the GPIO permissions.

But here’s the program.

And that’s pretty much it, the result should look something like this:

There you go!

Spitting incoming serial data arduino and visual basic

UPDATED CODE HERE


Hello! as you can probably tell, my last post was written in a fury of incoherency, but I needed to get the code out there so it is what it is.

The main focus of this post is to showcase the arduino program. The visual basic in the video is very simple, and there will be much more on that later.

This below program will take a string of characters fed to the arduino and split them into usable parts. This is a very valuable tool for working with serial and arduino. It’s pretty well commented, but if you have any questions, PLEASE leave a comment. I’d love to see some conversation here.

So for example if you inputted

[code]
123,456.
[/code]

it would output

[code]
123|separator|456
[/code]

to the lcd, or the serial monitor if you tweaked the code.

Now for the code in the video. The only different part about this is that it writes the two values to the servos.

const char EOPmarker = ‘.’; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

#include // we’ll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.

#include //we’ll need this for the lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //pins for the lcd, I set it up using the ladyada tutorial.

#include
Servo left_servo;
Servo right_servo;

int left_servo_pos;
int right_servo_pos;
void setup(){
lcd.begin(16, 2);
left_servo.attach(2);
right_servo.attach(3);
Serial.begin(9600); //changing this to other speeds has not been tested using this meathod
}

void loop() {
if (Serial.available() > 0) { //makes sure something is ready to be read
lcd.clear(); //clears for incoming stuff, won’t clear if there isin’t data to be read
static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read
char inchar = Serial.read(); //assigns one byte (as serial.read()’s only input one byte at a time
if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender
serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read
bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.
}
else { //once the end of package marker has been read
serialbuf[bufpos] = 0; //restart the buff
bufpos = 0; //restart the position of the buff

left_servo_pos = atoi(subStr(serialbuf, “,”, 1));
lcd.write(“Left Servo:”);
lcd.write(subStr(serialbuf, “,”, 1)); //witres the first bit of content before the first comma (or other seperator) to the lcd
left_servo.write(left_servo_pos);

lcd.setCursor(0, 1);

right_servo_pos = atoi(subStr(serialbuf, “,”, 2));
lcd.write(“Right Servo:”); //this signifies that the first seperation has occured
lcd.write(subStr(serialbuf, “,”, 2)); //same thing as 2 lines above, but with the second parts. this can be repeated
right_servo.write(right_servo_pos);
}
}
}

// below is just function logic, which I do not fully understand. but it works.
char* subStr (char* input_string, char *separator, int segment_number) {
char *act, *sub, *ptr;
static char copy[MAX_STRING_LEN];
int i;

strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

sub = strtok_r(act, separator, &ptr);
if (sub == NULL) break;
}
return sub;
}

//esologic.com
//Thanks to http://arduino.cc/forum/index.php?topic=119429

Splitting Strings Arduino

UPDATED CODE HERE


 

Hello!

Today I ordered parts for the proto phase of the plane.

This is a bit of code i’ve found that’s usefully for splitting strings in the arduino C

A comprehensive guide to controlling a lamp via the internet on any web enabled device.

Yay Chinese knockoffs!

Hello! sorry about my absence, I’ve been very busy with school/baseball over the past few weeks, but summer is soon, and I’ll be updating with a higher frequency once that happens.

So. you’ll need a few things in order to make sure this whole process works.

1. Multiple ethernet connections.

2. An Arduino and a compatible wiznet device (ethernet shield)

Yay Chinese knockoffs!

Here I’m using an arduino knockoff I got 2 years ago when I first got into hobby electronics, and an “ETHERNET 4 NANO” by gravitech. I didn’t want to permanently implement my arduino nano, but I still wanted to be able to do the project. It’s powered by 5v from my computer (well from a powered hub) and the brown striped wire goes to the + on the powerswitch tail II. The blue cable is ethernet.

3. A webserver with php installed on it. (Mine’s just LAMP’d)

This is the important part. The arduino is accessing a .php document on the server to tell weather or not the lamp should be on. The UI is also hosted out of the servo. That laptop is my old HP laptop that I’ve had for almost 6 years, it’s now got ubuntu 10.04 LTS on it and it’s been LAMP’d among other things.

4. Something that can SAFELY switch line voltage. (I’m using a powerswitch tail II, because I really don’t want to get killed, and it’s also very simple – if you’re using naked relays, please for the love of god, be careful with line voltages.)

This thing is a beast. I can drive it via 5v easily, and it switches line like a champ. It’s been in constant use since my last post about home automation.

START OF GUIDE

1. So first, we need to hook up the shield, the arduino and the PSTII. It’s really easy.

2. Get linux on the computer you want to run the server out of. I made a video a long time ago back when I was first getting into linux. The installation process is still the same, you can find that video here.

3. Install various programs your server. First things first, you have to install openssh by running the command:

sudo apt-get install openssh

This will make the server headless, and it will enable you to access the server via command line. Specifically through PuTTY for windows. You can then ssh to your server which is key. You then need to install LAMP by running the command:

sudo apt-get install LAMP

This will install PHP on your server as wells apache and mysql. The two ladder objects are not essential for this project, but if you are going to use the server for other things, I strongly recommend you get them as well. The install process is very easy, just make sure you WRITE EVERY USERNAME AND PASSWORD YOU USE DOWN. I’ve had to reinstall several times before I learned my lesson on this.

After you are done with that, install vim by running the command:

sudo apt-get install vim

Vim is a text editing program for linux. You also need to get pure ftp to upload and download files from your server. Get it by running the command:

sudo apt-get install pure-ftpd

Congrats! you are now an owner of a very powerful linux server. Wasn’t that easy?

4. Upload the call.php, res.php documents to your server.

This is the call.php text, you just need to make it into a .php document and upload it to the server. This document creates a form that the user accesses to turn the lamp on and off.

This is the res.php. It is what the user is taken to once they have entered the information in the call.php.

If you walk though the code. You will see that once the correct password gets entered, the res.php document creates a functioning document stat.php. This is the same document that the arduino reads, and compares to.

5. You need to upload the arduino code.

Here it is, upload it to your board with the shield attached, and everything should work. Access the call.php via your server, and go through the process.

At this point everything should work, please let me know if it doesn’t in the comments.

Sensing the Brightest Point

Youtube demo here:

 http://www.youtube.com/watch?v=YbwSl5Hp3r8

This is a round about way of using a servo to move an analog sensor to 3 points to triangulate the servo degree where the photocell experiences the most light.

 

The servo sweeps back and forth and then another servo points to where the brightest point was.

 

It is very simple wiring, but the code is a little fancy. It’s all commented up here, but as always deduction is your friend.

 

Raspberry pi soon?