Please point me to some step by step basics to code the PICAXE using Blockly.

Gramps

Senior Member
We tried that. It completely reload it again but still will not boot. Next week Wednesday the tech guy will be back
 

Gramps

Senior Member
lbenson, in posts 90 and 91 you posted the code for the dulcimer lighting array. When we check it for syntax errors, this error comes up.

return playNote: ' codedNote has "TUNE" note encoding: %ddoonnnn: duration, octave, note (12-tone)
^
Syntax error on line 177 at/before position 20

Please decipher! Thanks, Gramps
 

hippy

Technical Support
Staff member
return playNote: ' codedNote has "TUNE" note encoding: %ddoonnnn: duration, octave, note (12-tone)
^
Syntax error on line 177 at/before position 20
The RETURN command on a PICAXE does not take any argument. It should just be RETURN, nothing following it.

Also a colon at the end of a line without a following command will cause a syntax error. Unless it is a label followed by a colon.

Looking at the code in posts #90 and #91, pages 9 and 10, the "playNote:" is a label. It should be -

Code:
  Return

playNote:
So probably a cut-and-paste error losing the end of line after the RETURN.
 

Gramps

Senior Member
Lawrence, our Tech, fixed the picaxe editor.
We're really not sure what he did�� but it works now.(something to do with where the program was on the hard drive)
 

Gramps

Senior Member
This example is showing a syntax error at "if pin = 0 then flsh"
What's up?
main:
if pin 0 = 1 then flsh ; jump to flsh if pin0 is high
goto main ; else loop back to start

flsh: high 1 ; switch on output 1
pause 5000 ; wait 5 seconds
low 1 ; switch off output 1
goto main ; loop back to start
 

hippy

Technical Support
Staff member
As you seem to be using a 40X2 it will probably help to get in the habit of using the port.pin names for pins rather than just the pin number.

So "pin0" would be best referred to as "pinC.0", and similarly, if you had a "High 0", to use "High B.0".

Just using the number does work but that is primarily for backwards compatibility, to let older code run with newer PICAXE chips. As can be seen above, "0" is "C.0" or "B.0" depending on the command, whether that number refers to an input or an output. Using the full port.pin name means there is less ambiguity as to which pin is being referred to.

Code:
Do
  If pinC.0 = 1 Then
    High B.0
  Else
    Low  B.0
  End If
Loop
Is easier to understand than -

Code:
Do
  If pin0 = 1 Then
    High 0
  Else
    Low  0
  End If
Loop
 

Gramps

Senior Member
We wondered how the editor knew what pin was designated. This was sample code from the manual. That's why it surprised us that it had a syntax error.
 

hippy

Technical Support
Staff member
The syntax error wasn't because of using old-style pin names. There was a space incorrectly put between the "pin" and "0" which shouldn't be there. That may have been a typing error or an extraneous character if copied and pasted from the PDF or wherever the code came from ...

Code:
if pin 0 = 1 then flsh ; jump to flsh if pin0 is high
 

Gramps

Senior Member
Thank you I hope we remember all this!
New problem. We cannot get the editor to find the hardware when we attempt to load a program to the new 40x2 chip. The breadboard adapter works fine if we load to the 28x2 on the breadboard. Checked 10 times to be sure we have 5+ volts on leg 11 and 5- volts on leg 12. Also have a 10k from leg 1 to positive and leg 1 grounded through the reset switch. Tried a hard reset, too.
Any ideas? Gramps
 

Gramps

Senior Member
31 and 32 must also be connected? Tried it, still no hardware found...........
 
Last edited:

Gramps

Senior Member
Is this the way to connect this accelerometer to the chip?
Connect vcc to 5 volts+, ground to ground and the "Z_out" to pin C.1?
 

lbenson

Senior Member
Right. I looked only at acceleration in the Z-axis, expecting a sharp increase, and trying to ignore the lifting of the hammer after the strike.
 

Gramps

