165 Pi: MAK Pi ADC and RUPasc by ICH180RR (165.html)

[This article describes a Proprietary Product (as of 2021FJun22)]
[WARNING: Do NOT connect any of the Grove 3V3 power pins on the Maker Pi Pico to the 3V3 power on the Raspberry Pi.]

Keywords:
MAKPiADC Raspberry Pi Pico Cytron "Maker Pi Pico" Raw RUPasc ICH180RR Reading "complex number" "Unix Time" ADC0 ADC1 "Ambient Light" ambLight piButton potentiometer "photo-cell" GPIO22 GP22 "piButton22" picoButton picoButton22 Thermometer "Record the Pico 3V3 voltage" ambTemp "small red led" "In Charge Here" "MAK Pi ADC" warning monitor refrigerator fridge cooler freezer air-conditioner "power outage monitor" "emergency email" ambRemoteLight "ambient remote light" "power back-up" "In Charge Here" "cell-phone charging monitor" "Mak Temp Monitor" "MAK Pi ADC" :61

/KeywordsEnd


(To enlarge .....Click it)
thumb: IMG_4911.JPG
MAK Pi ADC ver 0.1 Prototype

by David @ ColeCanada.com (c) ICH180RR

(To enlarge .....Click it)
thumb: MAKPiADC.jpg
MAKPiADC Layout (future)


The MAK Pi ADC (IX device :61) shown above provides a non-mechanical piButton22, a potentiometer, two ADC lines for the Raspberry Pi, a small red LED and an instrument to measure the ambient light. This is done with the addition of a Raspberry Pico, a Cytron "Maker Pi Pico" to the new board. This new board, the MAK Pi ADC by ICH180RR and relevant Python Code (supplied by ICH180RR) is all that is required. An early prototype of the MAK Pi ADC appears above. It is mounted like a HAT on a Raspberry Pi Model 4 and is connected by 2 thin cables to the Raspberry Pico which is plugged into the Cytron Maker Pi Pico board.

