I am trying to convert a project from a Prop2 to the HC-8+. What would the code look like?
Current Prop2 layout and logic
I have 3 servos on P8,9,10 (Nod, Tilt,Turn)
LCD Eye power on OUT 0
LED spotlight power OUT 1 PWM
Serial IO on P14 to a AP-16+
the red and white wires are active on the pins. The black wire is wired to external power and everything to GND.
1. PWM the LED spotlight
2. Power on the LCD eyes
3. Start playing SFX.WAV
4. Read data and position servos Nod,Tilt,Turn X times 20ms see data.csv (add smoothing code data2.csv)
5. Loop through all data checking if audio stops. Start data over if audio still playing
6. Power off LCD eyes
7. PWM LED spotlight to off
8. Wait 2 minutes
9. Loop back to top
I have a HC-8+ labeled Rev C 2011 with a MicroSD board (c) 2012 on it
Okay -- the first thing we have to do is write a driver that will read a line from the file and then convert it into four values. I will post that later so that you can try it on your HC-8+. Once we can read that table (converting from text into numbers), things should be fairly straightforward.
Seems like I recall attempting this when the HC-8+ first came out and I ran into an issue with GND and the servo outputs. something about the way I wired it on the Prop2 and the way the power connections work on the HC-8+? That ring a bell?
I don't recall what happened early on, but from the beginning, the HC-8+ was designed for servos. We even went so far as to provide a method of "hacking" the board so that a separate power supply could be used for the header.
Back to the project at hand... I'm always for taking a "make sure the pieces work first" approach. I gathered all the pieces that you need and wrote a test program that does the hard part: read the file and parse the values from each line. Once it was working, I even made the display run in real time (I think). The loops value in the data is multiplied by 20ms for the delay, right?
As you can see, the program displays the current line from the file, the raw string, then the parsed position and looped values.
Move the data file to the SD card, install it on the HC-8+ (make sure all the option switches are off), and run the program. Note that I changed the name of the file on my end.
The code and a screen-shot from my system are attached. Note that I also measured the show time of the file.
yes the loops were every 20ms for the Prop2. Tested the program. Seems to run fine. I'm using v 1.3 of the Propeller Tool is that current enough. Any major updates I'd want?
I dug through my spare parts bin and found the Power Supply adapter you were talking about. So even that issue can be resolved.
I hunted through your code until I realized this is just testing the reading of the servos.txt file and playing it back. No servo movement or AP-16 commands being sent.
I've done the same thing. I have the HC-8+, 3 servos, 2 12V LED's, and a spare AP-16+ all sitting on my workbench. Should be able to test all the parts first before adding the board to my existing project.
Jeff
This adds audio and servo output. If this works, we'll strip out all the debugging code and go to the final prop version.
Attachment removed -- see end of thread for final program.
Not seeing any servo movement. According to the code they should be on h5,h6,h7? I also made sure that the Dip switches 1-256 are are ON. Code runs and the the debugger displays all the values as they are read but the servos don't move?
Not sure what you mean as to h5, h6, h7. I think you're on the wrong header, those are inputs and are labeled "In" not"h". Servos outputs are the header toward the bottom.
wasn't wearing my glasses. Yes those were In7,6,5 I tried the others first with no success but I moved them back. The debug display still shows the values being read but the servos are not moving. Tried the power switch at 1 and 2 didn't make a difference. Saw the AP16 code and wired up the serial connection to the AP16+ but it didn't play the file. I tested the board and it played the SFX.WAV file just fine manually. But not with the HC-8+.
Here is a pic of my setup
Check to see if you're getting 5v on the R output pins.
Also, I can't see the config. switches under the SD card adapter, is BR off?
I totally forgot about that switch block under the card reader. BR was off so I turned it on. the other 3 switches are off.
I tried switching A1,A2 to on but then the card reader failed to read the file every time. Turned them back off and the card reads the data but still no servos. I'll grab my voltmeter tonight and test the pin for 5v.
Still no audio being played.
You want the BR switch on the HC-8 off because that's where you have the BR switch on the AP-16, they have to match. (off is 2400)
Yes BR is ON and that matches the AP16+
In your picture BR is off on the AP-16.
I've tried with both BR on and off. Not sure which is best? 2400 is probably just as good for AP16 commands. Checked that 5v is on R with meter.
Program reads data but servo and AP16 commands not working still?
Really doesn't matter, as long as both BR settings match. At this point I'm out of hardware possibilities, maybe Jon can help.
Could it have anything to do with the firmware on the board or the rev of the board. It is a Rev C 2011?
Just in case I tried uploading both E and F versions of the firmware online. Still no servo or audio. But now the card reader isn't working either. No data being red. The green light comes on and stays on right after power up. Nothing else happens.
When I first set the board up and was testing the Propeller Tool IDE I did a Load EPROM but didn't have a BIN file loaded. Could that have done something? This was before you ever gave me any code to test.
Jeff
Success! Sort of. I reloaded the F firmware version. Reloaded the program and the servos started working. I am still not getting any audio commands that I can tell?
Jeff
I'm going change my suggestion about 38400 baud. The AP-16+ (until Rev E) uses a serial interface device that can be finicky*. I also went through and updated some of the AP-16+ routines in your program, based on a general template that I updated today.
This version works on my desk; the servos operate and the play command is sent to the AP-16+. Once audio plays on your end, we can get to a "production" type program. If you're going to want a constant status update from the AP-16+ we'll have to use a secondary cog so that we don't interfere with the main loop timing.
* We have changed the serial interface circuitry on the AP-16+ (Rev E and onward) and AP-8+.
Attachment removed -- see end of thread for final program.
OK got some details to report back. Prior to getting your latest code I was able to get everything working with the BR set to ON on both boards.
Couple of strange behaviors though. I can ONLY get the program to execute if I press F10 and then F12 and then hit enter. If I power off the board and back on and then hit F12 to debug and hit enter I either get no response or I get a can't read card (mostly no response) it is as if the servos get intialized when the program loads that doesn't happen on power up?
The other odd thing is that my audio file plays fine up until a certain point (about 3/4 of the way in) and then audio cuts out. Green light still flashing nothing else wrong. just no sound out the speaker outputs. I tried both Left and Right screw downs and it did the same thing.
I switched to both boards having BR off and used your new code. Had to change the file to "sfx" not "sfx00" and press F10 and F12 and it runs. But still not on power up. and the audio still cuts out after a while.
I don't need to check audio status unless that is the only way to test for the playback end. If you have to check I am find with 1-2 seconds. The sound can end and have a 1-2 second delay. I'll try attaching the audio file so we are in sync.
but I want servo movement to stop after the audio has ended. I tried using the larger servos2.txt file I upload a earlier in this thread. It has the movements smoothed out. Works REALLY well. But we can also do it in code and use the smaller file too.
here is the audio file. Too big to upload
https://drive.google.com/open?id=0BzJ0BzAn5tyoQ202alNGRm84Yms (https://drive.google.com/open?id=0BzJ0BzAn5tyoQ202alNGRm84Yms)
If you manually start the AP-16 audio, does it play completely or does it stop mid-stream?
Fixed it.
Even if I manually start the audio file on the AP16+ it stops output but continues to plan about 3/4 of the way through. I went back to the original MP3 file and converted to a WAV like I do for all my AP16 audio. Same problem. This is a Rev C board so I updated to the latest Firmware. Now it plays through fine.
Remember... this is a very complex program. I have gone step-by-step so that you can learn those steps and make adjustments as needed. The attached program is "prop ready." It has been running on my desk all morning.
Notes/Comments:
-- While the AP-16+ can play stereo files encoded at 44.1kHz, some SD cards cannot keep up
-- Your original file worked fine with my SD card; still, I re-encoded to mono, 32kHz. This takes a lot of strain off the SD card with no perceptible change in quality.
-- The link to the mono file is in the listing -- note that it's about 36% the size of the original
-- Reformat your SD card before putting the file (named as SFX00.WAV) and NORELAY.TXT on it
-- Set the BR switch on the AP-16+ to OFF for 2400 baud; best with open wire connections
-- If DEBUG is set to YES, you must open the terminal and press a key to start; this lets you watch things in progress
-- I created a scaled milliseconds constant (MS_ADJ) so that the movements end with the audio
-- A red light indicates a problem; the LED with flash green when playing show
Again, there is a lot to learn from this. I have included comments and divided the program into small, atomic methods to make things clean.
Do you still use Audacity to re-encode to mono 32Khz? Or how did you convert the WAV file?
Yes, I used Audacity.
Here's what I did with my WAV file. Loaded it into Audacity. Split the stereo to mono. Deleted the 2nd mono channel. Export to WAV (Microsoft) signed 16-bit PCM. This produced a much smaller WAV file which sounds exactly the same. Formated the SD card and copies on the new exported WAV
I had the right 2 pins on the PIR of the AP-16+ jumpered so the sfx00.wav would auto start. Renaming the file to sfx.wav works. So I removed the jumper and then renamed it back to sfx00.wav and it didn't autostart. Switches 1-6 are OFF. and the audio selector is set to 0. Now when I power it up it just waits.
The latest program seems to run very well when I first load it. Pressing F10 loads it and it runs first fading the LED then powering up the eyes, then starting the audio and then playing the servo data. When the audio is done the LED fades and the eyes turn off and the servos stop. There is a 2 minute delay then it starts again.
Couple of issues.
the LED fade up is TOO fast. Fades up very quickly needs to be 2-3 slower.
I am unable to get the program to start from a cold power on. Either turning the power switch off/on or unplugging power and replug. The only way I can get it to start again is to reload the program. When I press F10 there is an initial servo sync that happens before the program starts. This does not happen when I power off and on.
we are VERY close.
I am able to tweak the line
fade_spotlight(0, 255, 2000)
to
fade_spotlight(0, 255, 6000)
to get the fade slow enough.
One other observation besides the code only runs when compiled.
I am not able to get the debugger to work anymore. When I press F12 nothing ever gets output even though I see the term.str code?
Arrrg....nevermind. DEBUG = NO
set it to DEBUG = YES and now the debug window works. Still not getting power on execution though?
You must download to EEPROM (F11) to have the program run from power on.
Well, THAT makes sense. Then I'd say we are done. This seems to work just as well as my Prop-2 version with the addition of the extra space for show data and now the smoother servo movement.
Next step is to replace the prop2 with this programmed HC-8+. Get the wiring working and test it on the real prop.
Thank you so much for all your help Jon. You guys provide the best damn tech support help in the industry as far as I am concerned.
Jeff
I'm glad we were able to get it working. I hope you'll post a video of the prop in action.
Quote from: JonnyMac on August 28, 2017, 09:52:38 PM
I'm glad we were able to get it working. I hope you'll post a video of the prop in action.
Yes! Please!
Getting some odd behavior with my LED light and the LCD eyes
They are wired to OUT0 and OUT1 connecting the pair of wires to the OUT1 and GND and OUT2 and GND pair. The PWM isn't fading the LED it sort of flickers a couple of times and then just turns on. And the LCD eyes take a while to power on? The head movements start and then the eyes finally power on few seconds later?
Any ideas?
I'll see if I can grab a video of what is going on
https://drive.google.com/file/d/0BzJ0BzAn5tyocU5Oa1pNdUdLN1E/view?usp=sharing (https://drive.google.com/file/d/0BzJ0BzAn5tyocU5Oa1pNdUdLN1E/view?usp=sharing)
https://drive.google.com/file/d/0BzJ0BzAn5tyoZ044SUIyYVg5NmM/view?usp=sharing (https://drive.google.com/file/d/0BzJ0BzAn5tyoZ044SUIyYVg5NmM/view?usp=sharing)
added some video of the issues. What is funny is when I tested this on the bench I used a couple of simple 12V red 5mm LED's I had sitting around. When I ran the program with them the one faded up and the other turned on instantly both before the head started moving. code hasn't changed?
One other odd behavior. When the board first powers up the servos swing into a very strange position for the skull. Is there a place in the code that I can have the servos start at the positions in the first line of data? 164, 161, 162
Jeff
Kind of a shot in the dark. Are the LCD eyes instant on when powered or do they require a warm up period before they actually come on? Also, does your LED light have an internal driver? It looks pretty powerful so I'm guessing it might. That would be a problem with PWM.
Remember this hardware was all hooked up to a Prop2 and ran fine. LCD eyes power up almost instantly with HIGH PIN1 and the LED would fade up slowly. The LED is NOT powered. Just straight 12vDC. It is a Gantom One spotlight.
Regarding the servo startup I see where you are initializing the idle vales from the first line of data but something is not right with that code because the servos are going to what appears 0? I'll have to put the board back on the bench to debug that code?
Quote from: davisgraveyard on September 03, 2017, 08:14:37 PM
Remember this hardware was all hooked up to a Prop2 and ran fine. LCD eyes power up almost instantly with HIGH PIN1 and the LED would fade up slowly. The LED is NOT powered. Just straight 12vDC. It is a Gantom One spotlight.
That spotlight does have an internal driver. Not sure how the PWM fade is configured in the code but that light has to have a minimum of 10%.
Could it have anything to do with the way I wired it? It is connected to the OUT1 & GND post pair on the outside of the board. My version has OUTX & GND pairs instead of V+
Again this light fades just fine on the Prop2 using this.
led PIN 1
FOR level =0 TO 255
PWM led,level,10
NEXT
HIGH led
Sounds like it's wired correctly. If the program works as it should using a 5mm LED, then it's not the program as you pointed out. I believe that Gantom spotlight is non-polarized, probably won't help but did you try switching the leads?
Swapped the led wires with same result. The gantom light fades fine with the prop2 and prop1.
I checked the code and idle
- are intialized as 0. If I do an extra readln,80 it seems to work? Not sure why? Still haven't tested the eye on timing with show code. I think all the issues are related with the faster speed of the propeller and the multitasking nature.
1. Servo idle vales set from first line of text (adjust reading code?)
2. LED not fading smoothley (some sort of power level timing?)
3. LCD eyes not powering on until servo movement is running (need to force this to complete before starting servo loop)
I found the source of one of my problems. The power supply. On my test bench I am using a 1.2A 12VDC PS and a 300Ma 12VDC PS. the 300MA one is fine for driving the AP-16 but didn't work well for the HC-8+. WHen I use the 1.2A the LED fades fine. I must be using something less than 1.2A in my prop?
Still seeing the issue with the servos not getting set to idle correctly from the first line in the data file. I'm searching the code and debugging this one.
And the LCD EYE power is going to need a short pause to delay things which I can fix.
For those that are following and to Jon. I worked on the code last night to figure out what is going on with the servo Idle
- values not getting initialized and the servos getting reset to zero positions. The show would play without issue every time. But the concept of opening the file reading the first line out was not. I'm still not sure what is going on but if I remove the check and just let the player read the file and i check if line = 0 and store the values then the servos idle in position.
line := 0
t := cnt ' sync to system timer
repeat
check := rd_line(@linebuf, 80) ' read line from file
if (check =< 0) ' if EOF, break out of loop
quit
else
replace(@linebuf, 13, 0) ' strip CR from input line
parse_values(@linebuf) ' parse data from it
servo.set(NOD, nodpos , 0)
servo.set(TILT, tiltpos, 0)
servo.set(TURN, turnpos, 0)
time.mark
if (line == 0)
idle[NOD] := nodpos ' extract & covert to us
idle[TILT] := tiltpos
idle[TURN] := turnpos
if (DEBUG == YES)
term.rjdec(++line, 4, " ") ' show line from file
term.rjdec(nodpos, 8, " ")
term.rjdec(tiltpos, 6, " ")
term.rjdec(turnpos, 6, " ")
term.rjdec(frtiming, 8, " ")
term.tx(13)
waitcnt(t += (frtiming * MS_ADJ)) ' real-time delay (adjusted)
t := time.millis ' capture show time
close_file
set_idle_position
I've been on a road trip, hence very busy -- and you'll learn more by digging in than having me do everything, anyway.
All the pieces are there. At the beginning of the program, open the file, read the first line, parse those values, then save them as your start positions. Send these to the servo driver at the top of the loop (before the fade-up of the eyes).
I am more than comfortable wading through the code and most if not all if it makes sense to me and I am able to make changes as needed in most cases. Even add debug statements to help figure stuff out and move code around as needed.
But there are some basic concepts that I might not understand when it comes to the cogs in the propeller code or the architecture of the cpu. How things are executed and how to set priority or pause execution or make things happen synchronously. I'm a C# .NET guy so I get multithreading and background tasks with callbacks etc. But I only understand it from a Intel Process and Windows using .NET.
the code at the start of the program is not reading any data out of the file. No error opening the file but the buffer is empty. But once the show starts the reads work fine. The initial file check code happens right after the setup which intializes IO and the SD card reader. Could that not be complete when the data read happens but is complete by the time the show plays? I think it is some sort of race condition. All my debugs show that the file open is valid but the read is a blank line and there is no data to parse.
Similarly it appears that the outs.high(EYES) seems to happen on its on thread independent of the play_show() call? I placed a time.pause(3_000) after it to make sure it is on before the ap16_wav() or play_show() are called which does help but the timing still seems to be almost random when it is fully powered on?
pub main
setup ' setup io and objects
'verify_servo_file(@ServoFile)
ap16_stop(%00)
if (DEBUG == YES)
term.rxflush
term.rx
term.tx(term#CLS)
repeat
if (DEBUG == YES)
term.tx(term#CLS)
term.str(string("Starting show.", 13, 13))
fade_spotlight(0, 255, 6000) ' #1
outs.high(EYES)
time.pause(6_000) ' #2
ap16_wav(%00, @AudioFile, 1) ' #3
play_show(@ServoFile) ' #4
' optional
' -- must use 2400 baud with G command on older AP-16s
{
repeat while (ap16_playing(%00)) ' #5
time.pause(20)
}
outs.low(EYES) ' #6
fade_spotlight(255, 0, 6000) ' #7
time.pause(120_000) ' #8