I saw that someone found a way to record servo sequences with littlebits and I'm not proficient enough to translate that function into a non-littlebits project. http://littlebits.cc/projects/servo-sequence-recorder
I am interested in recording servo sequences.
For clarity, I want to push a record button, make my animated flowers talk and move using servos, then play back that sequence. I can use audio servo driver boards and use a sound recording but that would mean I can only control 2 things (left and right channel sound) from one board. (the audio servo driver boards- like Scary Terry's are kind of pricy to buy 10 that I would need)
Any ideas would be appreciated.
I've had a really (really) quick look through that linked code and I don't see anything that's littlebits specific: no libraries, for instance. I loaded the code into the IDE and it compiles, at least.
I have no idea what littlebits is (are?), although it seems it's just a way of snapping components together, onto what seems to be an Arduino-compatible board with littlebits connectors.
So, seems to me that (don't quote me, it's 5am here and I'm just leaving for work and haven't had a full look) you can just use that code on an ordinary Arduino, and connect the components in normal Arduino fashion, using the pin assignments as below, taken direct from that code:
byte modeBtn = 0; // Assign pin as the Button that you will push and hold for RECORDING.
byte morseBtn = A0; // Assign pin as the Button that is your input to record the sequence.
int recording_indicator_led = 1; // Assign pin d1 as a pin that will do digital output to indicate recording mode
byte pin_d5 = 5; // Assign pin d5 as a pin that will do digital output.
int pin_a1 = 1; // Assign pin a1 as a pin that will be an anlog input pin
edit..... this by the way is an often discussed topic, so search the forum for similar threads. If I'm not too worn-out when I get home later today, I'll try that code out on my Uno.
sperdie:
For clarity, I want to push a record button, make my animated flowers talk and move using servos, then play back that sequence. I can use audio servo driver boards and use a sound recording but that would mean I can only control 2 things (left and right channel sound) from one board. (the audio servo driver boards- like Scary Terry's are kind of pricy to buy 10 that I would need)
Any ideas would be appreciated.
This still lacks clarity.
What is going to make your animated flowers "talk and move using servos" ? If it's your own arduino then you don't need to record it, all you need to do is rinse and repeat.
The idea is that I have a voice track that I want to have the flowers talk to.
I'm thinking that it is possible but it would take a long time to develop a timed sequence to match the voice track. If there were a way to record a sequence by pressing a record button, make the flowers talk and move using buttons and pots - then I would be able to recreate all the movements.
I'm really new at this so I'm not sure what the easiest way to get a long sequence down.
Not really sure in the code that was done for the littlebits where the recording is done- I see the serial inputs and the digital output pins but I lack the knowledge to determine where the recording lives (or even if it is possible)
The code is below: (I think littlebits is a modular learning system that Radio Shack Sells, with snap together components- but I have never seen one in person)
/*
littleBits Sequence Recorder
advanced version
This project will repeat the sequence that you create and then play your sequence back on the output bits!
It will loop until you press the record mode button again.
Instructions on how to use it:
Go into record mode by pressing the button on the d0 input. While pressing the record button or switch,
twist the dimmer on pin a0 to create patterns for the servo to follow.
Let go the record button to play back your sequence! Press the record button once to stop playba
Rotate the dimmer counter connected to a1 clockwise to speed up the
your playback, rotate the dimmer clockwise to slow the
playback down.
Have fun with different littleBits on the output!
https://littlebits.cc/projects/sequence-recorder
Written by Glenn Mossy, May 8, 2014
Modified by Paul Rothman
This example code is under Creative Commons CC-BY-SA
A good resource is at Arduino - Home
*/
/*
littleBits needed
power bit p1
fork w7
arduino w6
buttons i3
dimmer i6
led o1
servo o11
a4 micro usb cable
snap the power bit p1 to a fork
snap a button on d0 of the arduino bit
snap a dimmer on a0 of the arduino bit
snap a dimmer on a1 of the arduino bit
snap a bright led on d1 of the arduino bit
snap a servo on d5 of the arduino bit
*/
byte modeBtn = 0; // Assign pin as the Button that you will push and hold for RECORDING.
byte morseBtn = A0; // Assign pin as the Button that is your input to record the sequence.
int recording_indicator_led = 1; // Assign pin d1 as a pin that will do digital output to indicate recording mode
byte pin_d5 = 5; // Assign pin d5 as a pin that will do digital output.
int pin_a1 = 1; // Assign pin a1 as a pin that will be an anlog input pin
boolean inRecordMode = false; // Create a boolean variable that will hold current state of the Record mode.
boolean wasInRecordMode = false; // Create a boolean variable that will hold previous state of the Record mode.
// buffers to record state/duration combinations
int maxSamples = 100; // This is the maximum number of samples in bytes that can be stored.
boolean states[100]; // Create a states array to record up to this number of on and off states.
int durations[100]; // Create a durations array and we can have up to this many duration times.
int idxPlayback = 0; // Initialize the index for the Playback array to 0
int idxRecord = 0; // Initialize the index for the Record array to 1
int sampleLength = 1; // 1 ms
float playbackRate = 1; // 2=>half speed, 0.5=>double speed, change this if you want to play back slower or faster than the recorded rate.
void setup() {
//Serial.begin(9600); // Uncomment this line for setup to use the Serial Monitor for troubleshooting your software changes.
pinMode(modeBtn, INPUT); // Setup the mode Button as an INPUT
pinMode(morseBtn, INPUT); // Setup the input Button as an INPUT
pinMode(recording_indicator_led, OUTPUT); // Setup the pin d1 the recording_indicator_led as an OUTPUT,
// when the record led is HIGH you will also be providing power to your morse sequence recorder button
pinMode(pin_d5, OUTPUT); // Setup the pin d5 pin_d5 as an OUTPUT
pinMode(pin_a1, INPUT); // Setup the pin a1 pin_a1 as an INPUT
}
void loop() {
digitalWrite(recording_indicator_led, LOW); //
inRecordMode = digitalRead(modeBtn); // read the mode button
if(inRecordMode == true) { // test if the mode button is pressed in record mode
digitalWrite(recording_indicator_led, HIGH); // When in record mode, turn on the led
if(!wasInRecordMode) { // if the button was not pressed in record mode, reset the arrays and index for playback
// reset record buffers
memset(states, 0, sizeof(states)); // Set the size of the states array
memset(durations, 0, sizeof(durations)); // Set the size of the durations array
idxRecord = 0; // reset record idx just to make playback start point obvious
}
recordLoop(); // perform the recording loop function
} else { // or else
playbackLoop(); // perform the playback loop function
}
wasInRecordMode = inRecordMode; // record prev state for next iteration so we know whether to reset the record array index
}
void recordLoop() {
boolean state = digitalRead(morseBtn); // read the state of the input sequence recorder button.
digitalWrite(pin_d5, state); // change the state of the output with the input to give feedback to person recording the loop
if(states[idxRecord] == state) {
// if the state is not changed, add to duration of current state
durations[idxRecord] += sampleLength;
} else {
// if the state is changed, go to next index (idx) and set default duration of 1ms
idxRecord++;
if(idxRecord == maxSamples) { idxRecord = 0; } // reset idx if max array size reached
states[idxRecord] = state; // save the state to the states array by index
durations[idxRecord] = sampleLength; // save the duration of the sample to the durations array by index
}
delay(sampleLength); // slow the loop to a time constant so we can reproduce the timelyness of the recording
}
void playbackLoop()
{
// playback rate control, remove the following three lines if you don't want speed control
//float dimmerVal = analogRead(pin_a1);
//dimmerVal = map(dimmerVal, 0, 1023, .5, 2);
//playbackRate = constrain(dimmerVal, .5, 2); // limits range of sensor values to between 0 and 2
//Serial.print("PlaybackRate= ");
//Serial.println(playbackRate); // Uncomment these print statements to use the Serial Monitor to observe your playbackRate
// play the loop back at the desired speed
digitalWrite(pin_d5, states[idxPlayback]); // playback output to pin_d5
delay(durations[idxPlayback] * playbackRate); // leave the output pin in that state for duration (* desired rate)
idxPlayback++; // increment the playback index so we can play the next value
if(idxPlayback == maxSamples) { idxPlayback=0; } // repeat the recorded loop when we reach the maximum number of samples
}
You could have an array that you write to every time that you write to your servo. To replay, you'd simply have to read back what you saved in the array.
I am really not a proficient programmer (yet) I am off to a good start and I was able to get an arduino that I have been using for exactly one day to get my flowers to move with a pot. (and with an audio driver board but that's another story)
I have never programed before yesterday, so what you suggest, while it may be possible, would be beyond my current skill set.
I was hoping that someone in the community already did this and I was happy to find the example sketch that I did -It describes a process to record servo movements- I'm just a little sketchy on how to build it and where the recording lives- is it in the memory of the Arduino? Do I need to attach something to the digital output pin to record?
It is beyond my understanding at this moment on how it works; where the output actually gets saved to for instance. (or for that matter if it will actually work at all)
I guess I will have to work through how to write to an array - and how that whole process works. I appreciate you pointing me in the right direction.
Do you have any reason to believe that the sketch that I posted will not work for recording a servo sequence?
The guys that make those huge animated christmas light displays must have some means of doing this. They can't all be using broadway-theater DMX light controllers.
The talking flowers thing sounds like fun. Can you give us a photo? (The full-reply feature, not quick-reply, will allow you to upload a photo.)
What state is the project in? You have servos operating the flowers and an Arduino controlling the servos? You are manually pressing buttons or knobs to make the flowers move? Now you have got them moving, do you have some idea of what kinds of moves you want? Do you just want two positions open/close or is it important to vary how quickly the flower moves in between positions?
Allowing accelerations is a lot more data to store than just recording open/shut times. You need to decide how to store the data and then you will know if it will fit in the Arduino RAM, EEPROM or if you have to get an SD card to store lots of detailed moves.
If you are just pushing one button per flower to make a simple open/shut then record the times that the buttons were pushed using the millis() function. You can record up to 32 seconds in a very compact data structure and thousands of seconds only doubles the size of the data. Save that to EEPROM so it isn't lost when the power goes off. With that information and some simple rules on speeds and accelerations, the program can recreate the movement of the flowers very easily.
If you need to control speeds or you have more complex movements, then perhaps logging the position of every servo 10 times per second will work. Then the playback doesn't need any rules - it just moves to the next position every 100ms.
I have a youtube vid of the first flower that I did. I have since added a second flower and 2 more servos. When its done there will be leaves and greenery to hide all the wires. I took a picture of the back. This is just a prototype so that I can get a process to work. I hacked a Big Mouth Billy Bass as an experiment. I have a restaurant that I'm looking to make animatronic things move. As the restaurant is called "Through the Looking Glass" - the talking flowers are from the book.
So I do want to be able to make the mouth move fast or slow -open small or wide.
I wil be using 3 servos for this project. One makes the flowers turn left or right.
The other servos control the "talking" action. I toyed with the idea of using an audio driver board, and this works but would be expensive to roll out a big project as these boards tend to be expensive. $40 to $50. and I can only control 2 devices with the left and right channels.
I can move them now by turning a pot screw. I want to first convert the pot to a button if I can then work out some way to record the servo movements.
So it would seem from what you are telling me that I would need to output to eeprom or an sd card.
Not sure how to use the millis() function as this seems to just record the time from when the program started.
So the original code that I posted for the littlebits servo recorder- is that a viable option?
The littlebits code looks good enough to start with. You should be able to get that to compile on the Arduino and record one button. When you understand how that works you can then move on to extending it. The comments at the top of the program say that it records the knob position but I can't see where it does an analogRead() and stores that anywhere.
It is only recording to the RAM, so the recording will be lost when the power goes off. I expect your project will need more permanent storage like an SD card.
Work on getting the manual control to work through the Arduino. Look for code examples of controlling one servo through an analog input. Set that up and get it going before trying to record and replay those inputs.
There is already a lot of stuff in this Thread and I confess I have not read every word.
What I have not seen is information about what makes the servos move in the first place so that there is something to be recorded.
If (just for example) I had a servo that moves in response to a person turning a potentiometer it would be very easy to include a function that saves the value of myServo.write() to an array at regular intervals. The only complication that I can see is the question of how many samples per minute are required and where the array is to be saved because the Arduino does not have much SRAM. However the values could be stored to an SDCard with only a little extra code (and the appropriate extra hardware).
From the sound of the application description I'm not sure it is necessary to have the recording and playback capabilities in the same program. Presumably the restaurant will only need playback and the "creator" will be the only person needing the record capability.
...R
See also the OP's other Thread
Thank you for all your guidance. At this point I don't really have the knowledge to act on some of your suggestions but it gives me a good general direction and that is really what I'm looking for.
Looks like a great community here and I'm sure that I will be able to contribute in the future instead of being a knowledge sucker.
I'm going to start with first - manually moving the plants around. My first goal would be to convert my pot to some kind of button. I am also going to order and sd card or sd shield kit so I can start to learn how that works as that would seem to be what I'm ultimately going to need to store a large animated project involving lots of characters. Thanks again everyone.
Did you ever get this idea to work? I'm looking to do something simlair and would love to see your code if you got it to work.