![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Rob, I now have the outside unit sending correctly and the inside unit ready to recieve properly I had several errors in the formatting of the outdoor information, all corrected now And "SOMEHOW" the weather actually prints on the indoor unit properly once I place the Humidity reading as the last item of weather to be transmitted before the * symbol No idea why it works there, but if I place the humidity reading elsewhere it fails to transmit Now I have to figure out once again how to make sure the recieve data is only processed once the reciever had correctly determined that the first 3 characters recieved are STX AND the last characters are *<CR?<LF> Ideally I'd like to not have the CR and LF transmitted, but I need some way to do this AND make the recieve know that once it recieves those characters and processes them to clear the recieve buffer ready for the next string of characters. |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4036 |
With PRINT use ; Also, to suppress tab chars, avoid , Instead use ; I expect this is documented... John |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2429 |
if you retain the <cr><lf> at the end, the interrupt driven code i posted earlier should now work - it depends upon the <cr><lf> to be able to split up the stream of data into individual lines. cheers, rob :-) |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Any ideas why this doesn't work? DIM STRING B$ DIM AS STRING N [320] N = GetFieldArray(B$) Error: Expected a number |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4036 |
If it's valid syntax, you've said N is a string. Then you've tried to set it to a non-string, as returned by Get...() Unless that Get... function despite its name does return a string? Its name suggests it returns an array. I think I would have expected the error to be Expected a string John |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
B$ is an array but I can't define N as an array - I can only define it as intiger, string or float |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4036 |
What does that Get function actually return? Does it return an array? If it does, there must be syntax to declare something holds an array. John |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
B$ is whats received by the com port At the moment the com port is receiving Searching For GPS signal once the gps locks it then gets weather data which is a series of numbers and letters in strings |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
The function returns the number of fields that are available. Returning an array is impossible in MMBasic so the array is a global one. Always check the returned value before doing further processing to make sure you have all the fields you need. [code] N = GetFieldArray(B$) IF N = 13 THEN 'change this number to the exact number of fields you expect 'All fields accounted for ELSE 'Not all fields available ENDIF [/code] Microblocks. Build with logic. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Jean, I understood that However at the moment I'm using OPTION EXPLICIT and when I do that it wants me to define N if I remove OPTION EXPLICIT the code works perfectly, I'm just waondering is there any way to define N |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4036 |
B$ doesn't seem relevant at the moment but why don't you declare N as a number (integer or whatever)? You've told MMBasic that it's a string... John |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
You need to define it with: [code] DIM INTEGER N [/code] Microblocks. Build with logic. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I tried that Jean once I got home but it then throws up the error EXPECTED A NUMBER |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Flash: 54K (53%) Program (1197 lines) 13K (12%) 5 Embedded C Routines 33K (35%) Free RAM: 88K (83%) 101 Variables 0K ( 0%) General 17K (17%) Free [59] Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2)) Error: Not enough memory Any idea why it's saying this? I can see it's not enough memory and I'm "assuming" it's the Ram under General but not sure Also I've no idea which bits of the program writes to the "General" area, is it possible to change some of the 17K to the 0K so there is more free? |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3282 |
The RAM is managed out of a general pool so if something requires "General RAM" it will be automatically created and the free RAM decreased. So that is not the cause. There are many things that can cause you to run out of RAM while the program is running but not show up when the program is halted and you run the MEMORY command. These include complex expressions (especially using strings), many nested subroutines and many local variables (especially string variables and arrays). Probably the quickest way to get back some RAM is to define string arrays with the LENGTH qualifier that is less than 255 (which is the default maximum string length). Geoff Geoff Graham - http://geoffg.net |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9589 |
Geoff is spot-on with that last comment. In my latest multi-page GUI project, I have lots and lots of strings, and at the outset, I just left them with no length spec, but as the program got bigger and bigger, I decided one of the steps would be for me to decide the length of those strings. When I did that, I shaved 8K off the used memory!!!!! That was all used by the strings being set to a default length of 255 bytes, when most of them were only 20 bytes or less. All the unused space in the string, is still reserved in memory - in case you DO use it later. So, for a five minute reshuffle of the strings, and defining the lengths of said strings, I saved 8K of RAM just like that. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks ~I've tried assigning lengths but so far it's still 0% left, but I'll keep working on it ![]() |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1982 |
I see the number of views for this post have exceeded Gizmos Guidelines post, over 25,000 and 350 odd replies over 30 pages. That's not bad for a FEW questions. ![]() ![]() ![]() ![]() I have followed this post and you have come a long way and what you built is a credit to you well done. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
That is what I love about this Forum (one of the best I have ever taken part in - correction; it is the best!). Hats off to Lewis, and to everyone that has helped him achieve what he has. That is the power of this forum. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Resurrecting this post as it's the most suitable one (I think) rather than make a new topic I'm writing pictures to my 7" TFT display using Matherp's excellent C functions as described HERE I'm trying to update part of the picture with a weather icon, the icon size is 252 width and 213 height My code to display the icon is [code] DisplayPicture ICON$,280,260 'Weather icon[/code] This works perfectly apart from OCCASIONALLY I get the error [quote][674][674] Local integer buff(511) Error: Not enough memory[/quote] When I press enter on the console I then get [quote]> DisplayPicture ICON$,280,260 'Weather icon [274] Local I, S$ length 80 Error: I already declared[/quote] This SUB is where the error occurs [code]Sub DisplayPicture(PIC$, StartX%, StartY%) LOCAL Buffer$,addbuffer$ length 3 LOCAL Result%=-1 LOCAL NumBytes%,a%,i% local integer buff(511) '******THIS IS WHERE THE ERROR OCCURS******* SDcard fileopen,PIC$ 'Read the first 128 bytes Buffer$=STRING$(128," ") SDcard readfile,buffer$,0,len(buffer$),NumBytes% a%=instr(buffer$,chr$(10)) ' look for the first CR if left$(buffer$,a%-1)="P6" then buffer$=right$(buffer$,len(buffer$)-a%) if left$(buffer$,1)="#" then a%=instr(buffer$,chr$(10)) ' look for the second CR buffer$=right$(buffer$,len(buffer$)-a%) endif a%=instr(buffer$,chr$(32)) ' look for the space between dimensions local width%=val(left$(buffer$,a%-1)) buffer$=right$(buffer$,len(buffer$)-a%) a%=instr(buffer$,chr$(10)) ' look for the third CR LOCAL height%=val(left$(buffer$,a%-1)) buffer$=right$(buffer$,len(buffer$)-a%) a%=instr(buffer$,chr$(10)) ' look for the fourth CR buffer$=right$(buffer$,len(buffer$)-a%) a%=len(buffer$) mod 3 addBuffer$=STRING$(3-a%," ") ' we need to make sure we have a number of bytes divisible by three in the buffer SDcard readfile,addbuffer$,-1,len(addbuffer$),NumBytes% buffer$=buffer$+addbuffer$ if (StartX%+width%>MM.HRES) OR (StartY%+height%>MM.VRES) then print pic$," too big", width%," x",height% else defineregionSSD StartX%, StartY%, width%, height% DisplayBufferSSD Buffer$ do SDcard readfile,buff(),-1,4095,NumBytes% if numbytes%<>0 then DisplayBufferSSD Buff(),numbytes% loop while NumBytes%<>0 endif else Print "Invalid File Format" endif end sub[/code] Any idea how to overcome this error? My first thought is to clear the buffer before I try and display the picture, but no idea how you would do that or if that is the problem |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |