Welcome to crunch time! Since my last posting until day eighty has been, to say the least, challenging. After partially constructing the Picorder in its case, all sorts of unknowns have came to light. I have practically had to throw out all previously conducted testing of hardware and software and start over. That which works in a "black box" environment, rarely functions in the same manner as a complete unit or system. That saying about inventions being 99% perspiration and 1% inspiration holds very true to form!
When I previously tested the temperature and humidity component of the Picorder on the bench, it worked flawlessly. Later on, I tested a PCD8544 display for functionality which worked fine, but later decided to go with a full 2.8" 320 x 240 TFT display instead of the smaller screen. Sound testing of the small amplifier I'm using worked fine when I triggered GPIO pins to play pre-recorded sound bytes stored on the SD card. I followed that testing with a flame detector which textually announced the presence or lack of flame displayed on the TFT display and PC.
In between tests, I incorporated both an alcohol and a CO2 sensor on the case as I prepared to get the most sensor detection built into the unit that I had physical space. These two devices had operational requirements that I had not previously anticipated. While I had not blogged about it, I had been planning on using either a 6vdc, 4xAA cell battery to power the unit, or possibly at least a 7.5vdc Nicad or lithium cellpack. In order to use either of these power systems, their output would need to be regulated. The Pi requires 5vdc@750ma plus the display, the sound amplifier requires 1.5vdc, and the two sensors even more. To accomodate these requirements I installed, so far, a 7805 voltage regulator to satisfy much of the requirement. I am still ineffective at draining the 1.5vdc from the power supply. As for the gas sensors, they both required additional power to be supplied to heating elements. These elements required 5v to 25v, dc or ac to operate and up to 48 hours of uptime to stabilize. Since the Picorder concept, in the tradition of Star Trek TOS, was to construct a sensing device to be used on unknown worlds, to determine immediate conditions capable to support human life for exploration, and to record the results for further analysis, it became obvious to abandon the use of these two sensors due to their excessive power use and warm-up period. I am now faced with finding other sensors to replace these two that will function in the same capacity or substitute other types of sensors with other capabilities.
My intent with the development of the Picorder is to test and record such readings as temperature, humidity, flame, sound, gases, and distance to objects. These were some of the elements and conditions we've seen the landing party characters from Star Trek record while exploring distant planets on their Away Missions. The original tricorder device tested for conditions such as these and did not rely on GPS, the internet, transceivers, satellites, external power systems, etc, to do so. The tricorder is a self-contained scanning, computing and recording device used for immediate detection and future extensive analysis. These readings and others like them needed to be analyzed immediately to avoid or prevent the threats and dangers of unknown planetary conditions.
Bench testing of the individual components and processes had been going well. Individual tests with the hardware and software proved promising. The expected reactions and results of the tests occurred as predicted. I've been using the Python code only because I started with it. In some ways, the formatting of the code is most frustrating for me! Unfortunately I do not know C, C+,C++, bash, etc. I am not software savvy with the various shells, languages and scripting methods, and to get this far with the project has been truly amazing. Consolidating the software code to function as desired with all sensors collectively is taking greater effort than even the physical construction of the unit. If ever I needed a miracle to complete ontime, this is the time for one!
Today I find myself removing the two gas sensors and needing to replace them with others. Those are the two .5 inch diameter brown cylinders with the silver screen in the previous photos I've posted. Leaving them out is not desirable since the testing of harmful gasses to human life would be paramount on any expedition of any planetary body exploration. So at this late date of the competition, I need to find a viable alternative for the gas sensors. I also need to modify the case to accommodate their replacements once determined and acquired. On top of everything else mentioned, I changed out the Raspberry Pi model B and replced it with the model B+ so I could use the extra GPIO pins made unusable and covered by the header connector of the display.
I'm enclosing the code being used so far. It is not in any particular scheme or flow for the device. I just want to put it out there. Obviously I need to consolidate it and work it into a usable format. This is my greatest challenge throughout the entire contest since I don't have a team working with me. One of my biggest concerns is the various libraries and their locations on the SD card. Pointing to them within the software construct is of paramount importance. Referencing those libraries at the appropriate times will be necessary for the recording, storing and displaying of the sensor readings.
Any suggestions or inclusions by any 'code experts' out there would be greatly appreciated and acknowledged!
So as of Day 80, reengineering, reformatting, redesigning, replacing, reevaluation and reassessment are the topics of discussion and direction moving forward. The rewards of Science, Technology, Engineering, and Mechanics are unsurpassed in any endeavor.
Sample code:
########################################################## # These are excerpts from scripts found on line. # # Authorship is either unknown, or not been identified # # in found scripts. Parts of those scripts are used here,# # but none in their entirety or original format. # # That which is commented out has been done so in order # # to test separate segments of the code. Other sections # # are general comment statements to assist in writing. # ########################################################## ############################################################################### # Authorship applies to only sections of the Adafruit_DHT, temp/humidity code # # Copyright (c) 2014 Adafruit Industries # # by Author: Tony DiCola # ############################################################################### #!/usr/bin/python #!/usr/bin/env python #import os import Adafruit_DHT #import Adafruit_Python_DHT # Sensor should be set to Adafruit_DHT.DHT11, # Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302. # Copyright (c) 2014 Adafruit Industries # Author: Tony DiCola # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ############################################################################### ############################################################################### # for instance, using a Raspberry Pi with DHT sensor # connected to pin 19. from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(13, GPIO.IN) # Flame detect GPIO.setup(18, GPIO.IN) GPIO.setup(19, GPIO.IN) # Temp, Humidity #GPIO.setup(21, GPIO.IN) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) pin = 19 sens = Adafruit_DHT.DHT11 # Take a sensor reading. The read_retry method which will retry up # to 15 times to get a sensor reading (2 seconds between retries). humidity, temperature = Adafruit_DHT.read_retry(sens, pin) if humidity is not None and temperature is not None: print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity) else: print 'Obtaining reading. Please wait!' #################################################################### #################################################################### #input = GPIO.input(13) ################################ ## Flame Sensor read routine ## ################################ #import RPi.GPIO as GPIO #GPIO.setmode(GPIO.BCM) #GPIO.setup(13,GPIO.IN) #input = GPIO.input(13) while True: if (GPIO.input(13)): print("Flame detected, take precautions") else: # print("All clear, no flame detected") # print("") # sleep (0.1); #clear #while True: # if (GPIO.input(13)): # print("Flame Detected") # else: # print("Not Detected") # if (GPIO.input(18) == False): # os.system('mpg123 -q twohours.mp3 &') # if (GPIO.input(21) == False): # os.system('mpg123 -q access.mp3 &') # if (GPIO.input(24) == False): # os.system('mpg123 -q defense.mp3 &') # if (GPIO.input(25)== False): # os.system('mpg123 -q Destruct.mp3 &') # Note: sometimes you won't get a reading and # the results will be null (because Linux can't # guarantee the timing of calls to read the sensor). # If this happens, try again. # might be time.sleep(0.1); # sleep(0.1); #################################################################### #################################################################### #################################################################### #################################################################### #!/usr/bin/python # remember to change the GPIO values below to match your sensors # GPIO output = the pin that's connected to "Trig" on the sensor # GPIO input = the pin that's connected to "Echo" on the sensor ## def reading(sensor): ## import time ## import RPi.GPIO as GPIO # Disable any warning message such as GPIO pins in use ## GPIO.setwarnings(False) # use the values of the GPIO pins, and not the actual pin number # so if you connect to GPIO 25 which is on pin number 22, the # reference in this code is 25, which is the number of the GPIO # port and not the number of the physical pin ## GPIO.setmode(GPIO.BCM) ## if sensor == 0: # point the software to the GPIO pins the sensor is using # change these values to the pins you are using # GPIO output = the pin that's connected to "Trig" on the sensor # GPIO input = the pin that's connected to "Echo" on the sensor GPIO.setup(26,GPIO.OUT) GPIO.setup(5,GPIO.IN) GPIO.output(26,GPIO.LOW) # found that the sensor can crash if there isn't a delay here # no idea why. If you have odd crashing issues, increase delay time.sleep(0.5) # sensor manual says a pulse length of 10Us will trigger the # sensor to transmit 8 cycles of ultrasonic burst at 40kHz and # wait for the reflected ultrasonic burst to be received # to get a pulse length of 10Us we need to start the pulse, then # wait for 10 microseconds, then stop the pulse. This will # result in the pulse length being 10Us. # start the pulse on the GPIO pin # change this value to the pin you are using # GPIO output = the pin that's connected to "Trig" on the sensor GPIO.output(26, True) # wait 10 micro seconds (this is 0.00001 seconds) so the pulse # length is 10Us as the sensor expects time.sleep(0.00001) # stop the pulse after the time above has passed # change this value to the pin you are using # GPIO output = the pin that's connected to "Trig" on the sensor GPIO.output(26, False) # listen to the input pin. 0 means nothing is happening. Once a # signal is received the value will be 1 so the while loop # stops and has the last recorded time the signal was 0 # change this value to the pin you are using # GPIO input = the pin that's connected to "Echo" on the sensor while GPIO.input(5) == 0: signaloff = time.time() # listen to the input pin. Once a signal is received, record the # time the signal came through # change this value to the pin you are using # GPIO input = the pin that's connected to "Echo" on the sensor while GPIO.input(5) == 1: signalon = time.time() # work out the difference in the two recorded times above to # calculate the distance of an object in front of the sensor timepassed = signalon - signaloff # we now have our distance but it's not in a useful unit of # measurement. So now we convert this distance into centimetres distance = timepassed * 17000 # return the distance of an object in front of the sensor in cm ## return distance # we're no longer using the GPIO, so tell software we're done GPIO.cleanup() ## else: print "Incorrect usonic() function varible." print reading(0) #################################################################### #################################################################### #################################################################### #################################################################### #!/usr/bin/python import math f = open('mydata.dat', 'w') # Loop for degrees in range(720): # Generate three data points si = math.sin(math.radians(degrees)) co = 0.5 * math.cos(math.radians(degrees)) if si>0: sq = 0.6 else: sq = -0.6 # Write 3 data points to text file data = "{} {} {} {}\n".format(degrees,si,co,sq) f.write(data) f.close() #The entire script can be downloaded from here: #wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/gnuplot/gnuplot_generate_data.py # # To run the code: #sudo python gnuplot_generate_data.py # ### # # Then start 'startx' # #startx # # Then type: #plot "mydata.dat" # # #plot "mydata.dat" using 1:2, "mydata.dat" using 1:3, "mydata.dat" using 1:4 # # # Setting a Plot Title and Axis Labels # # # To change the plot title you can type the following command : # #set title "Example Plot" #To change the data labels you can modify your plot command : # #plot "mydata.dat" using 1:2 title "Sin", "mydata.dat" using 1:3 title "Cos" #This can be abbreviated to : # #plot "mydata.dat" u 1:2 t "Sin", "mydata.dat" u 1:3 t "Cos" #To change the axis labels you can use the following commands : # #set xlabel "Minutes (mins)" #set ylabel "Temperature (degrees)" # # #Lines and Points #You can also change the way the data points are represented on the graph. By default points are used. You can change the style to “lines” or “linespoints” using the “with” keyword : # #plot "mydata.dat" u 1:2 t "Sin", "mydata.dat" u 1:3 t "Cos" with lines #This makes the square wave look nicer. # # # #################################################################### #################################################################### #################################################################### #################################################################### #PyAudio code for recording kept for reference: #import pyaudio #import sys #chunk = 1024 #FORMAT = pyaudio.paInt16 #CHANNELS = 1 #RATE = 44100 #RECORD_SECONDS = 5 #p = pyaudio.PyAudio() #stream = p.open(format=FORMAT, # channels=CHANNELS, # rate=RATE, # input=True, # output=True, # frames_per_buffer=chunk) #print "* recording" #for i in range(0, 44100 / chunk * RECORD_SECONDS): # data = stream.read(chunk) # check for silence here by comparing the level with 0 (or some threshold) for # the contents of data. # then write data or not to a file #print "* done" #stream.stop_stream() #stream.close() #p.terminate() #################################################################### ####################################################################