Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:23 10 Nov 2025 Privacy Policy
Jump to

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 : Pi-cromite 5.4.10, external ADC support

     Page 1 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 09:02am 23 Sep 2017
Copy link to clipboard 
Print this post

Please find attached version 5.4.10 of the Pi-cromite software

2017-09-24_101840_mmbasic.zip

2017-09-23_183552_Pi-cromite_Manual.pdf

Remember to delete the options file before running this release

rm .options


One downside of the Raspberry Pi is that it doesn't have an analogue input capability. This release supports two alternative external 4-channel ADC chips, the ADS1015 and the MCP3424.

Both chips are widely available on breakout boards and the ADS1015 is also found on the excellent Pimoroni Enviro pHAT

The ADS chip is faster but limited to 12-bits resolution and the code supports 4 single-ended channels. The MCP at full 18-bit resolution takes over a quarter of a second for a conversion but when set to +/- 0.256V range can easily measure thermocouples and even strain gauges. The MCP also has differential inputs so can measure negative differential voltages.

Both chips are connected via I2C and all the communication with the chip is handled by the Pi-cromite firmware. The ADC must be connected SDA to Pi pin 3, SCL to Pi pin 5.

The ADC system is initialised with a single option command which also specifies the 7-bit I2C address of the chip e.g.

OPTION ADC ADS1015, &H49 ' address on the Enviro pHAT


or

OPTION ADC MCP3424, &H68 ' address when chip address lines left floating


When the option is specified the I2C port is automatically opened as soon as MMBasic starts. I2C speed is set to 400KHz. OPTION I2C is automatically set.
Other chips can share the I2C lines and are programmed as usual except that I2C OPEN is not used.

The ADC can be disabled with

OPTION ADC OFF


Reading the ADC is done with the ADC function:

voltage = ADC(channel, range [,precision])


This returns the input voltage on the specified ADC channel (0-3). Both chips contain in-built programmable gain amplifiers. The range is specified as the full-scale in mV. Valid ranges for the MCP3424 are 256, 512, 1024, and 2048. Valid ranges for the ADS1015 also include 4096 and 6144. The MCP3424 must also have the number of bits of precision specified. Valid values are 12, 14, 16, and 18. The conversion time on the MCP3424 changes with the precision – see the manual for details.

In addition the range can be specified as AUTO in this case the code does a first conversion at the maximum range and then chooses the lowest safe range for a second more accurate conversion. Care should be taken in using AUTO with moving signals.

Unrelated to the new release I'm seeing one strange problem with the Pi Zero-W. I've upgraded to the latest Raspbian release (stretch) which may or may not be relevant. MMBasic statements that contain a syntax error sometimes lock up the Pi requiring a reboot. An example would be "? mm.hres()". This error is handled completely correctly on the Pi 3 and is not code I've changed from the original Micromite. The Pi Zero correctly reports the error but then freezes
Edited by matherp 2017-09-25
 
RonnS
Senior Member

Joined: 16/07/2015
Location: Germany
Posts: 121
Posted: 02:19am 06 Oct 2017
Copy link to clipboard 
Print this post

hello Peter

this version of mmbasic seems to have a bug - i cant call GUI Calibrate then mmbasic stops, i switched back to Vxx.09 there all ok

regards Ron
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 04:29am 06 Oct 2017
Copy link to clipboard 
Print this post

Just downloaded the version above and it works perfectly for me (ILI9481). Ditd you delete the .options file before running it?
 
RonnS
Senior Member

Joined: 16/07/2015
Location: Germany
Posts: 121
Posted: 10:05am 06 Oct 2017
Copy link to clipboard 
Print this post

  matherp said   Just downloaded the version above and it works perfectly for me (ILI9481). Ditd you delete the .options file before running it?


yes
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1044
Posted: 02:32am 07 Oct 2017
Copy link to clipboard 
Print this post

