Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:38 18 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PICAXE coding

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 521
Posted: 04:45am 09 Sep 2019
Copy link to clipboard 
Print this post

I thought I'd try and use the picaxe 08M2 for a project monitoring one or two
 water meters. There is a lamp that needs to be on if the meter/s are at or
 above the learned speed (rate). So here is my go at it. PICAXE Pros Please
 let me know if I've got any thing wrong.






;one-two channel low freq water meter monitor 20ppm to 12000ppm
#picaxe 08M2
#no data
symbol meter1 = C.1
symbol meter2 = C.2
symbol learn = pinC.3
symbol light = C.4

init:
read 252,WORD sp1 ; get saved data eprom/flash
read 254,WORD sp2 ;  valid only after learn used
let bn = 4 ; startup blink startup mode
let bh=10000 ; 10 sec high
let bl=10000 ; 10 sec low
gosub blink   ;4 * 20 sec 80sec to settle counts

start0:
if gm1=>sm1 and gm2=>sm2 then ;if gm's are at or above sm's
 high lamp ;then light on
else
 low light ;else light off
endif  
;later may add a serial LCD to show the counts and saves
     goto start0

start1:
count meter1, 60000, m1 ;get count for 60secs
let gm1=m1 ;update gm1
goto start1

start2:
count meter2, 60000, m2 ;get count for 60secs
let gm2=m2 ;update gm2
goto start2

start3:
pause 200 ;look for button press (low)
if learn <> 0 then goto start3  ;look for button pushed
       pause 100
if learn <> 0 then goto start3 ; still low 'good"
let bn=7     ;setup blink show learn mode
let bh=5000 ;5sec high
let bl=5000 ;5sec low
gosub blink ;7 * 10 sec 70sec lets counts settle
let sm1=gm1*.9 ;sm1=gm1-10% to allow a bit of drift
let sm2=gm2*.9 ;sm2=gm2-10%
write 252,WORD sm1 ;write to eprom/flash ???
write 254,WORD sm2 ;  "
goto  start3

blink:
for n=1 to bn ;blink n times
 high light ;lamp on
 pause bh ;on time
 low light ;lamp off
 pause bl ;off time
next n
return



Spent Saturday reading the online manual. Most parts easy enough others had to
reread and then go look at the examples. Just that the examples aren't enough
on some things. I think I got the parallel process right if each part gets a
slice of run time should work. Waiting for the USB cable and a few 08M2's to
show up then will know for sure.

Quazee137
 
f2cf1g
Newbie

Joined: 18/11/2016
Location: United Kingdom
Posts: 13
Posted: 08:56am 09 Sep 2019
Copy link to clipboard 
Print this post

Hi, I think you might be better to post your question to the very helpful Picaxe forum:
https://picaxeforum.co.uk/forums/active-picaxe-forum.2/
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 02:15pm 09 Sep 2019
Copy link to clipboard 
Print this post

With variable definitions added and some changes, the following compiles in the PE6 program editor and at least starts running in the simulator with delay set to 100ms.

CHANGES:
m1 is reserved; changed m1, m2 to mm1, mm2
"start0:" must be at beginning of program; replaced "init:" with "start0:" and put repeating code inside a DO...LOOP.
changed "high lamp" to "high light"

Maybe some others. To simulate, you probably want to make bh and bl a lot lower so you get through your blink routine quicker.

I've never used multiple starts, so I don't know if you need to explicitly activate start1, start2, start3.

The simulator is your good friend. You don't need an 08M2 to work through your code. Figuring out how best to input the values from your sensors may be an issue.

I think the simulator doesn't do the multiple thread thing, and I'm not sure that time-slicing here is your friend (other than for the blinking light, and there are other ways to accomplish that). Why not one master loop which checks the status of the pushbutton, reads one meter then the other, and then does what you want?

f2cf1g is right, you might get faster, better help on the picaxe forum.


' quazee01 ;one-two channel low freq water meter monitor 20ppm to 12000ppm
#picaxe 08M2
#no_data
symbol meter1 = C.1
symbol meter2 = C.2
symbol learn = pinC.3
symbol light = C.4

