TC-360 RF remote version..question

212

Senior Member
A friend came up with a real cool idea...a camera mount that uses PIR sensors to tell the camera where to look. We have a Picaxe 14M running a 360 degree servo, inside an enclosure, and the output shaft is ball bearing supported. He, my friend, used six PIR motion detectors on his, and his has 12 possible positions, the six sensors, and the in-between ones if two sensors are active at once. He can put this in a field or in a meadow, and "watch" the whole place :)

Mine uses some RF remote sensors, and I put the receiver in with the Picaxe and servo. I set mine up with six "channels" and that's enough for what I want to do with mine.

I have a working code, and thanks to a post from Hippy about poke $8C,0, I have it running well, and it is low power too, thanks to being able to stop the servo timer or whatever it is...

I have pre-determined positions for the servo to go to, and what I would like to do is, customize the positions, in the field, to suit the needs. Reading on here for how to do it, I did connect a pot to an ADC pin, and I can move the servo with that just fine.

My question is....can I store the positions in the 14M memory, so the servo goes to where I tell it to...and can I do this without writing a new code every time I want to adjust it some??? I bet so...but how and where to start???
 

hippy

Ex-Staff (retired)
The EEPROM, READ and WRITE commands are what you need to look at. These allow non-volatile data within the PICAXE, data which will be remembered even when powered off. You'll read your positions from Data Eeprom, all you need is a means and some code adding to adjust what those positions should be and write them.
 

BeanieBots

Moderator
As stated by Hippy, Read & Write can be used to store the positions in EEPROM.
The 'imaginative' part is how to move and determine those positions.
It could even be done with a single button. Press to move, when released, store position 1. Press again to move, then store position 2 when released. Repeat for all six positions then start again over writting position 1 etc.
OR, you could have three buttons, one for CW one for CCW and one for save.

Many methods, depends on how many inputs you have left and how often postions are likely to require 'teaching'.
Personally, I'd take the 'lazy' route and hard code the positions with a little bit of trial and error with many program downloads but position teaching buttons would be much nicer.
 

MFB

Senior Member
This is a neat solution. I have been playing with a single PIR triggering a SD video recorder but found the field of view too restrictive. The subject (often deer) that triggered the PIR rarely appeared or, stayed very long, in the frame. Your steerable camera mount should help reduce this problem.
 

212

Senior Member
BeanieBots, I have my positions equally spaced out, but where I intend to put the thing, I know that won't work very well. I was considering taking a compass and mapping the positions I need that way, then write the code to suit, but in my mind somewhere, I sure thought I could adjust the positions another way. I'll look at the EEPROM, READ and WRITE commands, and maybe I can even use RF to do what I want. Once set though, I don't intend to change it, so I'll have to weigh the difficulty against the cool-ness :)

MFB, yes, that's what my friend is using too...Jazz DV150 and another ...an HD unit, which escapes me at the moment. Both work well, and we even have IR cut filter exchangers working on the Jazz cameras, so we have color day and IR at night. I'm running a security camera sending me the audio and video using RF, and i record it to S-VHS here in the house.

Thanks for the help!
 

212

Senior Member
Computer went nuts, and it started deleting everything all by itself... I have it working pretty well again, and I'm glad :)

Just an update on where I am now. I have built a servo controlled camera mount, that moves a camera around. Inside is an RF receiver, a PT2272M6 decoder, and a 14M. The decoder is paired with a PT2262 encoder, which I am using in place where I might use serial commands, but these are more efficient, power wise. I have a "valid transmission" pin, and 6 "channels" the way I am using it, one for each of 6 remote PIR sensors. When a sensor is triggered, the camera is supposed to turn and look where I put the sensor...and it does :)

I built a little remote using a matching transmitter and a PT2262 encoder, and I would very much like to be able to set my presets using it. I have a bunch of options for button presses, as I have 6 "channels" and I can use them together too. For instance, I might say:

if pin0 = 1 and pin1=1 then "set positions"

I read the manual about read and write, and it's way above my skill level...please help!

My thought is I might try something like...but this is just an idea, not a code I have:

set positions:

b1 = 100
servo 2, b1
pause 2000
do
b1=b1+1
servopos 2, b1
pause 1000
if pin0=1 then save_position
loop while b1<200
goto main

save_position:

doh...now what???
 

BeanieBots

Moderator
How about something like:-

b0=pins
b0=b0 & mask

Select case b0

case first_pattern
do first thing

case second_pattern
do second thing

etc. etc.
 

212

Senior Member
Remember, I'm only 2 years old (mentally) and I do not understand that either?? I "think" I want to learn how to "read" the current position, when I stop the servo where I want it to be, then store that position in the eprom place. Now when a pin goes high, I want the servo to go to that position. I would like this to be remembered when power is removed too, else I think I could figure it out myself???

It's mostly the read and write I don't get???

save_position:

doh...now what???

maybe....I could save each of the 6 positions as it's own ... b1~b6 = this position

read current position and write it to eprom as b1~b6 = this position
if pin1 = 1 then b0=b1
if pin2 = 1 then bo=b2
etc
servo 2, b0

I have no clue???
 
Last edited:

212

Senior Member
If I say write b0, b1...is this a different b1 or b0 than the regular ones I always use...like on page 10 of manual 2???
 

BeanieBots

Moderator
The b0,b1,b2... variables are what is called "global".
That means that they are the same (including in value) everywhere within your code. There is only one set of them.

If you want to store data even after power down, then you are on the right path looking at the commands "read" and "write".