Hi,
Just having my first play with this,could not resist any longer.
I am loading programs with the AUTO command and pasting them in. Each paste is appended at the end.What I am trying to do is develop in MMEdit and paste the program in which seems to work OK ,but needs to replace the whole program each time.

Would it be possible that there is an option that clears the existing program when AUTO is entered.
e.g.
a) Change the default behavior of AUTO or
b) have and option such as AUTO [NEW] or AUTONEW

Currently I am using this sequence to achieve what I want to do.
NEW
AUTO

? MM.VER also truncates one character now the version is 5.4.10
returns 5.4.1 presumably truncated by 1 character.


Regards
Gerry



F4 H7FotSF4xGT
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 08:19am 07 Oct 2017
Copy link to clipboard 
Print this post

Please find attached version 5.4.11.

2017-10-07_180834_mmbasic-stretch.zip

2017-10-07_181432_mmbasic-jessie.zip


  Quote  Would it be possible that there is an option that clears the existing program when AUTO is entered


That was a bug AUTO should clear the existing program the same as autosave on the Micromite - fixed in the new version


  Quote  MM.VER also truncates one character now the version is 5.4.10


That is a feature of Geoff's code. The code converts the version number into a floating point number and of course trailing zeros are not displayed. Just means I can't use version ending in a zero

Ronns:

Version 5.4.10 was compiled under the new Raspbian release "Stretch". I've compiled 5.4.11 under both Jessie and Stretch for this release - may or may not make a difference but they are different sizes.

I've tested GUI calibrate on ILI9341, ILI9481, and SSD1963 and it works perfectly on all of them on both Pi 3 and Pi-Zero W. Calibrate will hang if it doesn't see T_IRQ so check wiring hasn't been compromised. Hope one of the versions works for you - if not, I'm not sure what more I can do.
Edited by matherp 2017-10-08
 
RonnS
Senior Member

Joined: 16/07/2015
Location: Germany
Posts: 121
Posted: 11:02am 07 Oct 2017
Copy link to clipboard 
Print this post

hello Peter,
it works with the "Jessi" Version now and the message due to missing libs is no longer seen before the mmbasic starts

thank you
Ron
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1044
Posted: 09:32pm 07 Oct 2017
Copy link to clipboard 
Print this post

Note for the next manual update.

The LongString Functions have not yet made it into the manual.


substring$ = LGETSTR$(longstringarray%(), start_position, number_of_chars)
string_length% = LLEN(longstringarray%())
test_string_position = LINSTR(longstringarray%(), test_string$ [,start_position])
string_comparision = LCOMPARE(first_longstringarray%(), second_longstringarray%())


r = LCompare( str1, str2 )
Compare the contents of two long string variables.
The returned value 'r' is an integer and will be -1 if 'str1' is less than 'str2'. It will be zero if they are
equal in length and content and +1 if 'str1' is greater than 'str2'. The comparison uses the ASCII
character set and is case sensitive. 'str1' and 'str2' must be long string variables.


r = LLen( str )
Will return the length of the string stored in the long string variable 'str'.

r = LInstr(str, srch, start )
Return the position of a substring in a long string.
The returned value ('r') is an integer and will be zero if the substring cannot be found. 'str' is the
string to be searched and must be a long string variable. 'str' is the substring to look for and it must
be a normal MMBasic string or expression (not a long string). The search is case sensitive.
Normally the search will start at the first character in 'str' but the second version allows the start
position of the search to be specifies as the number 'start'. In both the returned value ('r') and the
start position ('start') the first character in the string is number one.
For example, if the string str held "Hello world hello and hello":
PRINT LInstr(str, "worxx") Would print 0
PRINT LInstr(str, "Hello") Would print 1
PRINT LInstr(str, "hello") Would print 13
PRINT LInstr(14, str, "hello") Would print 23