Using the components shown above, the following (continuous) readings of the two ADCs (shown below) arrive at the Raspberry Pi. The first reading from ADC0 is the voltage sensed by ADC0. The second reading from ADC1 is the actual reading from ADC1 (in hexadecimal). Various formats can be selected each time the MAK Pi ADC is started up. Each of the two samples arrive as a complex number. The imaginary part of the reading is the Unix time (# of seconds since the Unix epoch). This will be known as the RUPasc format. RUPasc means "a Reading with Unix time with decimal Points in ASCii format". This means that each "Reading" represents a numerical value coupled with the relevant "Unix time". The P means that the decimal reading and the time are stated with 3 digits to the right of the decimal "Point". Note that the name of the Pico pin usually appears as the "name" of the reading. Different conversion factors can be specified for the MAK Pi ADC to convert the reading into other units. When the reading value is in hexadecimal, it is the exact (unconverted) reading from the ADC (Analog to Digital Converter) on the Pico. As can be seen below, ADC4 outputs the Pico's ambient temperature in Centigrade. ADC3 outputs the VSYS which is very close to 5.0 Volts. VBUS is approximately 0.3 V higher than VSYS. Web Source 04 can be reviewed and used to display the internal voltages of the Pico.

All 4 of these ADC readings are continually sampled and continually sent to the Raspberry Pi by the Pico.


	ADC0:(2.10456+1624341150.000j)
	ADC1:(0xF246+ 1624341151.000j)
	ADC3:(5.03364+1624341152.000j)
	ADC4:(20.3564+1624341153.000j)

Engineers and digital technicians should note that Pico ADC readings in hexadecimal sometimes have a left-most "digit" of "F" instead of "0F". A Python hexadecimal number beginning with "F" does NOT indicate a negative number using 2's complement format or notation. In fact, I don't know how a negative number is displayed in hexadecimal in Python. Perhaps it errors out. Furthermore digits to the right of the decimal point are rarely used after converting a number to hexadecimal. In Python "print(int(0xffff,16))" prints "65535" not "-1". In RUPasc format, negative hexadecimal integers will be preceded by a minus sign. e.g. -0xFFFF will be converted to the decimal number "-65535". Positive hexadecimal numbers are sometimes returned by ADC devices to maintain accuracy by doing absolutely no calculations nor conversions. This might be because today's 8-bit Pico processor does not have floating point hardware and returns neither negative numbers nor fractionary components of a hexadecimal number. Furthermore, today's Pico cannot read negative voltages.

The MAK Pi ADC prototpye board shown above has many female pins whose values can be sensed by ADC1 (or ADC0). All of the GPIO pins on the Raspberry Pi are also available to be sensed (i.e. read or measured) using a simple female to male jumper.
WARNING: do not attempt to read the 5V0 pin directly or the Pico will be destroyed. 
The DIP switches and jumpers allow selection of which electrical terminal is to be measured by each ADC. The ADC0 normally is connected to the on-board photo-cell that measures the "Ambient Light". Touching the photo-cell is akin to pressing a button. It is called the piButton or piButton22 and is connected to pin GPIO22. The Raspberry Pi has no ADC, but it can sense the digital value of its GPIO22 even without a Pico being attached. When the operator of the Raspberry Pi touches the photo-cell, GPIO22 is read as 0 (normally it is 1). This is said to be "Active-Low". However because the photo-cell is also connected to ADC0 on the Pico by a wire, a reading of the ambient light can be sensed if nothing (i.e. no finger) obstructs the light. As shown above, the local "ambientLight" is read as a voltage, that was "2.10456 volts" in this case. On the MAK Pi ADC, ADC1 is connected to a rotary control knob called a potentiometer. It's value is being read as the raw reading of ADC1, which is given in hexadecimal format. This hexadecimal value ranges from 0x0000 to 0xFFFF when read from a Pico ADC using the MAK Pi ADC. Each of these readings is reported as being coupled to the Unix time value when the reading was taken. The Unix time is followed by a "j" indicating that the time is the imaginary component of the complex number. Mathematicions often suffix an "i" to the imaginary portion of a complex number, but the creators of Python and MicroPython chose to use a "j" instead. Perhaps this was done to distinguish an "imaginary number" from an "integer number". This complex number couples a "real" reading value with an "imaginary" time value. This one complex number binds together both the reading and the timeStamp of the reading. The Unix time of 1624341150.000 (shown above) converted to Greenwich Mean Time is equivalent to:
 "Tue Jun 22 2021 05:52:30.000 GMT+0000"
This is the exact time when the reading was taken, permitting readings at different locations and in different time zones to be correlated correctly. Readings of other "test" points can be selected by connecting a simple electrical jumper wire from any pin on the board to the female pin of the ADC1 and turning a DIP switch on/off. Each reading (coupled with the time in RUPasc format) is sent to the Raspberry Pi, usually at regular time intervals. In this way the simple "MAK Pi ADC" board (with the Pico) effectively adds 2 ADCs to the Raspberry Pi. An Arduino is no longer the easiest way to get an ADC reading. The "MAK Pi ADC" adds 2 ADCs to the Raspberry Pi world. Software is also available to measure and report the ambient temperature (ambTemp) and the exact value of the 3V3 voltage (pico3V3) on the Pico using the "MAK Pi ADC" and the Pico. The MAK Pi ADC board also has a small red LED that provides minimal communication back to the person operating the MAK Pi ADC. For more information contact the WebMaster mentioned below.

The MAK Pi ADC software also provides code for a picoButton (also called picoButton22) that functions like the piButton described above. The picoButton22 returns 0 (normally 1) when the GP22 push button on the "Maker Pi Pico" is pressed. Code to turn on/off the green picoLed is also provided.

Function to Request a Sample Reading

There are various parameters that can be read by the Raspberry Pi. Some parameters are measured by the Raspberry Pi itself. Other parameters are read by the Pico and are transmitted to the Raspberry Pi. The parameters that are continuously sampled by the Pico are quite easy to read. All that the Raspberry Pi needs to do is to request the next reading of the desired parameter the next time it is sent by the Pico to the Raspberry Pi. It suffices to call the function and wait for the reading by the Pico to arrive. A similar function is called to request a reading by the Raspberry. The only difference is that the reading from the Raspberry Pi will probably arrive sooner.

The function to call for a complete msg to be read is readingRx(parameterName, sourceName, timeInterval, timeOut). A typical call for a reading would look like this:

#                                                      This program is a "Work in Progress"
progName = "test_mainReadMsg_pi.py"
print("progName:"+progName)
while True :                                              		#continuously read and do the following
	time0=time.time()
	timeOut=time0+180    # timeOut after 3 minutes


	while time< timeOut :
		# wait for a reading of ADC0 from the Pico Board
		#    sample the pkt stream from the Pico every 1 sec with a timeout of 90 seconds
		if anyReading("Pico","ADC0" ,1, timeOut)==True :
			parameterName="ADC0"      		#from the Pico stream
			readingComplex=reading("Pico","ADC0")
			readingValue=real(readingComplex)
			readingTime=imaginary(readingComplex)
			readingDT=readingTime-time0  		# time relative to time0
			readingUnits="volts"
			print("The value of", parameterName,"was ", readingValue, readingUnits,"at", readingTime, "secs:")
		#end if
		if anyButton(piButton22,"Pi",5,timeOut)==0 :
		      if (piButton22==0):
			print("piButton22 was pressed")
	                 #end if
		#end if
		timeNow=time.time()
		while timeNow< timeOut :
			commandReceived=""
			commandReceived=inputWait("type a command",4)
			print("commandReceived "+"was requested")
			timeNow=time.time()
		#end while
	#end while

ambLight at the Pico

There is a market comprised of those wishing to measure the ambient light near the Pico. This marketplace might wish to measure the temperature inside and the ambient light in a fridge or freezer or in an area whose climate is controlled by an air-conditioner or furnace. Measuring the ambient temperature can detect if the appliance is functioning badly or not at all. Measuring the ambient light can detect if the door of the appliance has been accidentally left open. A simple photo-cell circuit is available from ICH180RR to connect directly to the Pico to measure the ambient light.

Fridge or Freezer Monitor

In this way, an "improved" Pico can operate as a watchdog temperature sensor (remote to the Raspberry Pi). Code is available that permits the Raspberry Pi (that is connected to the Pico) to automatically send an email when an emergency situation arises with respect to a fridge, freezer, air-conditioner or furnace. This device (also available from ICH180RR) is called a "Mak Temp Monitor". The "Mak Temp Monitor" can operate in a "headless" mode. It doesn't need a display (eg HDMI monitor) nor a keyboard nor a mouse. But it does need access to a nearby wifi router in order to send email. Even a Raspberry Pi model Zero W can be used.

Building Power Monitor

ICH180RR has another product that monitors the "mains" power provided in a building. But it can only send the power outage notification email if both the wifi router and the Raspberry Pi have a short-term back-up Power Supply. This short-term Back-Up Power is only needed to keep them operational for a few minutes after the local power is lost. These few minutes are critical for the email warning to be sent.

Personal Device Monitor

Yet another inexpensive device is available from ICH180RR to monitor whether or not a person's cell phone is being charged during the night. If the cell-phone is not being charged (i.e. not drawing any current i.e. not connected), an email can be sent and an audible alarm can sound to to warn the owner of the cell phone that he/she forgot to put their cell-phone in the charging station overnight. How many times has anyone of us forgotten to do this essential act every night? This device is called "In Charge Here" and is the product that gave the ICH180RR company its name.

How to measure VBUS & VSYS (around 5V )

Web Source 04 has code that produces the following results:
Example output        VBUS       VSYS

2016 32263 1.624596 | 5.148788 | 4.873788
2019 32311 1.627013 | 5.156039 | 4.881039
2009 32151 1.618956 | 5.131869 | 4.856869
2013 32215 1.622179 | 5.141537 | 4.866537

The MAKPiADC: An Audio TestBed Leading to a Full Access-and-Control System

The first prototype of the MAK Pi ADC facilitates learning about ADC, CDS photocells and taking multiple readings. The Audio testbed shown in the photo at the top of this article adds audio to the mix. The addition of a microphone and speaker capture the audio signals and play the resulting audio through the speaker. The MEMS microphone converts the audio sounds into a digital I2S format which is the format used to store music on CDs and in .wav and .mp3 formats. An audio jack permits sound to be sent or received from other devices. The Pico provides the ADC (Analog to Digital Conversion) hardware. The Raspberry Pi provides easy access to .mp3 and .wav formats and the ability to capture, store (log) and analyse digital audio streams. The 741 provides a small amplifier that will take the small signals from the microphone and play them through the speaker. The author provides all the Python code necessary to glue this all together, one step at a time. A list of the available Python functions follows:
	readMEMS()
	memsToAudio()
	audioToMP3()
	audioToWAV()
	playMP3()
	isMicEnabled()
	readADC0()
	readADC1()
	ADCtoASC()
	ascToVector()
	ascToPrint()
	plotVector()
	displayVector()
	monitorADC0()
	monitorADC1()
	displayReading()
	piButton()
	digLight()
	logReading()
	picoButton()
	sendEmail()
	
Some of these Python functions run on the Pico and some on the Raspberry Pi. Some functions make use of the ultra-fast RP2040 processor on the Pico and some make use of the ultra-fast PIO processor on the Raspberry Pi. In addition to the audio devices on the MAKPiADC, two CDS photocells can be used as digital or analog sources, for example being used as non-mechanical buttons for either the Pico or the Raspberry Pi. The Raspberry Pi lacks ADC converters but can easily make use of two of the ADC converters that are on the Pico. All of these devices can be read (sensed), the results can be logged to an SSD and sent to a web site where all the readings can be stored. Some novel ways to store all of these readings are described by the author. For example, a set of readings can be stored in a Python vector, either at constant intervals or by time-stamping each reading. The time-stamps can be stored in the imaginary portion of complex number vectors (RUPasc format). Remote temperature and light sensors can be monitored, then lamps or heaters turned on (or emails sent) when necessary.

It is very interesting to have each of the devices available, but without the software to glue them together and see the intervening signals, nothing can be learned. The software included with the MAKPiADC is the key to its effectiveness as an educational tool. Article 164 describes many of the individual devices that make up the MAKPiADC, but the software functions are essential.

What is truly interesting is that the user of the MAKPiADC can learn about each different simple device on the MAKPiADC, one at a time. Each device is slowly added to the mix while creating the many, many different parts of a complete Access-and-Control system. The full MAKPiADC is a remarkable educational tool.

End of Article (Sources follow)

This article, by D@CC is of course, a work-in-progress as of 2021FJun22.

External Sources

Video Sources

Video Source 01:www Pi Pico - Review etc (18m 31s) by #garyexplains as of 2021B Feb 08

Web Sources

Web Source S165:01:www Cytron Home Page as of 2021EMay19
Web Source S165:02:www Article 164: "Maker Pi Pico" by Cytron as of 2021FJun22
Web Source S165:03:www Pico: How to Interface (almost) Everything! by Dronebot as of 2021FJun22
Web Source S165:04:www Pico: SOLVED How to measure VSYS by hippy
      See the almost last post dated Wed Feb 10,2021 at 9:46


/SourcesEnd


thumb: IMG_4910.JPG
.
Contact: email: David @ ColeCanada.com or cell: 613-875-7767



WebMaster: Ye Old King Cole

There is a way to "google" any of the part-numbers, words and phrases in all of the author's articles. This "google" search limits itself ONLY to his articles. Just go to the top of "Articles by Old King Cole" and look for the "search" input box named "freefind".

Click here to return to ePC Articles by Old King Cole

Date Written: 2021 F Jun 22
Last Updated: 2024 D Apr 04
More Documentation at: file:///C:.....165\
Backed Up On: 2021 F Jun 22 as 165_2021FJun22.html
© ICH180RR Corp.

/165.html