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 : convert gcbasic to basic
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2135 |
Hi. I'm trying to convert a VL53LOX rangefinder code from gcbasic to mmbasic but not sure of the byte values to mmbasic integers or the i2c. Here is the gcb and my mmb effort but not tested on a non vga pico and ili9341. 'GCBasic version to convert 'set up V53L0X #define HI2C_DATA PORTC.5 #define HI2C_CLOCK PORTC.4 #define HI2C_BAUD_RATE 400 HI2CMode Master ' 'v53l0x software restart HI2CStart HI2CSend(0x52) HI2CSend(0x89) HI2CSend(0x01) HI2CStop wait 200 ms sub getdistance HI2CStart ;Sys V53L0X Range Start HI2CSend(0x52) HI2CSend(0x00) HI2CSend(0x01) HI2CStop HI2CStart ;read distance HI2CSend(0x52) HI2CSend(0x1e) HI2CReStart HI2CSend(0x53) ;set the read flag HI2CReceive(distance_hi) HI2CReceive(distance_lo, NACK) ;read one byte and conclude HI2CStop end sub 'MMBASIC version ' OPTION EXPLICIT OPTION DEFAULT NONE setpin GP0,GP1,I2C I2C OPEN 400,100 dim dist_hi%,dist_lo% 'Dim vl1():vl1(0)=&H89:vl1(1)=&H01 'I2C WRITE &H52,0,2,vl1() i2c write &h52 i2c write &h89 i2c write &h52 i2c write &h01 do get_distance distance=dist_hi+256*dist_lo loop sub get_distance I2C Write &H52 i2c write &h00 i2c write &h52 i2c write &h01 i2c write &h52 i2c write &h1e i2c write &h52 i2c write &h53 i2c read dist_hi i2c read dist_lo end sub |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9139 |
Why not read the manual for the I2C command and then the Appendix that explains I2C before posting? Your "MMBasic" version uses completely incorrect syntax |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2135 |
Hi @matherp, I have read the non vga manual as results would be for lcd for now. I'm not good at serial and i2c. Never converted picaxe to gcb and now gcb to mmbasic. There's a command line that looks simple but for code it HAS? to be arrays 'Dim vl1():vl1(0)=&H89:vl1(1)=&H01 'I2C WRITE &H52,0,2,vl1() not sure of stop bits. HI2CReceive(distance_hi) HI2CReceive(distance_lo, NACK) ;read one byte and conclude HI2CStop I see the mmbasic option to send a stop or keep open after command. My other problem if it worked was the 2 bytes received as distance. I can use a ssd1306 i2c display no problem because there is nothing to do. I don't understand the gcb version.. it just works.. and it's a nice robot rangefinder. Anyone used a picomite for a "robot"? |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9139 |
Dim d$ SetPin gp4,gp5,i2c I2C open 100,1000 Const i2caddr=&H29 I2C write i2caddr,0,2,&H89,&H1 Font 5 Pause 200 CLS Do getdistance Pause 100 Loop ' Sub getdistance I2C write i2caddr,0,2,0,1 I2C write i2caddr,1,1,&H1E I2C read i2caddr,0,2,d$ Text MM.HRes/2,MM.VRes/2, Str$(Str2bin(uint16,d$,BIG),3,0)+"mm",cm 'Print Str2bin(uint16,d$,BIG) End Sub |
||||
RonnS Senior Member Joined: 16/07/2015 Location: GermanyPosts: 120 |
Hello; I have already mentioned that the syntax is very difficult to understand, the manuals lack examples to understand everything Ron |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
This goes for anyone having problems in understanding MMBasic. May I suggest that, as you come across commands that you feel need further examples, then you: a) experiment with them, using the information in the manual (including the appendices where there is a lot of information that people often ignore) until you either understand them or need to ask on the forum. If you are stuck on the basic commands of MMBasic then Geoff's site also has a book called "Getting Started With The Micromite" which, although it's not directly applicable to the PicoMite, still contains very useful information. b) in a *new* thread dedicated to command examples (and nothing else!), you post an example or two that illustrate the command usage. Keep them very, very brief! Even five lines of code is a lot. Geoff may choose to include them in the manual at some point, but they all need to be together in one place. Writing manuals is difficult. I know, I've done a bit of it. You don't precisely know your target audience - some will find it stupidly easy and will wonder why you try to simplify things too much, others will find even the simplest first steps difficult. Geoff's manuals are extremely good and contain an enormous amount of information, but you do need to experiment with some commands as well. He can't talk you through every little nuance of MMBasic. If you give him *useful* feedback it will help, if you just say "there aren't enough worked examples" then he'll have no idea what you actually want (and neither do you if your question is so general) and it won't help. Should you go through every possible combination of TEXT for example? Can you assume that your readers are capable of understanding the MATH commands at all? Personally, I think there may be a case for *someone* (not Geoff, Peter or me) to write a MMBasic book that's designed to be an in-depth addition to the manuals. However these things need time, dedication and a love for the project. A thread dedicated to command examples, as I proposed above, would go a long way towards something like this - possibly even making it unnecessary. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9139 |
The manuals are trivial to understand with respect to I2C IFF you take the trouble to understand I2C first. It is not and cannot ever be the role of a MMBasic manual to explain the intricacies of I2C, SPI, UARTs etc Appendix B of the manual has a great deal of information about using I2C including an example. It took me less than 5 minutes to create the working, tested code above |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1115 |
Hi Stan, Have you ever tried to convert a more complex C64 Basic program to ZX Spectrum? To be able to do this, you have to know the peculiarities of both systems exactly, as soon as it goes beyond standard commands. Same here, you should know both Systens and both Basic Dialects. The minimum is to understand what the source program does and then try to replicate it with your mm-Basic Hardware Cheers Mart!n 'no comment |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
^^^^^ This. :) Converting BASIC to BASIC is relatively easy *but* you MUST know both machines intimately. In this particular case: You are going from a simple microcontroller to a more complex one, from a compiled BASIC to an interpreted one... It's not going to be straightforward and it's not something that mos people on here are terribly interested in either, unfortunately. As Peter says, the I2C section is actually well explained. It's easier than the GCBASIC system. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3816 |
If you read the detailed explanations in the I2C Appendix (Appendix B) all should be clear if you've some basic grasp of I2C. It has examples, too. Stan - please do the same :) John |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2135 |
The vl53lox i2c address is &H52... Const i2caddr=&H29 ?? Text MM.HRes/2,MM.VRes/2, Str$(Str2bin(uint16,d$,BIG),3,0)+"mm",cm -- WOW! Thanks for your time. It is not mmbasic's place to explain i2c or spi but do you have to understand it to use it in that I just wired i2c and spi displays and they work? Converting basics was never fun, bbc to locomotive to spectrum, I recently looked up the "Snake" game in basic. Which basic would be easiest to convert to mmbasic thoughts. The manual has all the info for i2c but it's different to gcb, I'll have to understand it for other i2c devices that give info. Studying bitbang i2c is interesting but the hardware i2c syntax I must figure. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
If I were you I'd stick to converting MMBasic to MMBasic... ;) It's probably easier to start from scratch and produce something that looks like what you want rather than try to convert from a different platform. The exception is probably text-based stuff where graphics and sound don't cause too many problems. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4256 |
Hi EEjit, The miracle of the 52 and 29 is easily explained. The first byte send after I2C start is the "chip address+ R/W bit". This is build up as follows bit 7...6...5...4...3...2...1...0 ... A6..A5..A4..A3..A2..A1..A0..R/W There is a 7 bit chip address (A6...A0) and a single R/W bit MMBasic follows the I2C standard in using the 7 bit address ... A6..A5..A4..A3..A2..A1..A0. ....0...1...0...1...0...0...1 = 0x29 (&h29) In MMBasic the R/W is part of the I2C command (I2C READ and I2C WRITE) Great Cow Basic uses the 8 bit address (includes the R/W bit in the address) ... A6..A5..A4..A3..A2..A1..A0..R/W ....0...1...0...1...0...0...1...0 = 0x52 (&h52) That is all about the mysterie.... nothing fancy... Volhout PicomiteVGA PETSCII ROBOTS |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2135 |
Thanks @Volhout. The manual says if the address is out of a certain range it's 8 bit. gcb read is &H53. that the extra bit? Wire it up later and see. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
Read the I2C spec. Then discover that not all I2C stuff complies with it so you can't always trust it. Some things will not work together because their addresses are screwed up! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4256 |
Yves Read =1 Wrikte=0 For the I2C R\W bit Volhout PicomiteVGA PETSCII ROBOTS |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2135 |
Your code works on ili9341 lcd. Thanks. Seems you have the vl53lox. I like it more than ultrasonic range finders for robot avoid obstacles. Your code as an example in the manual for others maybe. I added a space for the display or it left chars on the display Text MM.HRes/2,MM.VRes/2, " "+Str$(Str2bin(uint16,d$,BIG),3,0)+"mm",cm |
||||
Print this page |