![]() |
Forum Index : Microcontroller and PC projects : Distance cfunction
Author | Message | ||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
I am new to micromite, so excuse me if I ask for help with the obvious. I programmed the mmbasic 5.04.08 in an mx170, and that works. Programmed a microbridge, using it to communicate through usb. Using Putty on linux to program the micromite. So far all good. Made some programs, and am learning on the way. But my problem starts when I copy the distance cfunction and try to use it. I attach a sensor to pin 10 and 14, although that is not making any difference. D=distance(10,14) Then the micromite locks up. Only way to revive it is to repower. Waited minutes, but nothing. After repower all is sane. Is the cfunction in the distance.pdf correct? Thanks in advance for any help. Volhout PicomiteVGA PETSCII ROBOTS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Hi Volhout, Just a couple of things to try. The manual says the I/O pins need to be 5V pins. Even though TRIG is an 'output' from the MM to the Distance module, Pin 10 is not a 5V pin. So first I would move this to a Pin that is 5V (see manual for possibilities - 15,16,17,18 - but depends if you have other things connected on these already). Also, if the above makes no difference, try disconnecting the Distance module altogether and then run your code - does it then work ok? If so - possibly suspect the power is reversed to the Distance module? Note that there is no standard 'pin out' on these modules and lots are available on eBay. So worth checking power polarity is correct. Does your Power source have enough current? And is the Distance being powered at 5v? Few things above to check/try . . . Let us know how you get on ![]() WW |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Forgot to mention that if you used copy/paste to insert your code, make sure it copied in ok. On several occasions I have witnessed a failed copy resulting in incorrect running code. |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
Yes, it should work fine. I just tested it on the latest beta version and it worked. It should never hang, even if the sensor is disconnected it will return -2. It does not handle invalid pin numbers very well (it throws a MIPS32 exception) but again it does not hang. Geoff Geoff Graham - http://geoffg.net |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Wauw ! Did not expect this fast and thorough support !! I am impressed. The problem is solved indeed, when I assigned pin 14 and 15 I got the response -2. Then I connected the sensor, and started getting readings. Thank you for the help. I have re-arranged the pins now, so I can get everything connected. It was a bit of a puzzle, because I need 3 servo's, 4 ADC channels, the display (1602, so eating 6 pins), the distance sensor.....3 leds and 2 switches... By the way, I am impressed by MMBasic and the micromite. I used to work with PICAXE chips, and these too have benefits, but to get string handling, no need to worry if you have a byte, and integer... and sufficient speed. That is quite an achievement. Regards, Volhout PicomiteVGA PETSCII ROBOTS |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
Welcome. ![]() I too am ex-PICAXE. I still use the little 8-pin PICAXE for simple single-task things from time to time.(such as a data-filter for 'Dumb' RF modules). But the Micromite has so many wonderful features built-in, I am sorry to say that the little 8-bit PICAXE has been left behind to some extent. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Hi dear members, I am managing quite well with the micromite, however occasionally I stumble into things that are not very obvious to me. Today I spend some time figuring out why I could not return to the console after stopping my program with CTRL-C. It is a program to control an 1602 LCD. You can test it without the actual LCD, I tried it. ' text on lcd LCD init 7,9,10,14,2,3 i=0 Do LCD 1,1,"Loops : " LCD 2,2,"Dummy text" LCD 1,12,Str$(i) i=i+1 Pause 300 Loop Until 0 End Yo can halt the program with CTRL-C, but you do not get back to the console. This is due to the LCD command. After I comment out LCD INIT and LCD writes, CTRL-C let's me return to the console (Putty). I found a workaround in typing CTRL-C then F4 (editor). But it is related to the pins I assigned to the LCD display. If I use pins 26.....21, all is fine. But the above pins (2...14) cause problems. Maybe this is related to my earlier problem with the distance command (where I used the wrong pins) since the behaviour is quite the same... you simply don't get back into the console after halting the program, and it feels if the micromite hangs....until you press F4. Maybe the prompt, after CTRL-C is sent to the LCD ??? I am not sure if this is a bug, or me....not reading through all the manuals... Perhaps it is writtens somewhere... Or it is something related to the SPI interface pin 3 or 14 being initialized for the (default ?) color LCD, and causing this artefact. Again, I found a solution, but you may want to check if this must be on some bug list ? Regards, Volhout PicomiteVGA PETSCII ROBOTS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Hi volhout, I have just run your code on a 28pin BackPack and it runs ok as well as Ctrl-C returning to a Command Prompt. I had to use the following pins though: LCD INIT 26,9,10,24,22,21 Try with these PIN numbers and see if you still have issues. Am using an older MMBASIC v5.04.05 How are you connecting between your computer and the MicroMite PIC? Also, how are you powering the MM? Is it mounted on a BreadBoard? If not - on what have you built your circuit? PCB / veroboard? WW |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Dear whitewizzard, I have confirmed that with different pin assignment the problem is solved. But I have no clue why my original assignment gives a problem.. Thank you for your help. Volhout. PicomiteVGA PETSCII ROBOTS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Hi, I am trying to see if your Pin 10 is an issue (common PIN number between your two issues!) Do the Pins I mention in my post above (i.e. LCD INIT 26,9,10,24,22,21) work for you? If NOT then swap only Pin 10 in the parameters for a different Pin. Then if the 'new' number works that would point towards a potential hardware issue on Pin 10. Is the circuit on a PCB, Breadboard, or strip/vero board? WW |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Dear whitewizzard, I can confirm that (in both cases) pin 10 is the culprit if used as an output. Meaning: print distance (10,14) has the problem print distance (14,10) doe not have the problem (no sensor connected, returns "-2", as this could damage the 3.3V pin 10). As soon as I include pin 10 in either the LCD of DISTANCE commands, the behavior is that a CTRL -C does not return to console. In both cases pressing F4 (edit) will bring up the editor screen, and with ESC get you back to the console. Regards, Volhout I am using a vero board with 28 pin socket, 47uF tantal cap. Run the MX from 3.298 Vdc. Appart from the serial lines RX and TX, only RESET is attached to the microbridge (I disconnected the PGC and PGD lines because I need the pins)....and of coarse we share GND and 3.3V. If in your example I replace pin 10 with pin 9, all is OK. PicomiteVGA PETSCII ROBOTS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
OK - Pin 10 is next to Pin 11 which is the MM's Console output. ![]() If there is a short between Pin 10 and Pin 11, then whenever Pin 10 is an 'output' it will stop comms from the MM to your console app. So do check for a short (or very low value resistance) between Pin 10 & Pin 11. Use a multimeter if you can (rather than just a visual check). Reckon we're close to resolving this one now . . . |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
I am convinced from this statement that you have a short between Pin 10 and Pin 11. If any pin is configured as an output, then when a running program is terminated with Ctrl-C, the pin will remain configured as an output. However, as soon as the EDITor is initialised (by pressing F4), the MMBASICs 'resets' all pin configuration (to OFF) i.e. Pin 10 would no longer be an output (as in your two examples). The Console Pin (11) is then not tied high (or Low) by the short to Pin 10 and hence you get response back. This is exactly what you're describing so hopefully you'll find a 'short' somewhere. WW |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
A brilliant deduction. You could be a second Sherlock Holmes. Geoff Graham - http://geoffg.net |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Now I know why they call you the white wizzard! Impossible to see with the bare eye, but under amagifying glass there was a hair thin short between pins 10 and 11. I could not believe it, thought I checked everything carefully, but it was there. Thanks a lot wizzard ! Now I can rearrange the pins to my liking, and better suited for single sided layout... Regards, Volhout PicomiteVGA PETSCII ROBOTS |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Great News Volhout - glad that little mystery is solved ![]() WW |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |