Creating an Enchanted Object
One of my assignments for the past few weeks was to create a visual or physical object or experience that connects with the digital world, an enchanted object. And we were encouraged to utilize a Raspberry Pi.
As part of our Joy Dept. installation, I had already begun experimenting with a Force Sensitive Resistor attached to an Arduino; we’re using it as a way to trigger lights underneath a seat when someone sits down. So I decided it would be fun to create something else that could utilize the sensor. I came up with the idea that there could exist a chair that had an FSR inside it that would send a notification to your computer after 30 minutes to let you know you’ve been sitting too long and should take a break.
I started this process first by figuring out the Arduino code. I was able to combine code I found on the Adafruit site about the FSR with a stopwatch code from Arduino Playground to create the final code below. This code starts a timer when pressure is applied to the FSR and stops/clears the timer when there is no pressure.
Next came the challenge of figuring out how to get it all onto the Pi. I set the Pi up using instructions found here and also installed Node, Express, Johnny-Five, and Sockets. That was the easy part. In order to get Arduino code onto the pi, I had to convert it to Javascript. Using the code I had for Arduino as a reference, I followed similar steps as before. Johnny-Five’s basic sensor example provided what I needed for the FSR and I found code for a stopwatch on JSFiddle. This wasn’t an easy task and I definitely had to get a little assistance. This final code does the same as the first, except after a specified amount of time it sends an alert. It also connects with a webpage to show the user how long they’ve been sitting (how long pressure has been applied). In order for the Arduino to communicate with the Pi, aside from being plugged in to it, Standard Firmata Plus had to be uploaded to the Arduino; this is also found in the examples.
To the left is a photo of the final setup of Arduino joined with Pi. I did try to get rid of the Arduino altogether by attaching the FSR straight to the Pi. A classmate led me to this site, which discusses what the pins on the Pi are to be used for and this site, which gives info on additional steps, like installing raspi-io and adding a few extra lines of code to the JS file. This is when I learned that all the pins on a Pi are digital and I needed one to be analog for the FSR. This page discusses additional code to add to convert a digital pin to an analog one, but it requires an expander be attached to the Pi, and I did not have one of those on hand. So I just had to leave the Arduino. Below is a video showing the whole setup in action. For the sake of time and not wanting to sit there for half an hour recording, the notification is sent after 10 seconds instead of 30 minutes.