writing to eeprom

Moving a stepper clockwise/counterclockwise...I have assigned b0=5 b0=10 to each direction and trying writing it to the eeprom .....I found this thread

http://www.picaxeforum.co.uk/showthread.php?t=13629&highlight=storing+data

with in this thread hippy posted:
Think of Eeprom as a chest of drawers, each drawer numbered; whatever data is stored in a drawer can be retrieved from that drawer so ...

WRITE 3, 29 would store the number in drawer 3

READ 3, b0 would retrieve the number stored in drawer 3, b0 would be set to 29

my fear is that iam just writing over to the same drawer so to speak...
Code:
main:
  do
     if pinc.1 = 1 then 'move stepper left
        pause 2000
       gosub moveleft
      endif
    if pinc.2 = 1 then 'move stepper right
      pause 2000
       gosub moveright
      endif
    if pinc.3 = 1 then 'move stepper right
      pause 2000
       gosub cycle
      endif
    loop



moveleft:
     pause 1000
      b1 = b1 + 1 & %00000011
      let b0 = b0 + 1
    if b0 < 5 then moveleft 'step multiplier for gear ratio
    if pinc.7 = 1 then
       pause 2000
       let b0=5
       gosub learn
      endif 
     return





moveright:
    pause 1000
     b1 = b1 - 1 & %00000011
      let b0 = b0 + 1
     if b0 < 5 then moveleft 'step multiplier for gear ratio
       pause 2000
     if pinc.7 = 1 then 'learn mode
        pause 2000
        let b0=10
         gosub learn
       endif
     return
   
   
learn:
    
    write 1,b0 ‘ write value into b0
     pause 2000
   return
   
cycle:
    'code to be added

not use if this part of the coded is working
learn:

write 1,b0 ‘ write value into b0
pause 2000
return
 

Wayne62

New Member
Yes, you are writing over the same address. In the statement:
write 1, b0
the 1 is the address or "drawer" you are storeing the data in. Each address can hold only one value at a time. Instaed of using address 1, use a variable and increment it to store multiple values. The manual 2 page 218 has the full description.
 

Dippy

Moderator
Exactly.
I haven't followed all this in detail but it seems a basic 'learn' and 'playback'.

So, run it through your mind first.

If you wanted someone to teach you a sequence of actions, you'd want to store it in STEPS.
e.g.
1. Turn left
2. then straight on
3. Turn right at next junction
etc. until "You have reached your destination".
(.. certainly better than the Mother in Law can do :) )

Have a variable called MyStep

Symbol MyStep = B9 (or whatever)

Then before each call to GoSUb learn you incrmement it.

Increment MyStep
GoSub Learn

Then in learn you would have...
write MyStep,b0 &#8216; write value into b0


Obv you will have to limit the number of steps. I'll leave you to read up on that one.

Playback simply runs through:-

For b0 = 0 to MyStep
Read b0 , b1 ' Read previously stored valfrom EEPROM location b0 an stick into b1
' Do something with B1
Next

Thats just a simple loop, do with it what you want....
 
Last edited:

212

Senior Member
Please forgive my interruption, but I recently downloaded version 5.2.7 of the editor and my manual 2 only had 181 pages??? I am wanting to learn this too, so what version do I need to get???
 

Dippy

Moderator
Near the top of this page:
PICAXE Manual (dropdown)
|
PICAXE Manual 2 (BASIC Commands)

Click / Open.
Then in the window, near top left is "Save a Copy"

And select a convenient place and Save.

Does that work and give the full (currently 224 pages) version?
 

Wayne62

New Member
Hmm.. I have 5.2.7 also. Try the "PICAXE Manual" towards the top of this forum page. You may have a incomplete download of the manuals.
 

MartinM57

Moderator
You probably need to update your manuals from the "PICAXE Manual" link at the top if this page - should be 224 pages in the latest Manual 2...
 

212

Senior Member
Thanks! Yes, now I have the new manual, but it only says what the old one did on the subject, and it is of no use to me, I guess due to my lack of working brain cells.

I'll add a post to the linked topic, on the manual issue.
 

Dippy

Moderator
The place is full of Forum Kerbcrawlers.... just waiting to pounce and expose themselves :)