s$ = LGetStr$( src, start, len )
Returns part of a long string as a normal MMBasic string.
's$' is the MMBasic string returned by the function. 'src' is the source long string variable, 'start' is
the character number in 'src' to start copying from (the first character is numbered one) and 'len' is
the maximum number of characters to return. If there are no characters to return 's$' will be an
empty string and if there are fewer characters than that 'len' then only they will be copied.
The following is an example of how to output a long string to a serial port using this function:
FOR i = 1 TO LLen(Str1()) STEP 250
PRINT #4, LGetStr$(Str1(), i, 250);
NEXT i






Regards
Gerry
F4 H7FotSF4xGT
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 10:19pm 07 Oct 2017
Copy link to clipboard 
Print this post

  Quote  Note for the next manual update.

The LongString Functions have not yet made it into the manual.


Easily rectified

2017-10-08_081846_Pi-cromite_Manual.pdf
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 07:51pm 09 Oct 2017
Copy link to clipboard 
Print this post

GDay Peter, All,

With all the changes in firmware and manuals etc can these be added to the Back Shed Document Register? (an example of my PCB manual pointed to in that link)

As it is it is hard to keep up with the latest versions.. especially if, as like me, I have had an initial play but have the project shelved until work settles down again.

Kind Regards,

Mick


Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 177
Posted: 09:18pm 09 Oct 2017
Copy link to clipboard 
Print this post

+1 Mick.

Listed, in folders, by device type would be good (MM, MM+, MMX).
With latest at the top.

Regards, Mike B.
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 02:51am 10 Oct 2017
Copy link to clipboard 
Print this post

+1 for docs and firmware versions in http://www.thebackshed.com/docregister/Browse.asp
(or at least links under descriptive headings).

I didn't know that existed.

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 05:48am 10 Oct 2017
Copy link to clipboard 
Print this post

  Quote  I didn't know that existed.


Nor did I which highlights the problem. There are several competing indexes/repositories.

To find any of my code, all I do is click on the matherp in the header of any of my posts and the BB gives a complete list of all the threads I've started in date order. This makes it very easy to find the latest version of any of my code/releases. I always try and put relevant details in the thread title.

To me this is much easier than trying to maintain numerous locations with current versions. Sorry but with limited time that is the best I'm going to do. If anyone else wants to index/store then that is fine - everything I post is completely open source except Pi-cromite and MMX source which is subject to the same licence conditions as Geoff's underlying code.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 03:15am 11 Oct 2017
Copy link to clipboard 
Print this post

Ah, I see. By clicking "Profile" on a post of yours, and scrolling down, I see all the posts you have initiated. Didn't know about that either. Very useful to know.

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2971
Posted: 03:10pm 11 Oct 2017
Copy link to clipboard 
Print this post

Peter, All,

That is a reasonable work around providing that you dont get into the habit of updating versions in an older thread.. ie. start a new thread with each version

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:51am 12 Oct 2017
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I didn't know that existed.
Nor did I which highlights the problem. There are several competing indexes/repositories.

Glenn (GIZMO) set up the document register back in April 2016 - see this thread. There are 19 very useful entries (documents) in it, all of which were added back then, but none have been added since. All nineteen were authored by either Geoff, Rob Rozee or Mick Gulovsen.

Glenn mentioned in that thread that he would need 'administrators/moderators' to control documents to be added but I haven't seen any posts since that mention anything more. There also don't seem to be any links to the document register in the forum 'screens' although various posts from those original three authors do have links to them within the post. This means that there is no way of browsing or accessing those documents unless you happen to read a particular post that references them, or you keep your own bookmark to the document register.

There was an in-depth discussion a couple of years ago about setting up a library in this thread which resulted in the formation of a library hosted by Peter Carnegie (G8JCF). Glenn had a link to this in the sticky post topic in this forum.

Since that library however is no longer available the 'sticky' library link has been replaced by the Fruit of the Shed link to Andrew's (CaptainBoing) excellent community driven 'Wiki' library. Andrew has pointed out that many libraries fail for a number of good reasons, not the least being keeping them non-commercial and also the onerous long-term commitment needed of the 'librarian'. He feels the Wiki approach is the most sustainable and the 'Fruitofthe shed' is currently tasting pretty good.

