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 : uMitePi
Author | Message | ||||
MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Just a quick post , after playing with Annex for quite some time I had forgotten how good mmbasic was and have used it for this latest project. Basically it is a Co processor for use with a raspberry pi , provides power control , shutdown / Restart for the pi , standby power is less than 10mA (could be uA if sleep was also employed) , pwm fan control. Communication with the Pi is via serial and Node RED provides the interface. This also gives lots of scope to write routines in basic instead of scripts or Python on the Pi. Codenquilts |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5645 |
That's very neat, MikeO. :) And a nice bit of shoehorn work to get everything in the box. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3422 |
Hi MikeO, Nice IO board, solves some functions lacking in the pi. Missing one thing though. The DS3132 RTC..... And as Mixtel said....quit a squeeze to put it all in the small box... Regards, Volhout PicomiteVGA PETSCII ROBOTS |
||||
MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Its designed to go together, does it really need a RTC when its connected to the internet? Codenquilts |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5645 |
I like that case, it's tiny! Is it 3D printed? Nope - internet time is close enough for me. lol Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Plasmamac Guru Joined: 31/01/2019 Location: GermanyPosts: 500 |
Work together! Great Plasma |
||||
MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Yes 3D printed, designed to take a Pi4 plus DC to DC power supply . Codenquilts |
||||
Quazee137 Guru Joined: 07/08/2016 Location: United StatesPosts: 514 |
Sweet. Looking at doing something similar to have sub I/O and ADC running in the background to the RPi main code. With small I2C display showing the 170's I/O states and the ADC's real time values. |
||||
MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
@Quazee137 Sounds like a excellent marriage! are you familiar with node-red for use on the Pi it is perfect for stitching the communications together. Mike Codenquilts |
||||
MikeO Senior Member Joined: 11/09/2011 Location: AustraliaPosts: 275 |
V2 PCB now complete. Makes all unused mx170 pins available and adds a RTC connector. This board makes all ADC pins available to the Raspberry Pi (via Node red suggested). New enclosure Long press of Button starts shutdown sequence, Pi Red power Led will go out when shutdown complete and RPI will be powered down. Standby current is ~ 6mA. Longpress again will restart the Raspberry Pi. Micromite code ' ' ***** uMitePi ***** ' ******************************* ' Filename: uMitePi.bas ' Date: Aug 2021 ' File Version: ' Written by: M.Ogden ' Function: uMitePi "Hat" controller for Raspberry Pi ' Device: micromite mx170 ' Last Revision: ' Initial v0.6 ' MMBasic Ver 5.05.04 ,raspberry Pi running Node Red 'adds some LED indicators, Fan control and Shutdown signaling to RPI Zero-Pi4 'plus mmBasic user code 'V2 PCB adds access to all unused MX170 IO pins, adds RTC connector 'V0.7 'release .v0.8 'add I/O changes for version 2 PCB ' ******************************* 'IO Pin List 'D1 Led (Button) 'D5 Button 'D6 Sig pi-running 'D8 Out shutdown-Pi 'D9 Out pi-power 'Pin 4 Fan Ctrl 'Pin 6 Fan Ctrl on v2 pcb option explicit dim integer D1=10,D5=16,D8=15,D6=18,D9=17 'mx170 IO pins V1 pcb 'dim integer D1=10,D5=16,D8=15,D6=9,D9=14 'mx170 IO pins V2 pcb 'Variables dim q$=chr$(34),J$="&",temp$="",lastline$,newline$ dim integer start=0,lotemp=45,hitemp=60,midtemp=50 'set lfan=0 if no low fan req'd dim integer lfan=0,mfan=60,hfan=75 'fan pwm speeds dim integer secs=0,flag=0 'periods dim integer uptime=0 'time up in seconds dim integer upspower=0 'ups power on dim integer upstime=0 'time on battery dim integer nolowfan=1 'if no low fan needed dim Integer userprocessflag 'user variables dim integer pi.temp=50 'LEDs & Outputs setpin d1, dout 'Led 1 setpin D8, dout 'pi-shutdown setpin d9, dout 'pi-power pin(d9)=0 'take control of power supply On pin(d8)=1 'pi-shutdown not-shutdown pin(d1)=0 'Led(button) off 'Inputs setpin D5, intl,buttonpress,PULLUP 'S2 Button setpin D6, din 'pi running 'Run Fan High 'for v2 pcb change format to PWM 1,,,100,hfan etc PWM 1,100,hfan 'Run fan high pause 3000 'run fan PWM 1,100,lfan 'Run fan low '********************************************************************************* 'initialise 'serial Com1 open "com1:38400,,rec1" as #5 settick 1000, T1,1 '1 sec timer 'settick 60000,runonce,2 'main loop processing do if pin(d6)=1 then led1 d1,25 'Pi & Co-Processor running else if uptime mod 15 = 0 then led1 d1,25 'Co-Processor only running , flash every 15secs endif Watchdog 20000 ' set the WDT at 20 secs 'process data from RPI if userprocessflag=1 then UserProcess UserProcessFlag=0 end if 'run periodic tasks if uptime mod 30 = 0 then fanctrl pause 1000 'restrict loop to 1 second minimum loop 'core routines sub runonce settick 0,0,2 'disable timer end sub 'Heartbeat sub T1 uptime=uptime+1 end sub 'Led1 pulse p=pin sub led1(p,d) if d=0 then d=50 pulse p,d end sub 'Led2 toggle sub led2(p) if pin(p)=1 then pin(p)=0 else pin(p)=1 end if end sub 'Led3 set sub led3(p,hl) pin(p)=hl end sub sub fanctrl 'for v2 pcb change format to PWM 1,,,100,hfan etc if pi.temp=0 then then exit sub 'exit if no pi.temp if pi.temp>hitemp then PWM 1,100,hfan endif if pi.temp<midtemp then PWM 1,100,mfan endif if pi.temp<lotemp and nolowfan=0 then PWM 1,100,lfan endif end sub Sub rec1 'reads bytes from comms buffer , data terminated by CR will output a NewLine$ and set the UserFlag 'also checks for block data transmissions , start with SOH (Dec 1) local a$ local integer p,l 'print "Buffer:";loc(5) a$=Input$(20,#5) 'user supplied processing routine 'print a$; on error skip lastline$=lastline$ + a$ 'add to data packet packet: l=len(lastline$) p=instr(lastline$,chr$(13)) if p>0 then 'CR found so process Newline$=left$(Lastline$,p-1) if l>p+1 then lastline$=mid$(lastline$,p+1) 'save the rest of the line else lastline$="" end if UserProcessFlag=1 'set process data flag 'print "newline:"+newline$ endif End Sub 'process json strings from RPI Sub userprocess 'print newline$ pi.temp=val(jsonvalue$(newline$,"pi-temp")) print pi.temp end sub sub buttonpress pause 50 'debounce if pin(d5)=0 then presstime end sub sub presstime pause 1000 if pin(d5)=0 then if pin(d6)=1 then 'is pi running print "Shutdown" led3 d1,1 pin(d8)=0 'shutdown RPI pause 1000 pin(d8)=1 pause 10000' Wait for pi to shutdown cpu 5 led3 d1,0 print "shutdown supply" pin(d9)=1 'shutdown power supply else print "Restart" cpu 48 uptime=0 pin(d9)=0 'power supply on end if else print "shortpress" end if end sub function jsonValue$(Jstring$,jParam$) local a,c,s$,d$,b,json$ json$=jstring$ s$=":" d$="," 'locate parameter a=instr(JSON$,jparam$) 'print "A is:";a json$=replace$(json$,chr$(34),"") 'strip quotes json$=replace$(json$,"}",",") 'replace closing curly brackets with comma if a>0 then 'retrieve value 'look for separator : b=instr(a,json$,s$) if b>0 then 'look for deliminator c=instr(b,JSON$,d$) if c>0 then jsonvalue$=mid$(JSON$,b+1,c-(b+1)) endif endif endif end function 'replaceString$(string$, replaceWhat$, replaceWith$) FUNCTION REPLACE$(R$, a$, b$) local integer i,j,c,d d=1 REPLACE$=R$ i = LEN(a$) : j = LEN(b$) do while INSTR(d,REPLACE$, a$) > 0 c = INSTR(d,REPLACE$, a$) REPLACE$ = LEFT$(REPLACE$, c-1) + b$ + MID$(REPLACE$, c+i) d = c+j loop END FUNCTION '**************** End Core routines and functions ******** 'user subs and tasks '*** User subs and other code here *** 'End user subs and tasks Codenquilts |
||||
Print this page |