Senior Member
Here's an update on the hammered Dulcimer project. It's working with 8 LEDs!
The code is 318 lines consisting of about 60 if statements, one for each note. B.0 through B.7 represent the notes.
The hammers trip the lamps by grounding the metal strings to pin C.0. or pin C.1.
(Many thanks to Hippy for his translation of my flow chart!)
There's a short u-tube video. The tune is "O God our help!"


This is the first three notes.
main:
High B.6
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low B.6
High B.5
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low B.5
High B.4
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low B.4
Yes, I realize this code is simple, but it does get the job done!! (Big Grin)
Next steps: experiment with other ways of writing the code.
We like LBenson's way of putting all the notes (to 3 songs!!) in a little box and getting them out in order one by one. But do not understand the code that does that. (tune command?)
Then it appears that each note can be assigned a symbol so you don't have to type each line.
Last trying various input devices, mike pickups, accel. chip, etc.
Thanks for everbody being such an encouragement! Gramps
 
Last edited:

lbenson

Senior Member
Nice, clean-looking implementation on the hammer dulcimer in the video. But, man, it would hurt my head to have to code a tune that way.

If you want to use that method, but reduce the code, you could do something like this (noting that B.6, B.5, etc. are just symbols for numbers which designate what pin to use):

Code:
poke 56,B.6,B.5,B.4,B.4,0 ' plus all the rest of the notes (put the trailing 0 at the end)
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = 0
That's all there is. The outer DO LOOP runs until @bptr points to the trailing zero that you put at the end of the POKE statement. The rest of the code makes HIGH the pin designated by the "B.?" number, waits for pinC.0 or pinC.1 to go high, pauses, and brings the pin low, stepping to the next note (with @bptrinc).

(BPTR is a variable which is a pointer into RAM (locations 0-255 on a 28X2); @BPTR designates the value at that ram location; @BPTRINC retrieves the value and increments the pointer.)

Longer tunes could be similarly specified in the scratchpad rather than in ram with the PTR pointer variable--1024 scratchpad bytes are available.

I'd be happy to explain further my encoding using the TUNE command if you wish.
 

Gramps

Senior Member
Thanks for the cool; shortcut! Yes, we would sure appreciate help understanding the tune command. The paragraph above is going to keep us busy for a day or two....
 

hippy

Technical Support
Staff member
The paragraph above is going to keep us busy for a day or two....
A simpler version of what lbenson presented using DATA and READ commands rather than POKE and bptr variables which might be easier to get your head around would be -

Code:
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
  High b1
  Do : Loop Until pinC.0 = 1 or pinC.1 = 1
  Pause 100 
  Low b1
  b0 = b0 + 1
  Read b0, b1
Loop Until b1 = $FF
 

Gramps

Senior Member
Please give a little hint on what the lines of code mean:unsure:
OH! I see it in the Simulator! YES!
Can we make the data string 60 notes long?
 
Last edited:

lbenson

Senior Member
Hippy's code is functionally the same as mine, except that he is storing the note B.# values in eeprom instead of ram.

You can see exactly what is happening if you simulate it and single-step through it.

READ B0,B1 means move the value of the eeprom location specified in B0 to B1.

He was wise to use $ff as a terminator rather than 0, since 0 is a valid pin number.
 
Last edited:

Gramps

Senior Member
Hippy's code is functionally the same as mine, except that he is storing the note B.# values in eeprom instead of ram.

You can see exactly what is happening if you simulate it and single-step through it.

READ B0,B1 means move the value of the eeprom location specified in B0 to B1.

He was wise to use $ff as a terminator rather than 0, since 0 is a valid pin number.
 

Gramps

Senior Member
ok, we'll try running yours in the simulator.
Now running Hippy's code we're not getting the LEDs to blink twice when we repeat a note.
We inserted an extra pause in our code to solve that.
How can we insert that pause between two notes that are alike?
 

Gramps

Senior Member
We're getting this error..........

bptr=56 ' above top named variable
^
Syntax error on line 3 at position 0
 

lbenson

Senior Member
This runs for me without error in the simulator in both PE5 and PE6
Code:
#picaxe 28x2
poke 56,B.6,B.5,B.4,B.4,$ff ' plus all the rest of the notes (put the trailing 0 at the end)
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = $ff
Note that I changed the terminating code to $ff in both the POKE statement and after UNTIL.

