![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
Paul_L Guru ![]() Joined: 03/03/2016 Location: United StatesPosts: 769 |
Hi Lou, The received data string is 7.23,04d,10.19,997,5.1,130,62,8.35,11,96,10000,broken clouds,Clouds,987.64,1.72,7.11,8.39,Rain,Wed Mar 14 14:55:47 2018 ,* It looks to me like this line tim2$ = mid$(tim$,12,8) 'Curent time ready to send to Micromite or RTC sets tim2$ to ".19,997," But the syntax needed is TIME$="HH:MM:SS" or "HH:MM" or "HH" and ".19,997" doesn't fit. I'm not sure how the data string above is formatted but if the hour is "10" and the minute is "19" try this. tim2$ = mid$(tim$,10,2) + ":" + mid$(tim$,13,2) which gives you "10:19" If the hour is "04", the minute is "10" and the seconds are "19" then try this. tim2$ = mid$(tim$,6,2) + ":" + mid$(tim$,10,2) + ":" + mid$(tim$,13,2) which gives you "04:10:19" Paul in NY |
||||
Paul_L Guru ![]() Joined: 03/03/2016 Location: United StatesPosts: 769 |
Hi Grogs, you type faster than I do! Paul. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6221 |
tim$ = FieldArray$(18) extracts the 18th field from the data. 19th if you start from zero. Is it always the 18th field that has the time? In the example field 18 is "Wed Mar 14 14:55:47" Is it always the same size with 2 digits for the date? PRINT tim$ and tim2$ for debug purposes. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks everyone I've made it easier Now the time comes in on the 18th field and is in the format hour:min:sec So it can be directly passed to the Micromite and it works ![]() The question for today is I have the ESP8266 transmitting the weather data including the time once every 15 seconds HOW can I get the Micromite to ONLY update the time once an hour? Preferably at the top of each hour say when Min = 00 and Secs = 00 The problem I have is I have no idea and cannot control the exact time the ESP sends the data and it sends the data up to 4 times a minute and at the moment is updating the Micromite each time it updates. EDIT: This is the relevant section of code for the MM [code] tt1$ = FieldArray$(18) 'hour:min:sec dow1$ = FieldArray$(19) 'Day of week (example) Thu dm1$ = FieldArray$(20) 'day:month (example) in 15:03 Year$ = FieldArray$(21) 'Year (example) 2018 Month$ = right$(dm1$,3) 'Month Day$ = dow1$ 'Day of week [/code] |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6221 |
The variable oldHour$ will be "", so different to the real hour the first time the program is run. After the first run, it will only be different at the start of a new hour so the time is updated once per hour. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you so much, I've spent hours trying to work out a way to do that and you did it in minutes |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
deleted * Edited 2020-07-24 06:26 by lew247 |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Can anyone see why this isn't working please? It should run on any MM It's meant to print a triangle representing the wind direction of 240deg It's giving this result CLS Dim As integer z(1000) Dim As string q q=Chr$(34) 'set up pointer const pivot_x=501 'specify where the centre of the dial is located const pivot_y=387 const radius=73 'specify the radius of the compass dial const side_length=13 'specify the size of the equilateral triangle pointer 'define the points that make up the triangle relative to a pivot at 0,0 const x0=0 const x1=-side_length/2 const x2=side_length/2 const y0=-radius const y1=-radius+side_length*cos(rad(30)) const y2=y1 dim integer angle, X, Y, W, H dim integer xx0,xx1,xx2,yy0,yy1,yy2 'variables holding the vertices of the triangle relative to its pivot dim integer pxx0,pxx1,pxx2,pyy0,pyy1,pyy2 'variables holding the absolute vertices of the triangle ' angle = 240 'wind direction 'load image "image.bmp" ,400,280 'load compass picture do print angle angle = val(angle1$) print time$ " time$" moveto(angle) 'Move Compass to the current wind direction pause 1000 loop 'Subroutines to make the compass pointer move to the correct position sub moveto(angle as integer) local integer xs=x, ys=y, ws=w, hs=h rotatetriangle(angle,0,radius,x0,y0,x1,y1,x2,y2) pxx0=xx0+pivot_x pyy0=yy0+pivot_y-radius pxx1=xx1+pivot_x pyy1=yy1+pivot_y-radius pxx2=xx2+pivot_x pyy2=yy2+pivot_y-radius getlimits(x, y, w, h) ' blit write and blit close first time in will error so skip ON ERROR SKIP 2 ' BLIT WRITE #1, xs, ys, ws, hs 'restore the save background **** bypassed as the triangle isn't working at all*** ' blit close #1 ' blit read #1, x, y, w, h triangle pxx0, pyy0, pxx1, pyy1, pxx2, pyy2, rgb(RED), rgb(BLUE) 'COLOUR OF TRIANGLE end sub sub getlimits(x as integer, y as integer, w as integer, h as integer) Local integer i,max_x=0,min_x=MM.HRES,max_y=0,min_y=MM.VRES if(pxx0(i)>max_x)then max_x=pxx0(i) if(pxx1(i)>max_x)then max_x=pxx1(i) if(pxx2(i)>max_x)then max_x=pxx2(i) if(pxx0(i)<min_x)then min_x=pxx0(i) if(pxx1(i)<min_x)then min_x=pxx1(i) if(pxx2(i)<min_x)then min_x=pxx2(i) if(pyy0(i)>max_y)then max_y=pyy0(i) if(pyy1(i)>max_y)then max_y=pyy1(i) if(pyy2(i)>max_y)then max_y=pyy2(i) if(pyy0(i)<min_y)then min_y=pyy0(i) if(pyy1(i)<min_y)then min_y=pyy1(i) if(pyy2(i)<min_y)then min_y=pyy2(i) x=min_x y=min_y w=max_x-min_x+2 h=max_y-min_y+2 end sub ' ' Simple trig to rotate the vertices of a triangle ' specified as x0,y0,x1,y1,x2,x2 relative to coordinate 0,0 ' by the angle specified ' and then translate them about the supplied real centre x,y ' the calculated coordinates are then placed into element n of a set of coordinate arrays ' sub rotatetriangle(angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer) local float sine=sin(rad(angle)),cosine=cos(rad(angle)) local integer x0a,y0a,x1a,y1a,x2a,y2a x0a= x0*cosine - y0 * sine + x y0a= y0*cosine + x0 * sine + y x1a= x1*cosine - y1 * sine + x y1a= y1*cosine + x1 * sine + y x2a= x2*cosine - y2 * sine + x y2a= y2*cosine + x2 * sine + y xx0=x0a yy0=y0a xx1=x1a yy1=y1a xx2=x2a yy2=y2a end sub '*******End of compss routine ******************************* I just cannot figure out why though I'm using it on a pi-cromite |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
I think it's because you set your pxx0 (and similar variables) as integers, not arrays, so when you try to index into it (pxx0(i)), it can't because it's not an array |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's a bug on the Pi-cromite I downgraded to Stretch today, reset everything and used 2019-05-05_211935_mmbasic.zip and it works perfectly Still can't get touch to work though, maybe I do have 2 duff SSD1963's |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10071 |
No it isn't. Geoff tightened up error checking and I included it. You are using declaring pxx0 as a scalar but then using it as an array. This creates the error. Fix function getlimits and it will work |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Function getlimits is exactly identical to the one you gave me originally (and the whole code for drawing the triangle) other than the length of the sides I haven't changed function getlimits at all Multiline IF ELSE was throwing errors as well, that aren't there in Stretch and the older one, which is why I tried it to see if it was me or an issue I don't mind using Stretch, it's only a weather display after all, nothing serious Edited 2020-07-25 04:15 by lew247 |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3999 |
getlimits doesn't do anything useful with i so you can probably remove it and also remove all the (i) references. e.g. if(pxx0(i)>max_x)then max_x=pxx0(i) becomes if(pxx0>max_x)then max_x=pxx0 John |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Interesting it's working well ![]() I'll reinstall Buster over the weekend and try that, because it did load the screen a lot quicker Edited 2020-07-25 05:54 by lew247 |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Definitely something with Pi-cromite it works fine on Stretch, I just reinstalled the latest raspbian Pi OS, aparently PI OS is just Buster renamed and it's definitely not working |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10071 |
The BASIC code is WRONG. Old versions of the Picromite code work because they didn't check syntax properly. Fix the Basic code. sub getlimits(x as integer, y as integer, w as integer, h as integer) Local integer i,max_x=0,min_x=MM.HRES,max_y=0,min_y=MM.VRES if(pxx0>max_x)then max_x=pxx0 if(pxx1>max_x)then max_x=pxx1 if(pxx2>max_x)then max_x=pxx2 if(pxx0<min_x)then min_x=pxx0 if(pxx1<min_x)then min_x=pxx1 if(pxx2<min_x)then min_x=pxx2 if(pyy0>max_y)then max_y=pyy0 if(pyy1>max_y)then max_y=pyy1 if(pyy2>max_y)then max_y=pyy2 if(pyy0<min_y)then min_y=pyy0 if(pyy1<min_y)then min_y=pyy1 if(pyy2<min_y)then min_y=pyy2 x=min_x y=min_y w=max_x-min_x+2 h=max_y-min_y+2 end sub |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I thought I had done that yesterday and to make certain I copied and pasted and it still doesn't draw the triangle I then wiped the SD card, installed Stretch, earlier Pi-Cromite and it works fine I then wiped the SD card again, installed the last version of Buster (2020-02-13-raspbian-buster.zip) Used the latest Pi-cromite and it doesn't draw the triangles it doesn't crash, it just doesn't draw the actual triangle on the display |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I've reinstalled the very first version of BUSTER, and the first and last versions of MM for Buster I could find on here and none of them are drawing the triangle on the screen If I use any version of Stretch,and MM for Stretch it's working and drawing the triangle perfectly using the exact same code - the modified getlimits The only issue with Stretch is it's very slow drawing boxes on the screen which is why I would have loved to have had Buster working. but c'est la vie Simple code that loads a compass and draws a triangle pointer (set for 7 inch SSD1963) CLS Dim As integer z(1000) Dim As string q q=Chr$(34) 'set up pointer const pivot_x=501 'specify where the centre of the dial is located const pivot_y=387 const radius=73 'specify the radius of the compass dial const side_length=13 'specify the size of the equilateral triangle pointer 'define the points that make up the triangle relative to a pivot at 0,0 const x0=0 const x1=-side_length/2 const x2=side_length/2 const y0=-radius const y1=-radius+side_length*cos(rad(30)) const y2=y1 dim integer angle, X, Y, W, H dim integer xx0,xx1,xx2,yy0,yy1,yy2 'variables holding the vertices of the triangle relative to its pivot dim integer pxx0,pxx1,pxx2,pyy0,pyy1,pyy2 'variables holding the absolute vertices of the triangle ' angle = 174 'wind direction load image "image.bmp" ,400,280 'load compass picture do print angle print time$ " time$" moveto(angle) 'Move Compass to the current wind direction pause 1000 loop 'Subroutines to make the compass pointer move to the correct position sub moveto(angle as integer) local integer xs=x, ys=y, ws=w, hs=h rotatetriangle(angle,0,radius,x0,y0,x1,y1,x2,y2) pxx0=xx0+pivot_x pyy0=yy0+pivot_y-radius pxx1=xx1+pivot_x pyy1=yy1+pivot_y-radius pxx2=xx2+pivot_x pyy2=yy2+pivot_y-radius getlimits(x, y, w, h) ' blit write and blit close first time in will error so skip ON ERROR SKIP 2 ' BLIT WRITE #1, xs, ys, ws, hs 'restore the save background **** bypassed as the triangle isn't working at all*** ' blit close #1 ' blit read #1, x, y, w, h triangle pxx0, pyy0, pxx1, pyy1, pxx2, pyy2, rgb(RED), rgb(BLUE) 'COLOUR OF TRIANGLE end sub sub getlimits(x as integer, y as integer, w as integer, h as integer) Local integer i,max_x=0,min_x=MM.HRES,max_y=0,min_y=MM.VRES if(pxx0>max_x)then max_x=pxx0 if(pxx1>max_x)then max_x=pxx1 if(pxx2>max_x)then max_x=pxx2 if(pxx0<min_x)then min_x=pxx0 if(pxx1<min_x)then min_x=pxx1 if(pxx2<min_x)then min_x=pxx2 if(pyy0>max_y)then max_y=pyy0 if(pyy1>max_y)then max_y=pyy1 if(pyy2>max_y)then max_y=pyy2 if(pyy0<min_y)then min_y=pyy0 if(pyy1<min_y)then min_y=pyy1 if(pyy2<min_y)then min_y=pyy2 x=min_x y=min_y w=max_x-min_x+2 h=max_y-min_y+2 end sub ' ' Simple trig to rotate the vertices of a triangle ' specified as x0,y0,x1,y1,x2,x2 relative to coordinate 0,0 ' by the angle specified ' and then translate them about the supplied real centre x,y ' the calculated coordinates are then placed into element n of a set of coordinate arrays ' sub rotatetriangle(angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer) local float sine=sin(rad(angle)),cosine=cos(rad(angle)) local integer x0a,y0a,x1a,y1a,x2a,y2a x0a= x0*cosine - y0 * sine + x y0a= y0*cosine + x0 * sine + y x1a= x1*cosine - y1 * sine + x y1a= y1*cosine + x1 * sine + y x2a= x2*cosine - y2 * sine + x y2a= y2*cosine + x2 * sine + y xx0=x0a yy0=y0a xx1=x1a yy1=y1a xx2=x2a yy2=y2a end sub '*******End of compss routine ******************************* Edited 2020-07-26 06:02 by lew247 |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4860 |
First of all, I don't have a picromite running at the moment, so I cannot test. But from browsing your code, there seems something not logical. You commented out the blit functions. The preceeding ON ERROR SKIP 2 will skip the "END SUB" now. Result: you won't see the error, but also the program may also crash. Maybe you could also comment out the ON ERROR SKIP line. Volhout PicomiteVGA PETSCII ROBOTS |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I give up totally I'm in my 60's, had brain surgery so my memory is cr@p, everytime I leave MM for a few weeks and come back to it. I've basically got to try and learn all from scratch again Yesterday I spent the whole day going through every version of Stretch and Buster I could and also trying every version of pi-cromite The triangles definitely do not work on the later versions of pi-cromite, I thought it was just me until I saw a post from someone saying triangle was not working as well What made it really hard is every version of Pi-cromite is called mmbasic It would have help tremendously is it had the version number as well in the filename It really would help if there was one post dedicated to posting new versions of Pi-cromite along with issues people found with that version, that way it would save having the search the whole forum to try and find versions I'm sure that would be the case with other versions of MM as well, such as DOS etc That way people such as idiots like me can see instantly which version they are testing Yes I know you can check once it's running but that doesn't help when you're trying to find the right version to install in the first place After spending all day and most of the night I just give up, it's definitely not working Yes Volhout you were right, I had an error in the code, I thought I had changed it before I uploaded it The correct code is below and it should work on every version of MM that has a display attached from my "VERY" limited knowledge it seems to me from running the program that the issue "could be" that the blit read and write figures and not correct? I thought that Blit write should have the same values as the previous Blit read?? It doesn't the pic below shows the angle of the pointer and underneath it the values of Blit write and underneath Blit read This was running Buster and the latest version of pi-cromite I could find V5.05.04 CLS 'set up pointer const pivot_x=mm.hres/2'specify where the centre of the dial is located const pivot_y=mm.vres/2 'specify where the centre of the dial is located const radius=73 'specify the radius of the compass dial const side_length=13 'specify the size of the equilateral triangle pointer 'define the points that make up the triangle relative to a pivot at 0,0 const x0=0 const x1=-side_length/2 const x2=side_length/2 const y0=-radius const y1=-radius+side_length*cos(rad(30)) const y2=y1 dim integer angle, X, Y, W, H dim integer xx0,xx1,xx2,yy0,yy1,yy2 'variables holding the vertices of the triangle relative to its pivot dim integer pxx0,pxx1,pxx2,pyy0,pyy1,pyy2 'variables holding the absolute vertices of the triangle ' angle = 1 'wind direction 'load image "image.bmp" ,400,280 'load compass picture do print angle 'so we can see the current angle pause 500 angle = angle+1 ' mose triangle one degree at a time until it does a whole 360° circle if angle = 361 then angle = 1 text mm.hres/3, mm.vres/3, "test to check display works",CM,2,1,rgb(white),-1 '"checking display works" moveto(angle) 'Move Compass to the current wind direction print xs, ys, ws, hs ' so we can see the values print x, y, w, h ' so we can see the values loop 'Subroutines to make the compass pointer move to the correct position sub moveto(angle as integer) local integer xs=x, ys=y, ws=w, hs=h rotatetriangle(angle,0,radius,x0,y0,x1,y1,x2,y2) pxx0=xx0+pivot_x pyy0=yy0+pivot_y-radius pxx1=xx1+pivot_x pyy1=yy1+pivot_y-radius pxx2=xx2+pivot_x pyy2=yy2+pivot_y-radius getlimits(x, y, w, h) ' blit write and blit close first time in will error so skip ON ERROR SKIP 2 BLIT WRITE #1, xs, ys, ws, hs 'restore the save background blit close #1 blit read #1, x, y, w, h triangle pxx0, pyy0, pxx1, pyy1, pxx2, pyy2, rgb(215,255,119), rgb(215,255,119) 'COLOUR OF TRIANGLE end sub sub getlimits(x as integer, y as integer, w as integer, h as integer) Local integer max_x=0,min_x=MM.HRES,max_y=0,min_y=MM.VRES if(pxx0>max_x)then max_x=pxx0 if(pxx1>max_x)then max_x=pxx1 if(pxx2>max_x)then max_x=pxx2 if(pxx0<min_x)then min_x=pxx0 if(pxx1<min_x)then min_x=pxx1 if(pxx2<min_x)then min_x=pxx2 if(pyy0>max_y)then max_y=pyy0 if(pyy1>max_y)then max_y=pyy1 if(pyy2>max_y)then max_y=pyy2 if(pyy0<min_y)then min_y=pyy0 if(pyy1<min_y)then min_y=pyy1 if(pyy2<min_y)then min_y=pyy2 x=min_x y=min_y w=max_x-min_x+2 h=max_y-min_y+2 end sub ' ' Simple trig to rotate the vertices of a triangle ' specified as x0,y0,x1,y1,x2,x2 relative to coordinate 0,0 ' by the angle specified ' and then translate them about the supplied real centre x,y ' the calculated coordinates are then placed into element n of a set of coordinate arrays ' sub rotatetriangle(angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer) local float sine=sin(rad(angle)),cosine=cos(rad(angle)) local integer x0a,y0a,x1a,y1a,x2a,y2a x0a= x0*cosine - y0 * sine + x y0a= y0*cosine + x0 * sine + y x1a= x1*cosine - y1 * sine + x y1a= y1*cosine + x1 * sine + y x2a= x2*cosine - y2 * sine + x y2a= y2*cosine + x2 * sine + y xx0=x0a yy0=y0a xx1=x1a yy1=y1a xx2=x2a yy2=y2a end sub '*******End of compss routine ******************************* |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |