Last week, we ran into trouble concerning our audio connections. However, this week, we managed to solder and test everything, and were able to create a youtube video of our soundcard and headphones playing sound based on keyboard input. We hope to use the Edison to integrate this audio system into the clock, with the inputs as the clock’s bells which are outfitted with potentiometers affixed to buttons.
In addition, we worked on the external frame of the clock, attaching the potentiometer buttons which will hopefully be used next week for the values sent over I2C. We have realized that the plastic tops of the push buttons we are using are not firmly affixed to the base of the buttons, and move around too much, so we hope to either replace the buttons or reinforce them structurally so that the heavier bell exterior can sit atop them.
Accomplishments for the week:
- Resoldered the audio connections on the mic
- Tested to make sure that the speaker and mic works
- Integrated all of the previous Bash Audio code together. (Can now play random music, record, and playback at the push of different buttons)
Future plans for audio: We want to connect to the Edison to allow us to get music from an online playlist that can be edited by the user.
We bought a USB hub to use with the Edison. Our USB hub will allow us to control multiple USB ports for the project (Which will probably come in useful)
Code:
Current goals:
Next week, we plan to post a blog on the completed Arduino I2C. Hopefully by that time we will have received the Edison, and will be able to make further progress in In addition, we plan to begin closing up the clock and integrating a stepper motor to control the clock’s gears. We chose a stepper motor over a continuously rotating servo because stepper motors were easier to find and we felt it went with the spirit of upcycling to use our old materials.
We have connected the stepper motor to the Arduino. This stepper motor will be used to turn a calibration knob on the clock, so that We are using interrupt with I2C so that the Arduino slave will send a message over I2C that a button has been pressed.
Image of our stepper motor working with the two arduino units. We are working on getting it to rotate counter-clockwise. An H-Bridge may be needed.
Code:
/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/
// the previous reading from the analog input
int previous = 0;
void setup() {
}
void loop() {
// get the sensor value
// move a number of steps equal to the change in the
// sensor reading
stepper.step(100);
// remember the previous value of the sensor
}
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2, 3, 4, 5);
#include<Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
Wire.onRequest(requestEvent);
attachInterrupt (digitalPinToInterrupt (BUTTON), buttonPressed, CHANGE);
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
digitalWrite(8,HIGH);
}
void loop() {
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void requestEvent(){
Wire.write("hello "); /* I couldn’t get it to give a sensor value might have to do with timing? If I replace it with giving the current value for a potentiometer it does work. Might have something to do with button states */
}
void buttonPressed ()
{
int x=analogRead(5);
if (digitalRead (BUTTON) == HIGH)
Wire.write(“High”);
Wire.write (x);
else
Wire.write (“Low”);
Wire.write(x);
}
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c);
}
int x = Wire.read(); // receive byte as an integer; checking to make sure the sent value equals original
Serial.println(x); /*May be turned into a stability system, so we say that if two values are more than 5 values apart, we say they aren’t measured(as in the slave sends back the number received and the master sends a new number to check against the first. This is necessary because we noticed the potentiometer values during movement could greatly vary) */
}
http://www.gammon.com.au/interrupts
*Change* Previously, we were going to use the Arduino to run some sensors. However, we decided that running the Arduino as a slave that would report button state to the Edison when the Edison requested it was inefficient because we couldn’t have two masters (So it would be pretty inefficient to have the Edison clog up the I2C line to constantly request button state and it would be annoying if one had to press the button for longer than half a second to make the Arduino send the information). Thus, we are looking at possibilities of using the Edison for running buttons and stuff that should be changed manually while the Arduino slave will run outputs. (Such as the mechanized calibration of the clock (Does not need to happen the second something is pressed)) Apparently there is a way to run this, but it is complicated, so we would prefer to avoid it and just use an interrupt function on the Edison to look for button pushes while the rest of the code runs.
Expected Problems: To be truthful, audio and I2C are expected to be the most difficult parts for this project. Thus, we have to see how difficult I2C on the Edison will be at this point.
I2C stuff
We have connected the stepper motor to the Arduino. This stepper motor will be used to turn a calibration knob on the clock, so that We are using interrupt with I2C so that the Arduino slave will send a message over I2C that a button has been pressed.
Code:
/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/
// the previous reading from the analog input
int previous = 0;
void setup() {
}
void loop() {
// get the sensor value
// move a number of steps equal to the change in the
// sensor reading
stepper.step(100);
// remember the previous value of the sensor
}
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2, 3, 4, 5);
#include<Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
Wire.onRequest(requestEvent);
attachInterrupt (digitalPinToInterrupt (BUTTON), buttonPressed, CHANGE);
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
digitalWrite(8,HIGH);
}
void loop() {
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void requestEvent(){
Wire.write("hello "); /* I couldn’t get it to give a sensor value might have to do with timing? If I replace it with giving the current value for a potentiometer it does work. Might have something to do with button states */
}
void buttonPressed ()
{
int x=analogRead(5);
if (digitalRead (BUTTON) == HIGH)
Wire.write(“High”);
Wire.write (x);
else
Wire.write (“Low”);
Wire.write(x);
}
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c);
}
int x = Wire.read(); // receive byte as an integer; checking to make sure the sent value equals original
Serial.println(x); /*May be turned into a stability system, so we say that if two values are more than 5 values apart, we say they aren’t measured(as in the slave sends back the number received and the master sends a new number to check against the first. This is necessary because we noticed the potentiometer values during movement could greatly vary) */
}
http://www.gammon.com.au/interrupts