symbol gm1=w1
symbol gm2=w2
symbol sm1=w3
symbol sm2=w4
symbol sp1=w5
symbol sp2=w6
symbol bh=w7
symbol bl=w8
symbol mm1=w9
symbol mm2=w10

symbol bn=b26
symbol n=b27

start0:
read 252,WORD sp1 ; get saved data eprom/flash
read 254,WORD sp2 ;  valid only after learn used
let bn = 4 ; startup blink startup mode
let bh=10000 ; 10 sec high
let bl=10000 ; 10 sec low
gosub blink   ;4 * 20 sec 80sec to settle counts

do
 if gm1=>sm1 and gm2=>sm2 then ;if gm's are at or above sm's
   high light ;then light on
 else
  low light ;else light off
  endif  
;later may add a serial LCD to show the counts and saves
loop

start1:
count meter1, 60000, mm1 ;get count for 60secs
let gm1=mm1 ;update gm1
goto start1

start2:
count meter2, 60000, mm2 ;get count for 60secs
let gm2=mm2 ;update gm2
goto start2

start3:
pause 200 ;look for button press (low)
if learn <> 0 then goto start3  ;look for button pushed
      pause 100
if learn <> 0 then goto start3 ; still low 'good"
let bn=7     ;setup blink show learn mode
let bh=5000 ;5sec high
let bl=5000 ;5sec low
gosub blink ;7 * 10 sec 70sec lets counts settle
let sm1=gm1*9/10 ;sm1=gm1-10% to allow a bit of drift
let sm2=gm2*9/10 ;sm2=gm2-10%
write 252,WORD sm1 ;write to eprom/flash ???
write 254,WORD sm2 ;  "
goto  start3

blink:
for n=1 to bn ;blink n times
high light ;lamp on
pause bh ;on time
low light ;lamp off
pause bl ;off time
next n
return

Edited 2019-09-10 00:16 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3488
Posted: 03:14pm 09 Sep 2019
Copy link to clipboard 
Print this post

Hi Quazee137,

Personally I would add a 10nF at Vdd of the PICAXE08M2. Not sure how good the 10uF alone works.

@lizby: It is interesting to see that in start0: you have a nice do...loop structure, but tasks start1:, start2 and start3: have hard goto's….

Personally I have not tested the "count" command in 2 different tasks. As far as I know count is not interrupt driven on the edge, but there is an internal 20uSec timer interrupt for each "counter", where they poll the count pin.
How that behaves in a multitasking environment, I don't know.
Also since there is a task3 with EEPROM writes that typically blocks the second write until the write is allowed (first write success).

IF you get irregular count "reads" you may want to run both counts in one task, and alternate them. Count 1 for 60 sec's then count 2 for 60 sec's. Or 30 sec's each...
With 30 seconds you could even run at 8MHz.

Succes,

Volhout
Edited 2019-09-10 01:18 by Volhout
PicomiteVGA PETSCII ROBOTS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 04:15pm 09 Sep 2019
Copy link to clipboard 
Print this post

  Volhout said  @lizby: It is interesting to see that in start0: you have a nice do...loop structure, but tasks start1:, start2 and start3: have hard goto's….

Just copied Quazee's code except where something had to be changed to get "start0:" at the beginning--if writing from scratch, I would not have used GOTO.

Agree that C5 should be on the other side of the DC-DC module, as close to the picaxe power pins as possible.
Edited 2019-09-10 02:19 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 521
Posted: 10:28am 10 Sep 2019
Copy link to clipboard 
Print this post

Thanks for having a look at the code. It was what I came up with Saturday evening
after reading the online manual/s. I downloaded the tools for linux and will being
trying things out.

 I missed that m1 is reserved. Yup all so miss labeled lamp/light.
 The blinking times is what is wanted. I though that the blinking time and
 time slices would give the counts the time needed to get steady.
 The reads and writes I was unsure about in the byte/word types working
 as read/write word or read/write 2 bytes to make the word the manual example
 was for one byte. "I think"

 Does the cable have to be the $29 or can I make use of any USB to serial
 as long as I invert the RX and TX signals? I have a tiny dual xnor chip
 that and a switch for mode (MITES or PICAXE) makes it one tool for ether
 chip.

 In cleaning up the schematic I lost the other cap but then you know how easy it
 is to lose those SMD parts.  

 I have a version running in a 170 on the bread board working great.
 Was planning on using the tiny square 170 to fit case that it is to go in.
 The hot air tool is getting easier to use but that is tiny. So I though
 maybe a picaxe 08M2 would be a way to go.

 Thanks ALL
 Quazee137