Greg

 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1044
Posted: 11:51pm 12 Oct 2017
Copy link to clipboard 
Print this post

MMEdit Syntax file for Pi-cromite V5.4.10

I use MMEdit to do all my MM programing so as part of playing with the Pi-cromite
I have created an MMEdit syntax file for the Pi-cromite as I read all that been written in Peter's posts and tried commands to verify them when not certain of the status.

Its taken quite a few hours over a few days, so Jim must have really spent some time on the ones produced so far for the other MMs.

Here is some nonsense code that merely test how syntax is highlighted.
It shows MMEdit highlighting (turns them blue) the new commands and not highlighting some of the ones not in the Pi-cromite.
.e.g. cfunction, csub, ain,spi2,I2c slave,PEEK cfunaddr, SDCARD


  Quote  OPTION autorefresh
refresh

OPTION i2c 11,12
OPTION lcdpanel ILI9481,LANDSCAPE,29,31,13
OPTION lcdpanel disable
OPTION lcdpanel ILI9486,LANDSCAPE,29,31,13
OPTION lcdpanel disable
OPTION lcdpanel ILI9341,LANDSCAPE,29,31,13
OPTION lcdpanel disable
OPTION TOUCH 26,24

DEfinefont 6
0000
end DEfinefont

'4.3" SSD1963 with page support.
OPTION lcdpanel SSD1963_4P
GUI startline 272

' NOT SUPPORTED cfunction, csub, ain,spi2,I2c slave,PEEK cfunaddr, SDCARD
cfunction ctest
end cfunction
csub
end csub
spi2
SETPIN 28 ain
i2c slave
peek(cfunaddr,ctest)
SDCARD
OPTION sdcard

'syntaxs works but not sure they are implemented.
VAR SAVE thisvar
VAR RESTORE
VAR CLEAR


OPTION CASE UPPER
TEMPR Start
?
FIELD$("aaaa,bbbbbbb,cccccccc,",2,",")

?
MAX(1,4,6,8,33,4)
?
MIN(10,4,6,8,33,4)
?
TIME$
?
DATE$
CPU
BITSTREAM 21,66,
BOX
CIRCLE
CLS
DISTANCE
HUMID
IR devcode,keycode,subroutine
BLIT
SAVE image "pic1.bmp"
load image "pic1.bmp",10,10
'ONEWIRE syntax checking
ONEWIRE RESET 11
OWSEARCH (11,1)
?
mm.onewire

'SERVO Command
SERVO 11,1.24
SERVO 11,stop
'PWM Command
PWM 11,10000,50
PWM 11,stop

system "ls -alF"
OPTION COLOURCODE ON

' Socket and transmit html check.
OPTION SOCKET 80
OPEN "SOCKET" as #5
print #5,"hello"
transmit html
close #5
transmit page "index.html"
transmit code 404
LongString append a%(),Input$(10,2)
p%=
LInStr(a%(),"GET",1)
t%=
LInStr(a%(),"HTTP",1)
s$=
LGetstr$(a%(),p%,t%-p%+4)
LongString ucase a%(),t%+4


' COUNT pins CIN,PIN,FIN on pins 12,24,29,33
SETPIN 12,Cin
SETPIN 24,pin
SETPIN 29,fin
SETPIN 33,Cin

' FORK syntax highlighting check
FORk ls -alF
FORk KILL
?
MM.FORK
FORk aplay sound.wav
FORk KILL

sensorfusion madgwick
sensorfusion mahony
triangle
CIRCLE
rbox
pixel
line



This shows where MMEdit puts its syntax files. So you need to add it there and restart MMedit to see it.



Here is the file zipped.
2017-10-13_094526_Pi-comite_V5.4.10.zip