Followed by Martin going for his hat-trick !


212... you have tickled my curiosity and my rapidly dwindling grey cells ... what more do you want?
 

212

Senior Member
Being unfamiliar with that term, Kerbcrawlers, I went looking.... Luckily my wife didn't catch me looking at goggle images lol...

I need to be told like I'm 2 years old to understand things. Once I get it though, I can usually figure out how to use the information to fit my needs. I have another topic somewhere, where I asked about this too, I'll go find it. Thanks for asking !
 
Dippy ty for the explaination.....So if iam understanding right the following cose should work

Code:
learn:
        [COLOR="Red"]Symbol MyStep = B9 [/COLOR]
   do
     if pinc.1 = 1 then 'move stepper left
        pause 2000
        gosub learnleft
        endif
     if pinc.2 = 1 then 'move stepper right
       pause 2000
       gosub learnright
       endif
    loop

learnleft:
   do
     if pinc.1 = 1 then
       b1 = b1 + 1 & %00000011
       let b0 = b0 + 1
       endif
     if pinc.2 = 1 then
       [COLOR="red"]b3= MyStep+1
       write b3,b0[/COLOR]
       b0=0
       gosub learnright
       endif
     if pinc.1 = 0 then   
       goto learnleft
       endif
     loop
learnleft:
do
if pinc.1 = 1 then
b1 = b1 + 1 & %00000011
let b0 = b0 + 1
endif
if pinc.2 = 1 then
b3= MyStep+1
write b3,b0

b0=0
gosub learnright
endif
if pinc.1 = 0 then
goto learnleft
endif

If so my next question is can write to another set of "drawers" so two sets of data can be saved
 
Last edited:

Wayne62

New Member
The total number of eeprom space available depends on the picaxe chip used (listed in Manual 2 under read or write commands), for example,the 18x has 256 available numbered 0 - 255. In your example:
b3= MyStep+1
write b3,b0
you will be saving the contents of the variable b0 in eeprom loaction b3. So you have to be sure you have enough room for the number of data you want to save. If you need more room you can use extrenal eeprom, it's numbered in a similar way but the i2c commands are a little different than the read and write commands.
 
.....seems that the picaxe chips (28x2) then can only store one set of numbers then variable b0/contents <0-255>..

Iam very new at this so forgive me.....can the extrenal eeprom store several "contents" ........ variable b0/content 1 <0-255> , content 2 <o-255>, ect?
 

lanternfish

Senior Member
.....seems that the picaxe chips (28x2) then can only store one set of numbers then variable b0/contents <0-255>..

Iam very new at this so forgive me.....can the extrenal eeprom store several "contents" ........ variable b0/content 1 <0-255> , content 2 <o-255>, ect?
An 28X2 can has 256 (0 - 255) eeprom locations available for storage. Each location can hold a value of 0 - 255.

External (I2C) eeproms vary in size but in general can hold significantly more. Typically 16384 locations/65536 locations.

I may be a little confused at what you are trying to achieve, but shouldn't you be increasing the MyStep value after each learning step?

Cheers
 
lanternfish trying to write code to move a stepper motor to some location ...store data (the direction it moved and the ammount of step)...then play it back...Lol my grandson and I are trying to build a robot..the hardware is a breeze if he cab draw it I can build it....but the software on the other hand omg...

So if iam understanding you one can store too 255 locations and in each location store 255 peices of data.....

by combining to location b0.b1 a word can be created w1 which can store alot more

is this correct
 

BCJKiwi

Senior Member
Locations 0 to 255 so 256 locations.
Each location can store a single byte - i.e the contents of 'b' variable. A 'w' variable is a word variable and as it is 2 bytes will fill 2 of the 256 available locations.

It is possible to get creative if the content of a b variable stores more than a single piece of 'information' - if you can code the 'b' variable to hold useful info per bit.
e.g. if you want to store which pins are high or low, that could be the state of 8 pins in a single 'b' variable/byte/eeprom location.

Also be aware that the eeprom has a limited life of writes so provided this is a learn then play back rather than constantly changing state of play being recorded, all should be well.
 
Last edited:
Top