Just went to https://picaxeforum.co.uk/forums/active-picaxe-forum.2/
I know I signed up there a few years back and never did much. Now for
some odd reason it says I an BANNED. Now to find our why and what to do next.
Edited 2019-09-10 20:39 by Quazee137
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 12:33pm 10 Sep 2019
Copy link to clipboard 
Print this post

  Quazee137 said  Does the cable have to be the $29 or can I make use of any USB to serial as long as I invert the RX and TX signals?


I use a usb-to-RS232 DB9 cable with a 3-pin header--but some work and some don't and I don't know how to buy one off of ebay which is guaranteed to work. It is also possible to use a usb-to-ttl serial module with an inverter, but that module has to recognize and pass on a BREAK signal, which the PICAXE Editor uses to initiate a download. Many people have had problems with not being able to download because of this BREAK issue. I wish I could point to a reliable download cable which is less expensive than the Rev-Ed one, but I can't.

Here is somebody's usb/serial CP2102 to picaxe inverter using a 74HC14:




  Quazee137 said  I know I signed up there a few years back and never did much. Now for
some odd reason it says I an BANNED. Now to find our why and what to do next.

Send a message to tech support to see if they can straighten it out (you probably have already figured that out).
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3488
Posted: 02:22pm 10 Sep 2019
Copy link to clipboard 
Print this post

Hi quazee137,

USB serial cables with a PL2303 in them do work. I have used several (from ATEN) with older chips, and newer (in W10 that means you have to install a different driver).
I run Linux (Lubuntu 18.04) and these work flawless. No need for different drivers whatsoever.

The only time you may need to help the software download to the 08M2 a bit is when you assigned a different function to the serial communication pin (because you ran out of pins). The 08M2 has only 4 otherwise... In some applications I needed a 5'th pin.

As mentioned by lizby, it has to do with the break. The USB chip should be able to hold that break indefinitely. Some chips time out after 1 character.

Volhout

This one works


Edited 2019-09-11 00:26 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 521
Posted: 11:08pm 10 Sep 2019
Copy link to clipboard 
Print this post

I have a lot of the PL2303TA's. Blue plastic housing with a 3 foot cable.
 Was using them before the 16f1455 chip. Now there is an idea . I have tube
 of them and a few MicroBridges.

 When I send a break to a PL2303TA in GtkTerm I receive a null 00H on my tester.
 Same with a few different USB-Serial modules I have.
 It is a single null not a stream.
 
 I also have a mix of the USB to RS232 cables a few have real +/- 12 Volts.

 @Volhout what software tools are you using in Lubuntu ?
 I have the LinAXEpad and the compilers.

 Still working on understanding the syntax.
 Learning from lizby's code mod. Thanks.

 I was going to use the 08M2 and an ESP-01 to replace a cable. Ended up using only
 ESP-01 with ESP-EASY .


Onward to more FUN
Quazee137

Funny thing I loaded the 170 code into LinAXEpad and the colored text
got me for a sec. Then loaded lizby's modded code.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 521
Posted: 09:46pm 29 Sep 2019
Copy link to clipboard 
Print this post

Update here

 The three Picaxe 08M2+s showed up. I tried a few USB to Serial converters none
 wanted to work. I was going to order the cable and looked at my ESP-01 USB to
 serial sitting there and said HAY why not give IT a try.




and YEA !! it worked.




 The parallel coding was not working so went to standard fall through coding.  

 This is working really well. It takes 30 seconds to test if meter/s
 is above 8PPM. If only one is the other is tagged at zero.


' mod of code from lizby's help.
' one-two channel low freq water meter monitor 9ppm to 10000ppm
#picaxe 08M2
#no_data
symbol meter1 = C.1
symbol meter2 = C.2
symbol learn = pinC.3
symbol light = C.4

symbol gm1=w1
symbol gm2=w2
symbol sm1=w3
symbol sm2=w4
symbol bh=w7
symbol bl=w8
symbol mm1=w9
symbol mm2=w10

symbol bn=b26
symbol n=b27

init:
sertxd( cr, lf, "getting sm's " )
' get startup values
count meter1, 15000, mm1 ;get count for 15secs
let sm1=mm1*4 ;update sm1 to ppm
'if above zero set to 8PPM
if sm1<>0 then
  let sm1=8
endif

count meter2, 15000, mm2 ;get count for 15secs
let sm2=mm2*4 ;update sm2 to ppm

sertxd( "sm1=", #sm1, " sm2=", #sm2, cr, lf )
'if above zero then set to 8PPM
if sm2<>0 then
  let sm2=8
endif
'if both are zero retry
if sm1=0 and sm2=0 then
  sertxd( "No Pumps are ON", cr, lf )
  goto init
end if

'ok got starting values and number of running meters
'now get running values
do
  sertxd( "getting gm's " )
  count meter1, 15000, mm1 ;get count for 15secs
  let gm1=mm1*4 ;update gm1
  count meter2, 15000, mm2 ;get count for 15secs
  let gm2=mm2*4 ;update gm2
  sertxd( "gm1=", #gm1, " gm2=", #gm2)
 'if gm's are above sm's
  if gm1=>sm1 and gm2=>sm2 then ;
    high light ;then light on
    sertxd( " Lite ON", cr, lf )
  else
    low light ;else light off
    sertxd( " Lite OFF", cr, lf )
 endif
loop



Now wiring up a 28 pin Ziff socket and and 8 pin cable to go to the ESP-01
USB to serial and work with all the Picaxes.  

Thanks lizby for the help.

Thanks Volhout saw some of your work at the picaxe forum great help to see working code.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 10:21pm 29 Sep 2019
Copy link to clipboard 
Print this post

I don't use any other USB <---> serial gadget now. CH340G always seems to just work when I have had a load of trouble from others - however, other  peeps seem to hold PL2303 etc. in high regards so maybe it's me *shrugs* but I have one of WW's 44 pin micromites on my desk right now that I daren't not move coz the USB chip on it with throw a paddy and then it's a reboot to get it back. I was looking at it sideways today and thinking I ought to cut the darned USB chip out of the loop and use a CH340G - got a bag of them in the workshop.
Edited 2019-09-30 08:30 by CaptainBoing
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3488
Posted: 11:03am 01 Oct 2019
Copy link to clipboard 
Print this post

Hi Quazee137,

Sorry for the late reply. I am using LinAXEpad also, but if you like there is a more advanced environment available called Blockly (also for Linux).

In Blockly you can develop code using "jigsaw puzzle pieces" similar to scratch, but there is a possibility to switch to text code development. An then you have a more advanced development environment compared to LinAXEpad.

Disadvantage is that you cannot go back to the jigsaw puzzle pieces.... Once in text mode, all development must happen in text mode.

What project of mine did you look at (the fuel gauge ?).

I have another project ongoing, that is not yet on the forum: a clock radio, using 4 digit 7 segment display, and one of those TEAxxx FM radio modules.

Regards,

Volhout
Edited 2019-10-01 23:02 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 521
Posted: 08:51pm 06 Oct 2019
Copy link to clipboard 
Print this post

Volhout

    Yes it was the fuel gauge I was looking at. Brought back memories
 of gluing balsa wood strips to paper. It took weeks to build a plane.
 Made a lot of planes that way. The controllers where much bigger and
 less range compared to today. Very different now with carbon fiber,
 plastic and electric driven planes.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3488
Posted: 01:43pm 07 Oct 2019
Copy link to clipboard 
Print this post

Yeah, those where the days... My first TX was a vacuum tube (DCC90) oscillator that was keyed.... Not a big success, to hard to control planes with keying.

Then a took a leave until proportional became possible. My second TX was homebuild using transistors.
Trimming was all done adjusting the hardware.
Now with computer controlled RX and TX it is soo simple.. and far more reliable.. and cheaper...

My dearest planes are still balsa. With methanol engines.
But I do have some foam planes, with electric engines. Both have their charme. The electric planes are smaller, and company me on holidays. There is always room for an RC plane on holiday.

Greetz….
PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024