You have to run the simulation at a slow speed so that you can click C.0 off immediately after you click it on. Hippy's code will pause between two notes that are the same--if you didn't see that, it is probably because you didn't click C.0 off fast enough. If you increase the pause to 1000 for testing, you may be better able to see what is happening.
 

Gramps

Senior Member
We ran Hippy's code on the LEDs mounted on the Dulcimer and could not see a blink, but they do seem to dim.
We can't seem to get LBenson's code to loop past the first LED......(in the simulator)
 
Last edited:

lbenson

Senior Member
I think this should light the LEDs for Twinkle, Twinkle, Little Star
Code:
' 28Twinkle
#picaxe 28x2
'poke 56,B.6,B.5,B.4,B.4,$ff ' plus all the rest of the notes (put the trailing 0 at the end)
symbol _D=B.0
symbol E=B.1
symbol Fs=B.2
symbol G=B.3
symbol _A=B.4
symbol _B=B.5
symbol Cs=B.6
symbol DD=B.7
' Twinkle, Twinkle, Little Star
poke 56,_D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, _A,_A,G,G,Fs,Fs,E, _A,G,G,Fs,Fs,E, _D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, $ff
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = $ff
This assumes the scale: D, E, F♯, G, A, B, C♯, D
I've given symbolic names to the notes. Can't use A,B,D because those are pin port names, so used _A, _B, _D. Fs is F#.
 

lbenson

Senior Member
We can't seem to get LBenson's code to loop past the first LED......(in the simulator)
In the PE6 simulator with C.0 and C.1 off, start the simulation of the Twinkle program. Set the simulation speed to 200ms (lower right). Click C.0 or C.1 on and leave it on. You should see the appropriate pins light up.
 

Gramps

Senior Member
Running Hippy's code, we're not getting the LEDs to blink twice when we repeat a note.
How can we insert a pause between two notes that are alike?
We tried changing the pause duration. It didn't seem to make a difference
We could give the program an unused pin between two like notes to get a blink, but that seems so wasteful.
 

hippy

Technical Support
Staff member
Running Hippy's code, we're not getting the LEDs to blink twice when we repeat a note.
How can we insert a pause between two notes that are alike?
You can do it by brute force, putting a pause when the LED goes off -
Rich (BB code):
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
  High b1
  Do : Loop Until pinC.0 = 1 or pinC.1 = 1
  Pause 100 
  Low b1
  Pause 100
  b0 = b0 + 1
  Read b0, b1
Loop Until b1 = $FF
Or you could have slightly more complicated code which does only add a delay between notes when they are teh same as the last -
Rich (BB code):
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
  High b1
  Do : Loop Until pinC.0 = 1 or pinC.1 = 1
  Pause 100 
  Low b1
  b2 = b1
  b0 = b0 + 1
  Read b0, b1
  If b1 <> $FF And b1 = b2 Then
    Pause 100
  End If
Loop Until b1 = $FF
 

lbenson

Senior Member
To get a blink off between the same notes in succession, in my code, change the DO LOOP as follows to put the PAUSE 100 after the LOW command:

do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : low @bptrinc : Pause 100 : loop until @bptr = $ff

Similarly shifting the PAUSE 100 in hippy's original code will have the same effect--no additional PAUSE needed.
 

Gramps

Senior Member
Yes, twinkle works in the simulator and plays on the dulcimer!
"do it by brute force,"
but that will add a pause 100 to every note, correct?
"If b1 <> $FF And b1 = b2 Then"
what does <> mean in this line? more or less?
 

Gramps

Senior Member
Well it sort of played because we didn't have a C# on that scale, and at B.0 the pin is smoked on our only 28X2 chip!
Twinkle didn't want to run on the simulator with the 28X1 chip. Don't know why.
Our 8 LEDs mounted on the dulcimer are as follows:
(high) D= B.0
C= B.7
B= B.6
A= B.5
G= B.4
F#= B.3
E= B.2
D (low) =B.1
using the 28X1 chip they all work well.
 
Top