I will watch this thread for any corrections and then see if Jim wants to put it in his MMEdit distribution for next time.

Regards
Gerry


F4 H7FotSF4xGT
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1044
Posted: 12:18am 13 Oct 2017
Copy link to clipboard 
Print this post

Hi Peter,
I have some suggestions for the manual as a result my digging when updating the MMEdit Syntax file.
In no particular order but here they are.Hopefully you can use then without too much retyping.

This one appears to be missing from the TRANSMIT section.

TRANSMIT HTML

Used to construct and transmit an HTTP 1.1 header of the required length
that contains all buffered PRINT outputs to the fileno opened with
OPEN "SOCKET" as #fileno



A small update to this.


OPEN "SOCKET [interrupt][,count]" as #n

...change TRANSMIT to TRANSMIT HTML




Add these to the existing PWM and SERVO commands as they use pinno
and not 2A,2B etc.


PWM pin, STOP

Stops PWM output on the 'pin'


SERVO pin, STOP

Stops output to the 'pin'



Field may also be in MMX but I don't think its made it into the manuals anywhere yet.


FIELD$(datastring$,fieldno,delimiter$)

returns a field from the datastring$
delimiter$ is the delimiter, defaults to "," if not entered.
fieldno is the required field position to be extracted.Returns "" if field requested is bigger than number of fields.




I dont think OWSEARCH is in any manual yet. It updates MM.ONEWIRE as well.


MM.ONEWIRE

The system variable MM.ONEWIRE is maintainted to show status of OWSEARCH as for ONEWIRE communication
(1=success, 0=failure/no result) See MM manual for other ONEWIRE details.


OWSEARCH (pin, flag [,serial_number_mask)
Flags are:
0 - Continue an existing search
1 - start a new search
4 - Continue an existing search for devices in the requested family
5 - start a new search for devices in the requested family (the MSB of the serial_number_mask)
8 - skip the current device family and return the next device
16 - verify that the device with the serial number in serial_number_mask is available
The system variable MM.ONEWIRE is maintainted as expected (1=success, 0=failure/no result)




IR receive is on a different pin than MM. You can see it in the pinout table but might be worth having here as well.

Some differences to SETPIN and pins for CIN,FIN and PIN are listed.


IR

As for MM but IR receive pin is 33.

SETPIN pin [CIN|FIN|PIN]

Only pins 12,24,29 and 33 allowed for CIN,FIN,PIN config options.
AIN option is not supported. See ADC function for analogue input.
All other SETPIN options as per MM




This extra information for FORK was in your posts, might be useful to add it.

FORK unix_command

.......
Note that the unix command does not need quotes or specific field separators but
commas may be used instead of spaces if preferred.
Note also that the C-library parser does not accept "-" characters in filenames
as these are treated as specific to command syntax.




Last one. These seem to pass syntax, but I don't think they write any where as yet.


VAR SAVE variable
VAR RESTORE
VAR CLEAR


Hope this is helpful.

Regards
Gerry
F4 H7FotSF4xGT
 
Micro-80
Newbie

Joined: 03/03/2017
Location: Russian Federation
Posts: 26
Posted: 02:11am 13 Oct 2017
Copy link to clipboard 
Print this post

Peter, there is a need to exchange data over the UDP protocol (client-server). Is it possible to implement this with mmbasic on RPi3?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 03:25am 13 Oct 2017
Copy link to clipboard 
Print this post

Gerry: many thanks for your hard work - very useful. I'll make the changes in the manual in the next release. VAR commands will be removed as these make no sense in a RAM based environment and given that you always have a SDcard available.

  Quote  Peter, there is a need to exchange data over the UDP protocol (client-server). Is it possible to implement this with mmbasic on RPi3?


Not at the moment but you may be able to do something with the SYSTEM command.

Do you need sender (fairly easy) or receiver (considerably harder)?Edited by matherp 2017-10-14
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025