Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:54 24 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 : Picomite serial client code; MMB4W controller

     Page 1 of 2    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 05:09pm 23 May 2022
Copy link to clipboard 
Print this post

I have a picomite rigged with a 4-relay module (3 being used to turn on 12V LEDs) and two DS18B20 temperature sensors.

Here's the program which the client picomite runs:
' serCli.bas evaluates serial messages
OPTION AUTORUN ON
dim string cmd
pause 2000
print "Picomite SerialClient starting"
' SetPin 22,21,com1 ' setpin 21,uart0tx:SetPin 22,uart0rx
' open "com1:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters
SetPin 11,12,com2 ' setpin 21,uart0tx:SetPin 22,uart0rx
open "com2:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters

DO ' the program loops forever
WATCHDOG 2000 ' this will recover from errors
LOOP

SUB SerInt ' received a message
  pause 20 ' allow all characters to arrive (11,520/sec, ~230 in 20 milliseconds
  cmd=input$(255, #1)
  s$="NAK"
  print cmd;
  on error skip 4
  execute cmd ' e.g., "s$=tempr(17)" for function, "pin(16)" for command
  if s$="NAK" then ' EXECUTE didn't fail and s$ not set by command
    s$="ACK" ' returned if "s$" not set by execute and command succeeded
  endif
  xx$="" ' throw away for error
  print #1,s$
  do while loc(#1)>0: cmd=input$(255,#1): loop ' flush the input buffer
END SUB ' return from the interrupt

Geoff's I2C code was the inspiration, but the EXECUTE command makes it much simpler.

Here's the code for MMB4L (or MMBasic DOS or MMB4L or other picomite or serial outputter):
' testSerCli ' test serial client picomite from MMBasic for Windows

const pTANKPUMP=19,pYARDPUMP=20,pHEATPUMP=16

open "com14:115200" as #1
pause 500
print #1,"dim integer pTANKPUMP=19,pYARDPUMP=20,pHEATPUMP=16"
pause 1000
a$="?"+chr$(34)+"pTANKPUMP,pYARDPUMP,pHEATPUMP pin ="+chr$(34)+",pTANKPUMP,pYARDPUMP,pHEATPUMP"
' print a$
print #1,a$
pause 1000
print #1,"setpin pTANKPUMP,dout"
pause 1000
print #1,"setpin pYARDPUMP,dout"
pause 1000
print #1,"setpin pHEATPUMP,dout"
pause 1000
do while loc(#1)>0: a$=input$(255,#1): loop

do
 do while loc(#1)>0: a$=input$(255,#1): loop ' synchronize
 print #1,"pin(pTANKPUMP)=1"
 pause 100
'  if loc(#1)>0 then: line input #1,a$: ?"TANKPUMP OFF: "+a$: endif
 if loc(#1)>0 then
   line input #1,a$
   ?"TANKPUMP OFF: "+a$
 endif
 pause 100
 print #1,"pin(pYARDPUMP)=1"
 pause 100
 if loc(#1)>0 then: line input #1,a$: ?"YARDPUMP OFF: "+a$: endif
 pause 100
 print #1,"pin(pHEATPUMP)=1"
 pause 100
 if loc(#1)>0 then: line input #1,a$: ?"HEATPUMP OFF: "+a$: endif
 pause 100

 print #1,"s$=str$(tempr(17))"
 pause 1000
 if loc(#1)>0 then: line input #1,a$: ?"Outside Temperature: "+a$: endif
 pause 100
 print #1,"s$=str$(tempr(29))"
 pause 1000
 if loc(#1)>0 then: line input #1,a$: ?"Inside Temperature: "+a$: endif
 pause 100

 print #1,"pin(pTANKPUMP)=0"
 pause 200
 if loc(#1)>0 then: line input #1,a$: ?"TANKPUMP ON: "+a$: endif
 pause 100
 print #1,"pin(pYARDPUMP)=0"
 pause 200
 if loc(#1)>0 then: line input #1,a$: ?"YARDPUMP ON: "+a$: endif
 pause 100
 print #1,"pin(pHEATPUMP)=0"
 pause 200
 if loc(#1)>0 then: line input #1,a$: ?"HEATPUMP ON: "+a$: endif
 pause 100

 pause 5000
loop

Here's the output on the MMB3W side:



Note the "Outside Temperature" changing as I held the waterproof DS18B20.

If the command sent to the picomite sets the value of s$, then that value is returned. Otherwise, "ACK" is returned for success and "NAK" for failure of the command. Here's the output on the MMB4W side:
> run
Picomite SerialClient starting
dim integer pTANKPUMP=19,pYARDPUMP=20,pHEATPUMP=16
?"pTANKPUMP,pYARDPUMP,pHEATPUMP pin =",pTANKPUMP,pYARDPUMP,pHEATPUMP
pTANKPUMP,pYARDPUMP,pHEATPUMP pin =      19      20      16
setpin pTANKPUMP,dout
setpin pYARDPUMP,dout
setpin pHEATPUMP,dout
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
s$=str$(tempr(29))
pin(pTANKPUMP)=0
pin(pYARDPUMP)=0
pin(pHEATPUMP)=0
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
s$=str$(tempr(29))
pin(pTANKPUMP)=0
pin(pYARDPUMP)=0
pin(pHEATPUMP)=0
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
s$=str$(tempr(29))
pin(pTANKPUMP)=0
pin(pYARDPUMP)=0
pin(pHEATPUMP)=0
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
s$=str$(tempr(29))
pin(pTANKPUMP)=0
pin(pYARDPUMP)=0
pin(pHEATPUMP)=0
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
s$=str$(tempr(29))
pin(pTANKPUMP)=0
pin(pYARDPUMP)=0
pin(pHEATPUMP)=0
pin(pTANKPUMP)=1
pin(pYARDPUMP)=1
pin(pHEATPUMP)=1
s$=str$(tempr(17))
>


The MMB4W program has no error checking.

(Note that for this relay as configured, 0 turns it on and 1 turns it off.)





~
Edited 2022-05-24 03:48 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3505
Posted: 07:52pm 23 May 2022
Copy link to clipboard 
Print this post

Hi Lizby,

What a good example of the use of the execute command. I know I tried similar as you did by executing from the commandline, but this seems much simpler when you already have the access to the remote IO (in my case I used a virgin pico).

What you are missing is the possibility to upload a complete MMBAsic program to the pico (but you may not need that).

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5711
Posted: 09:15pm 23 May 2022
Copy link to clipboard 
Print this post

Probably safer if you didn't... :)

This is a great working example. It's the sort of thing I was aiming for with my designs for remote I/O modules. Are you intending to add error checking?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 10:59pm 23 May 2022
Copy link to clipboard 
Print this post

Thanks, @Volhout. I'm not looking to be able to download a full program. I just wanted to be able to do I/Os from a remote box.

Mick--thanks. As I elaborate an actual controller program, I will add some error checking--at least to do something if a "NAK" is received.

I'm not sure what all the error conditions will be, and might need to have access to the console on the remote Picomite to find out. On the other hand, if the serial connection from the PC to the picomite was a Cat5/6 cable also carrying power, then you would be able to see the console and download a new program.

The next thing I will try is a subroutine built into the picomite to read 8 DS18B20s in a second with TEMPR START and TEMPR. I'm assuming that the subroutine called by EXECUTE will return properly to the right place--I'll find out soon.

I probably need to put in a startup message so that if there's a timeout of the watchdog timer, the PC program will be able to know that it occurred. Lots of ins and outs here, but for straightforward serial control of the pins on a remote micro, this seems sufficient, and EXECUTE makes it dead simple.
Edited 2022-05-24 09:50 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 11:34pm 24 May 2022
Copy link to clipboard 
Print this post

Here's a version of the Picomite client in which the MMB4W PC/serial controller can call a subroutine in which as many DS18B20 temperature sensors as one likes may be called in about one second with TEMPR START performed for each, then a PAUSE 750, and then TEMPR.

' serCli.bas evaluates serial messages
' if first character is "!", text data is to be returned, CR terminate
'   otherwise, single command is to be run with "EXECUTE"
OPTION AUTORUN ON
dim string cmd, s$
dim integer nTemps ', pTemps(12)
dim float fTemps(12)
pause 2000
print "Picomite SerialClient starting"
' SetPin 22,21,com1 ' setpin 21,uart0tx:SetPin 22,uart0rx
' open "com1:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters
SetPin 11,12,com2 ' setpin 21,uart0tx:SetPin 22,uart0rx
open "com2:115200, 256, SerInt, 4" As #1 ' interrupt triggered with 4 characters

DO ' the program loops forever
WATCHDOG 2000 ' this will recover from errors
LOOP

SUB SerInt ' received a message
  pause 20 ' allow all characters to arrive (11,520/sec, ~230 in 20 milliseconds)
  line input #1,cmd ' cmd=input$(255, #1)
  s$="NAK"
  print cmd;
  on error skip 4
  execute cmd ' e.g., "s$=tempr(17)" for function, "pin(16)=1" for command
  if s$="NAK" then ' EXECUTE didn't fail and s$ not set by command
    s$="ACK" ' returned if "s$" not set by execute and command succeeded
  endif
  xx$="" ' throw away for error
  print #1,s$
  do while loc(#1)>0: cmd=input$(255,#1): loop ' flush the input buffer
END SUB ' return from the interrupt

SUB readTemps ' controller sends, e.g., "nTemps=5" & then "redim pTemp(5)=(10,32,14,29,17)" & then "readTemps"
' ?"readTemps: nTemps="+str$(nTemps)+": ";
 if nTemps > 0 then
   for i%=1 to nTemps
'      ?str$(i%)+" "+str$(pTemps(i%))+"; ":
     if pTemps(i%) > 0 then: tempr start pTemps(i%): endif
   next i%
   pause 750 ' allow DS18B20s to read temp
   s$=""
   for i%=1 to nTemps
     if pTemps(i%) > 0 then
       fTemps(i%)=tempr(pTemps(i%)): s$ = s$ + str$(fTemps(i%),0,2) + " " ' : ?fTemps(i%)," ";
     endif
'      ?" "
   next i%
 endif
'  ?" "+s$
END SUB

Here's the controller program:

' testSerCliTemps.bas ' test serial client picomite from MMBasic for Windows

const nTemps=5
dim integer pTemps(5)=(0,10,32,14,29,17)

open "com14:115200" as #1
pause 500
print #1,"nTemps=5"
pause 100
print #1,"dim integer pTemps(5)=(0,10,32,14,29,17)"

do
 do while loc(#1)>0: a$=input$(255,#1): loop ' synchronize
 print #1,"readTemps"
 pause 1100 ' allow temperatures to be read
 if loc(#1)>0 then
   line input #1,a$
   ?"Temps for 10,32,14,29,17: "+a$
 endif
 pause 5000
loop

And the serial input returned to the controller:



You can see the temperatures rising and falling as I hold or release the sensors.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 12:03am 07 Jun 2022
Copy link to clipboard 
Print this post

Here's another way to do this--no program at all on the PicoMite client--just MMBasic. Your MMB4W program just acts like a user by supplying commands at the ">" prompt, and interpreting the result.

I set up serial console and connected through 10' of Cat5 with a couple of RJ45 breakout connectors. I used Mixtel90's picomite with 20x2 header, cut out of his "pear" pcb:


This picomite is in a box with a 4-relay module. In addition to the RJ45 connector, the box has 4 power panel mount jack for the relays plus another for the voltage switched by the relays, and 5 panel mount 3.5mm stereo audio jacks for DS18B20 sensors.

I don't have any notable skill as a machinist, even in plastic, but it does work:



The program defines the four pins controlling the relays and sends a SETPIN command for it. Then in an infinite loop it sends a command to randomly turn on or off one of the 4 relays, and to print the 5 temperatures ("? TEMPR(pin#)") separated by a space each. With FIELD$, the program breaks out the temperatures, formats them with 3 decimal points, prints them, and then pauses for 2 seconds.

' geopico0.bas
dim string a,b,c,r,s,t,u
dim integer i,j,k,l,m,n,iONOFF,ledpin(4)=(0,19,20,21,22), temppin(5)=(0,24,29,31,32,34)
dim float d,e,f
open "com5:115200" as #1
s=""
for i=1 to 4: s=s+"setpin "+str$(ledpin(i))+",dout:": next i: ' print s
print #1,s ' +":?"+chr$(34)+"!"+chr$(34) '  "!" to provide response
pause 1000
a=input$(255,#1) ' clear response line
do
 if loc(#1)>0 then
   pause 100
   do while loc(#1) > 0
     line input #1,a
'      print ": ",a
     if mid$(a,1,1)="!") then
       'print a
       s="": for i=2 to 6: f=val(field$(a,i," ")): s=s+str$(f,2,3)+" ": next i
       print s
       a=input$(255,#1) ' clear response line
     endif
   loop
 endif
 s="? "+chr$(34)+"!"+chr$(34)+";"
 for i=1 to 5: s=s+"tempr("+str$(temppin(i))+");"+chr$(34)+" "+chr$(34)+";": next i
 iONOFF=cint(rnd()) ' 0=off, 1=on
 k=fix(rnd()*4)+1 ' pin number index 1-4
 t="pin("+str$(ledpin(k))+")="+str$(iONOFF)
 print #1,t: print #1,s+"" ' : print t+" "+s
 pause 2000
loop

Here's the output; you can see the temperatures change as I touch and release the waterproof sensors:



Here's a youtube video--not much action except for the relays randomly turning on and off 12V LEDs.
Picomite box 4 relays, 5 DS18B20s, MMB4W controlled

Of course, the control program wouldn't have to be on MMB4W--it could be on another Picomite or micromite, or on MMB4L, or on any device with serial output (rewritten for that device).

I plan to test this soon with 50' of CAT5. Wondering if it will still work at 3V3.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 05:13am 07 Jun 2022
Copy link to clipboard 
Print this post

  lizby said  Here's another way to do this--no program at all on the PicoMite client--just MMBasic. Your MMB4W program just acts like a user by supplying commands at the ">" prompt, and interpreting the result.


AND IT INCLUDES A WONDERFULLY INGENIOUS USE OF EVAL!!! As usual, you're way ahead of me, Lance.

I used to like dBase, Clipper and FoxPro because they could interpret programming statements which were presented to the interpreter as data. They called it "run time interpretation" as opposed to pre-compiled or tokenized interpretation. This idea makes it possible to build programming steps at run time which immediately leads to self-modifying programs and programs driven by data elements.

You could build a complicated algebraic formula, name it to a string variable, then enclose that named string variable in parenthesis after an ampersand and pass it to the interpreter and it would be evaluated.

To solve for the definite integral of Sin^5 A dA you would get this binomial expansion ...

INTEGRAL (Sin^5 A dA)
= INTEGRAL (Sin A * (Sin^2 A)^2 ) + k
= INTEGRAL (Sin A * (1 - Cos^2 A)^2)  + k
= INTEGRAL (Sin A * (1 -2 Cos^2 A + Cos^4 A) ) + k
= INTEGRAL (Sin A) - 2 * ( Sin A * Cos^2 A)  +  (Sin A *  Cos^4 A) ) + k

Then by INTEGRAL ( u ^n du) = (u ^(n+1) ) / n+1 you would get ...

= -Cos A + ( 2/3 * Cos^3 A)  - ( 1/5 * Cos^5 A) + k

You would then programmatically set ...

P$ =  "-Cos A + ( 2/3 * Cos^3 A)  - ( 1/5 * Cos^5 A) + k"

You would then pass this formula as data to the interpreter in programming steps (assuming degrees, not radians) like this ...

for A = 0 to 90 step 5 : PRINT &(p$): next A

and the interpreter would magically evaluate and print the 19 calculated values for the binomial expansion INTEGRAL of (Sin^5 A dA).

It was magic!!!

So is EVAL()!!!

  lizby said  I set up serial console and connected through 10' of Cat5 with a couple of RJ45 breakout connectors. I used Mixtel90's picomite with 20x2 header, cut out of his "pear" pcb:

This picomite is in a box with a 4-relay module. In addition to the RJ45 connector, the box has 4 power panel mount jack for the relays plus another for the voltage switched by the relays, and 5 panel mount 3.5mm stereo audio jacks for DS18B20 sensors.


That's a really nice looking box. Just what is needed in a dusty, damp, dirty cellar!

  lizby said  I don't have any notable skill as a machinist, even in plastic, but it does work:



HMMMMMMM ..... I think you are hiding your light under a bushel. Seems to me I remember some other boxes you made way back in the far distant past.



NOW THAT'S A REALLY FANTASTIC LOOKING BOX!!!! Have you ever thought about going into business making boxes? Maybe if you had a 3D printer up there in the wilds of Canada ....

  lizby said  Of course, the control program wouldn't have to be on MMB4W--it could be on another Picomite or micromite, or on MMB4L, or on any device with serial output (rewritten for that device)..


Oh heck ... it could even be on a little LINUX box, if MMBasic will run under LINUX. I used to be able to run big UNIX boxes. I can probably learn to start up LINUX.

I see that you are using four of those cheap Chinese relays. They are the obvious failure point. Have you found an easy way of replacing the entire relay board, preferably with limited tools, with a spare?

  lizby said  I plan to test this soon with 50' of CAT5. Wondering if it will still work at 3V3.


I think I remember something about needing to send a separate 3.3v conductor to each sensor instead of using a pull-up resistor to power it using phantom power. It should work that way.

BY THE WAY EVERYBODY ... I CASE YOU HADN'T GUESSED ALREADY ... LANCE HAS VOLUNTEERED TO HELP ME GET THIS LONG DORMANT PROJECT OF MINE FINISHED! I NEVER WOULD BE ABLE TO GET IT DONE WITHOUT HIM ... I'M JUST TOO DARNED OLD AND DECREPIT!! THANK YOU, LANCE!!!

I might soon have some real data about the performance of my Geothermal Heat Pump to share with all of you. It has been running since 2013 but I have very little idea of how much work it is accomplishing.

Paul in NY
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3650
Posted: 05:36am 07 Jun 2022
Copy link to clipboard 
Print this post

Paul,

You can run the above under Linux & yes it's easy enough to set up.

John
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:59am 07 Jun 2022
Copy link to clipboard 
Print this post

Quickest AE delivery that I ever had  








Craig
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 11:54am 07 Jun 2022
Copy link to clipboard 
Print this post

Paul--it was late when I posted this, or I would have emailed you about it. I see you're keeping up with the forum.

Yes, this is a working mock-up for your geothermal HVAC system (cooling side). I need to add the panel mount 3.5mm audio jacks for 2 more DS18B20s (yes, they are powered from 3V3 on the tip-sleeve-ring audio plugs (3V3, signal, 0V), not parasitically), and two panel mount power jacks for 5V from the motor on/off sensors, and I think the box contains what you have specified for hardware.

Several people have testified that MMB4W runs well under WINE on Linux, but there is also nothing about the controller program which would not run straight up with MMB4L. However, if you want to add graphical stuff you need MMB4W. Or you can use PC drawing characters like this (though I don't remember whether MMB4L supports DEFINEFONT):



Regarding a spare, I was thinking of an entire separate box. A lot of unplugging and plugging because, no, it would not be easy to replace that relay board. That one was what I had on hand; I've ordered these 4-ch SSRs (a little smaller--no idea how they'd compare for reliability):
4-SSR module
Edited 2022-06-07 22:08 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3838
Posted: 12:17pm 07 Jun 2022
Copy link to clipboard 
Print this post

  lizby said  I don't remember whether MMB4L supports DEFINEFONT)


It doesn't because it would need a custom graphical console (like MMB4W) to do that. Instead use OPTION CODEPAGE to make the box drawing and other extended characters available as characters 128-255 or use explicit UTF-8 via CHR$(UTF8 codepoint%).

Note that much as I wish MMB4L had some users I'm uncomfortable with the idea of it being used in a heating control system without some less serious applications having been thoroughly tested first - hope you have good Q/A.

Best wishes,

Tom
Edited 2022-06-07 23:00 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 12:34pm 07 Jun 2022
Copy link to clipboard 
Print this post

  Paul_L said  
  lizby said  I don't have any notable skill as a machinist


HMMMMMMM ..... I think you are hiding your light under a bushel. Seems to me I remember some other boxes

Woodworking is a different matter--I'm comfortable with wooden boxes:


PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 11:55am 08 Jun 2022
Copy link to clipboard 
Print this post

  thwill said  
  lizby said  I don't remember whether MMB4L supports DEFINEFONT)


It doesn't because it would need a custom graphical console (like MMB4W) to do that. Instead use OPTION CODEPAGE to make the box drawing and other extended characters available as characters 128-255 or use explicit UTF-8 via CHR$(UTF8 codepoint%).

Note that much as I wish MMB4L had some users I'm uncomfortable with the idea of it being used in a heating control system without some less serious applications having been thoroughly tested first - hope you have good Q/A.

Best wishes,

Tom


Hi Tom,

The intention is to use a Windows/LINUX box with a screen and rudimentary keyboard running MMB under either DOS or Windows to control a PICO or CMM2 (if it is ever available again) to control the machinery. I'm confident in the stability of MMBasic. I'm not terribly worried about power failures because the machinery will be shut down without power anyway. I am concerned about the whole thing being able to start up and resume operation after a power failure.

I suspect that I will default to the DOS extended ASCII box characters for the display screen.

Paul in NY
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 12:09pm 08 Jun 2022
Copy link to clipboard 
Print this post

Lance,

I have some reservations and questions about the way this thing is coming together.

The relays will be switching the 28 v.a.c. coils of heavier relays.  They can develop pretty big inductive spikes at turn off time. Is it advisable to have these 28 v.a.c. switching circuits in the same box with the PicoMite or should the relays be in a separate box of some sort?

The power relays are not all conventional relays. The smaller ones are the Functional Devices RIBU1C which have some sort of solid state circuit instead of a conventional coil. The coil will accept either 10 to 30 v.a.c., 10 to 30 v.d.c., or 120 v.a.c. Here's a link to the data sheet. RIB RELAY

It's too bad that these RIB relays need 10 v.d.c. otherwise we might be able to switch them directly from the PicoMite pin which would avoid having the Chinese relays involved at all.

It might be possible to use the cheap Chinese relays to power some of the smaller pumps. The smallest pump is rated at 1/20 hp or about 38 Watts. But that would mean that the cheap realy will be switching 120 v.a.c. Would this mean that it is even less advisable to have the relays in the same box with the PicoMite?

I'm not sure about using the Javino SSRs you found. It sounds like a good idea but who knows how reliable they will be. The Javino web site doesn't have any real technical specs for them.

I believe that both 5 v.d.c. and 3.3 v.d.c. power will be needed for the PicoMite and the temperature sensors. Will this mean two separate wall warts, both feeding into the same box or can we amek do with just a 5 v.d.c. wall wart and then follow it with wither a zener clamped resistive divider or a separate voltage regulator IC circuit?

To do this job the PicoMite will have to have a program loaded, either MMBasic alone, or MMbasic plus a communication program talking to the PC contoller.

How reliable will the flash memory holding the programs be after a power failure?

Will the PicoMite be able to restart and resume working without manual assistance after a power failure?

Is battery backup advisable or possible?

Should we quit trying to use a PicoMite and wait for the renewed production of the CMM2 which could load programs from an SD card after a power failute?

I have been running the heat pump on a kludged up hodgepoge of relays since 2013. If you think we should wait for renewed production of the CMM2 that would not be a catastrophe.

How difficult will it be to physically re-flash the PicoMite with MMBasic plus (maybe) a comm program while it is in the little blue box duct taped to an overhead joist above the array of pumps and pipes in my cellar?

I think you are probably right about having replacement pluggable boxes waiting for a failure rather than plan on replacing the PicoMite board or relay board in the failed box.  If the relays are in a separate box it would mean having a second spare box full of relays.

In your photograph of the blue box I don't see a row of jacks which would connect to each of the temperature sensors. It looks like there are insufficient jacks of all types to make the box truly pluggable. Where did you hide them?

Do you have any ideas about a rudimentary display for the PicoMite in the cellar. Usually nobody will be down there to watch it but  I would like to see something shining in the dark to confirm that it's alive, even if it's just a bunch of LEDs.

If there is a convenient way to display the temperatures it is reading that would be nice but probably overkill.

Paul in NY
Edited 2022-06-08 22:10 by Paul_L
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5711
Posted: 01:13pm 08 Jun 2022
Copy link to clipboard 
Print this post

Just a couple of points for a control system installed in a cellar.

I'd recommend using two boxes gasketed together with the various connections going between them. The lower box is then just a cable box, but it keeps dust and dirt out of the connectors. Cables could enter ffrom the bottom or both ends. The upper box contains the electronics and has no outward holes in it at all. In fact, it could even be sealed with silicone. It would be possible to fit a window over a small LCD display or some LEDs for local monitoring. The boxes should be screwed together and the complete assembly fitted to the wall with gaskets and silicon sealant  at any screw holes to keep damp out. The PicoMite could be mounted with the USB socket downwards and accessible from the cable box.

Personally I'd like to see a third box with a door-interlocked mains isolator on it and containing SSRs protected by individual fuses (which are also individual isolation devices). A multicore cable would connect it to the control box. The mains box can then be safely earthed if it's metal and, as the SSRs will have opto-isolated inputs, there is no danger of getting mains near the PicoMite. Most SSRs will work from 3V3 inputs now, but you could just feed the PicoMite box at 5V (it produces its own 3V3) and use small mosfets or transistors to drive the SSD inputs from that supply.

If full rating SSRs aren't viable because of the loads then I'd still recommend using small ones and mains coils on the contactors. Adding a 28V supply is adding another layer that can go wrong, and the less mechanical contacts the better.

If the RIBU relays are essential, then I'd use 5V (some 6V ones will also work) telecoms-type relays to power them from 120V. These little relays are standardised, easy to get and cheap. Many of them are rated up to 250V AC, but at that the current needs to be low (which it is here - only 30mA). They can't be driven directly by a PicoMite, but the5V supply is there.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 01:13pm 08 Jun 2022
Copy link to clipboard 
Print this post

Paul,

Re flashing the picomite: as presently configured in the box, this right angle "up" micro usb cable could be left plugged in to the picomite and dangling out of the box,


micro usb right angle up cable
But I see no likely circumstance in which the picomite would need to be reflashed with the MMBasic firmware, since all the picomite will be doing is turning 4 pins on and off, reading the status of 2 pins, and reading 7 (or more) DS18B20 sensors.

Re loading an MMBasic program to the picomite, the last posting of code required no MMBasic user program whatsoever on the picomite--the MMB4W program sends MMBasic commands to the console prompt to be executed. However, since the console prompt is what is available via serial, you could simply shut down the MMB4L program, start TeraTerm and connect it to the serial port, and you would have the ">" prompt. From that point, AUTOSAVE and pasting in a program and terminating with Ctrl+z would load a program to the picomite. It would survive power cycling.

Re the relays, I put them in since you had indicated that 28V AC would need to be switched to turn on/off the 120V AC motor relays. If, as you say, they can also be switched with 12V DC, I would be much happier to use MOSFETs. These could be mounted on a PCB with the picomite. Or either 12V DC MOSFETs or relay modules could be mounted in a separate box.

As presently configured, the CAT5/6 cable carries 5V from the PC to the box to the VSYS pin, and the switcher on the picomite provides the 3V3 from that. With the relay module, with 3V3 on the DC+ input, only 3 of the 4 relays switched. Providing 5V to that power input allowed all of the relays to switch with the 3V3 signals from the picomite.

>How reliable will the flash memory holding the programs be after a power failure?

With many power cyclings, I've never had a picomite fail to be able to run the MMBasic program it was previously loaded with, nor have I heard of such failure (but this picomite doesn't have any MMBasic program--just the firmware).

>Will the PicoMite be able to restart and resume working without manual assistance after a power failure?

Yes. But the MMB4W control program also has to restart.

>Should we quit trying to use a PicoMite and wait for the renewed production of the CMM2 which could load programs from an SD card after a power failute?

I don't see any benefit which the CMM2 would provide for this application, and many drawbacks.

>In your photograph of the blue box I don't see a row of jacks which would connect to each of the temperature sensors. It looks like there are insufficient jacks of all types to make the box truly pluggable. Where did you hide them?

In the photo there are 5 3.5mm 3-connector jacks on the lower right, with holes drilled for 9 (3 columns of 3 jacks). I've since added 2 more for a total of 7 (9 available).

>Do you have any ideas about a rudimentary display for the PicoMite in the cellar ... to display the temperatures

Pins are available to add an SPI display up to 4" & 480x320, but that would significantly complicate the making of the box. Easier would be adding an ESP-01 which could display a web page on its own AP so your cell phone could look at it.
Edited 2022-06-08 23:20 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5711
Posted: 01:18pm 08 Jun 2022
Copy link to clipboard 
Print this post

Put the program in a flash slot and use OPTION AUTORUN n to run it automatically on boot. There's no need for manual restarting.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 01:46pm 08 Jun 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  Just a couple of points for a control system installed in a cellar. . . .


Good ideas, Mick. This is just a working mock-up. Fully functional, I hope, and capable of exercising all the inputs and controlling the outputs with a picomite controlled by an MMB4W program.

Any ideas about optimizing the physical configuration are welcome.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 03:46pm 13 Jun 2022
Copy link to clipboard 
Print this post

Here's a version which more nearly aligns with Paul's specifications. The pins for the relays (for pumps) and temperature sensors and other inputs are named rationally for his application (pYARDFEED, pYARDRTRN, pTANKFEED, pTANKRTRN, pTANKCNTR, pOUTSIDE, pINSIDE, pYARDPUMP, pTANKPUMP, pHVAC, pYARDRUNNING, pTANKRUNNING):
' geopico_01.bas
 Option EXPLICIT
const pYARDFEED=29,pYARDRTRN=31,pTANKFEED=32,pTANKRTRN=34,pTANKCNTR=9,pOUTSIDE=26,pINSIDE=27 ' temperatures
const pYARDPUMP=19,pTANKPUMP=20,pHVAC=21,pAVAILABLE=22,pYARDRUNNING=24,pTANKRUNNING=25 ' outputs & inputs
dim string a,b,c,r,s,t,u,cmd,QT=chr$(34)
dim integer i,j,k,l,m,n,iONOFF,TRUE=1,FALSE=0,TESTING=TRUE
dim integer ledpin(4)=(0,pYARDPUMP,pTANKPUMP,pHVAC,pAVAILABLE)
dim integer temppin(7)=(0,pYARDFEED,pYARDRTRN,pTANKFEED,pTANKRTRN,pTANKCNTR,pOUTSIDE,pINSIDE)
dim integer runningpin(2)=(0,pYARDRUNNING,pTANKRUNNING)
dim float d,e,f
dim string TTxt(7) ' temperature sensor labels
 TTxt(1)="  Yard Feed":TTxt(2) ="  Yard Rtrn":TTxt(3) ="  Tank Feed":TTxt(4) ="  Tank Rtrn"
 TTxt(5)="  Tank Center":TTxt(6) ="    Outside  ":  TTxt(7)="  Hallway  "

if TESTING then: temppin(1)=pYARDRTRN: temppin(5)=pYARDRTRN: temppin(7)=pOUTSIDE: endif ' temperature sensors 1,5,7 not connected
open "com5:115200" as #1
s=""
for i=1 to 4: s=s+"setpin "+str$(ledpin(i))+",dout:": next i: ' print s (SETPIN for outputs)
print #1,s ' +":?"+QT+"!"+QT '  "!" to provide response
pause 100
s="setpin "+str$(pYARDRUNNING)+",din: setpin "+str$(pTANKRUNNING)+",din" ' (SETPIN for inputs)
print #1,s
pause 100
s="dim string s,s2"
print #1,s
pause 100
print #1,"? "+QT+"Starting geopico"+QT
pause 1000
a=input$(255,#1) ' clear response line
print a: print "Starting geopico main loop"
do
 if loc(#1)>0 then
   pause 100
   do while loc(#1) > 0
     line input #1,a
     print ": ",a
     if mid$(a,1,1)="!") then
       print a
       s="": for i=2 to 8: f=val(field$(a,i," ")): s=s+str$(f,2,2)+" ": next i
       for i=9 to 10: j=val(field$(a,i," ")): s=s+str$(j)+" ": next i
       print s
       a=input$(255,#1) ' clear response line
     endif
   loop
 endif
 print #1,"s2="+QT+" "+QT+"+str$(pin("+str$(pYARDRUNNING)+"))+"+QT+" "+QT+"+str$(pin("+str$(pTANKRUNNING)+"))" ' pumps running?
 cmd="s="
 for i=1 to 4: cmd=cmd+"str$(tempr("+str$(temppin(i))+"))+"+QT+" "+QT+"+": next
 print #1,mid$(cmd,1,len(cmd)-5) ' strip trailing "+\" \"+"
 pause 1000
 cmd="s=s+"+QT+" "+QT+"+"
 for i=5 to 7: cmd=cmd+"str$(tempr("+str$(temppin(i))+"))+"+QT+" "+QT+"+": next
 print #1,mid$(cmd,1,len(cmd)-5) ' strip trailing "+\" \"+"
 pause 1000
 print #1,"? "+QT+"! "+QT+"+s+s2"
 pause 500
loop

For each pass through the main loop, the picomite sends and this program extracts 7 temperatures and two input reading which indicate whether the yard pump and tank pump are running in the form "23.75 24.50 22.25 23.75 25.50 24.75 23.25 1 1".

The hard part is up to Paul--to figure out which of the output pins to turn on or off based on these readings.

(But the specs have now changed, and 4 more relays are to be controlled for a total of 7. Looks like we'll be testing a Chinese module with 8 SSRs.)

~
Edited 2022-06-14 01:47 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3013
Posted: 11:44am 23 Jun 2022
Copy link to clipboard 
Print this post

Here's the latest iteration, using Paul_L's PC graphics character display and running on MMBasic for Windows while reading 10 DS18B20 sensors on a Picomite which has no user code--just the MMBasic firmware:



(The "508" in the upper right corner indicates that the program has completed 508 main loops.)

This is essentially throttled by the time it takes to complete a TEMPR START on the Picomite (around 800ms with a resolution of 1/16 degree C), so the MMB4W code only calls on the picomite when the seconds of a time$ call changes. In practice, the temperatures update every second (all 10 sensors), but about once every 8 seconds the time (HH:MM:SS) shown on the second line of the display skips a second.

This is the hardware for test purposes. When I put a finger on a DS18B20, the changes in temperature are reflected in about a second.



I note that there's a spurious zero in the tank center reading. I suspect that's because of a reading of 1000 at some point. I will be checking for readings of 1000 (generally "not connected", but can be spurious) or 85 (probably missing pullup) and logging them.

The code is now 373 lines long--too long to be appropriate for a CODE box, so I've attached the program. The program lacks all of the control code--what to do regarding setting relays as a result of reading these temperatures.

G9.zip
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 1 of 2    
Print this page
© JAQ Software 2024