Have a good of these commands in manual.
You can move your servo to where it needs to be.
Press a button (or whatever) to save the position to EEPROM.
Next time you power up, use read to get the value back from EEPROM and then use that value to move the servo to where it was before the power down.

Is that what you want to do? I'm getting a little confused now.
 

212

Senior Member
My confusion must be contagious, I hope we find a cure fast! I'll try to better explain, now that I'm a little more clear on it myself.

I want to turn the power switch on, and put the camera mount up on a pole. I want to push a button on my remote and have the servo move the camera to a preset position, at one end of the travel. I want the servo to move slowly toward the opposite extreme. When the camera gets to a desired position, I want to press a button on my remote and save that position as one of my presets. I have a button on my remote for each of 6 inputs on the 14M, so I can set position 1 to input one etc. The servo can now continue on it's way, till I want another position saved. Once the servo gets to the opposite extreme, the Picaxe will go to the center position and go into a low power loop. When a remote sensor puts one of the inputs high, I want to servo to go to the position that was assigned to that pin.
 

manie

Senior Member
As noob I think what worries 212.

If b1 contains the value 10 and b0 = 5, then "Write b1,b0" will put the value 5 into memory position 10 and conversely "Read b1,b0" will read the value 5 INTO b0 FROM memory position 10. Hope that helps a bit.
 

BeanieBots

Moderator
What manie says.

b0,b1,b2 etc are variables which hold your data.
EEPROM can be used to save that data when you power down.
Read & write are used to save and retrieve the data.

When the PICAXE powers up, all the variables will be reset to zero so to get your data back, you must read the EEPROM into one of your variables.

Break the problem down into sections.
Have a play with saving data first without any concerns about the rest of your program just yet.
 

212

Senior Member
'If b1 contains the value 10 and b0 = 5, then
'"Write b1,b0" will put the value 5 into memory position 10
'and conversely "Read b1,b0" will
'read the value 5 INTO b0 FROM memory position 10.
'Hope that helps a bit.

Yes it does! Thanks!!

do

b1 = 10
b0 = 5
Write b1,b0
pause 3000
b0 = 0
pause 3000
Read b1,b0
pause 3000
loop
 

212

Senior Member
Wow! Now the manual makes more since too :) I really appreciate the helpful replies, I think the seed sprouted and now I'm a blooming idiot lol...
 

212

Senior Member
I'm running very low on space and would like to add a few more things...but it's working! ..thanks to you guys:)

If there is a more efficient way of doing some of this, please share.




Code:
'   ADC1        'VR input = portc in c0/ADC1 (pin 0 powers VR)
'   portc pin2  'D4 
'   portc pin1  'D5
'   pin0        'D3
'   pin1        'D2
'   pin2        'D1   
'   pin3        'D0    
'   pin4        'VT..Valid transmission


'   pin 0       'output to VR...not used here though
'   pin 1       'output to servo power mosfet
'   pin 2       'servo control wire

'   poke $8C,0  '!!!!!!!!!!!!stops servo timer


let dirsc = %00000000        'make all portc pins = inputs
let pins = %00000000         'turn off all outputs
disablebod


b6 = 1
b7 = 2
b8 = 3
b9 = 4
b10 = 5
b11 = 145

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Restores presets after power is removed

read b6,b1
read b7,b2
read b8,b3
read b9,b4
read b10,b5

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Default positions and limits, so servo doesn't go nuts

b1 = b1 min 115 max 175
b2 = b2 min 115 max 175
b3 = b3 min 115 max 175
b4 = b4 min 115 max 175
b5 = b5 min 115 max 175


'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Low power main loop...servo moves to a preset position
'when RF receiver hears a valid signal from either an RF
'remote PIR sensor or from a handheld remote control

main:

do
nap 4
loop while pin4 = 0   'pin4 = Valid Transmission


if pin3 = 1 then scan 'pin3 = D0..look around and/or set presets 

if pin2 = 1 then      'pin2 = D1
b0 = b1
endif

if pin1 = 1 then      'pin1 = D2
b0 = b2
endif

if pin0 = 1 then      'pin0 = D3
b0 = b3
endif

if portc pin2 = 1 then       'D4
b0 = b4
endif

if portc pin1 = 1 then       'D5
b0 = b5
endif


if b0 <> b11 then   'if position needs to change
servo 2,b0
high 1
pause 2000
servopos 2, b0   'this seems to help achieve correct position???
pause 5000
low 1
low 2
poke $8C,0  '!!!!!!!!!!!!stops servo timer
b11 = b0

endif
goto main


'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'This will move camera from one extreme to another in steps
'Pushing a button on the remote sets that position to a preset

scan:

b0 = 175
servo 2, b0
high 1
pause 3000

do while b0>115
servopos 2, b0

b0 = b0 - 2

if pin4 = 1 then gosub mark_preset
pause 3000
loop
pause 3000
servo 2,145
pause 3000
low 1
low 2
poke $8C,0  '!!!!!!!!!!!!stops servo timer
b11 = b0
goto main


'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

'set the pre-set positions by pressing said button on remote transmitter

mark_preset:


if pin2 = 1 then  'pin2 = D1
let b1 = b0
write b6,b1
return
endif

if pin1 = 1 then  'pin1 = D2
let b2 = b0
write b7,b2
return
endif

if pin0 = 1 then  'pin0 = D3
let b3 = b0
write b8,b3
return
endif

if portc pin2 = 1 then   'D4
let b4 = b0
write b9,b4
return
endif

if portc pin1 = 1 then  'D5
let b5 = b0
write b10,b5
return
endif
pause 100
return
 
Last edited:
Top