This code is kids level Analogue Data-Logger(/Transient-Recorder), using the Arduino series of dev' boards.
It is no where near completion and is a second feeder/feeler upload only.
It is designed to work from Classic Text Mode Python from Versions 1.4.0 to 2.7.2 on a Classic AMIGA, WinUAE, Linux and Windows, (32 bit), to Vista. Not tested on Python for Windows 7, (32 bit), nor Mac OSX flavours as I don't have these OSes.
Linux versions run from a default root terminal for the time being.
The Arduino dev' board IS catered for in the code for the above platforms just thoroughly read the code for more information. It defaults to a DEMO mode so you can see it working...
The test code for the Arduino Diecimila Dev Board is here:-
http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/
Enjoy finding simple solutions to often very difficult problems... ;o)
Bazza, G0LCU...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | # DataLogger.py
#
# Copyright, (C)2011, B.Walker, G0LCU.
#
# Issued under the MIT licence.
#
# A kids level project using the Arduino Diecimila and other related boards as an
# analogue input for use as a Data Logger using Python in text mode only. The accuarcy
# is 8 bit depth but the display is only 4 bit depth due to the limitations of text mode.
#
# This is the second feeder upload, it is nowhere near completion. ANY future uploads
# will no longer be feeders.
#
# This code defaults to DEMO mode but the crucial Arduino code is added and just
# requires the line "demo=0" to access the board and the correct device number to
# be changed. Later versions of Arduino now use /dev/ttyACMx in Linux and I have
# not got one to test with, so if any of you guys are willing to experiment by
# changing the Linux device type and number and let me know how you get on with
# it, then thanks.
#
# It now auto-saves a file after every 64 plots in CSV format and tested on MS Works
# and Open Office Org, read the code for more information. To disable the auto-save feature
# just set it to, "autosave=0"...
#
# The test *.pde file for the Arduino Diecimila Board is here:-
#
# http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=user-4177147
#
# Tested on Windows XP using Python 2.4.2, Vista using Python 2.6.1, PCLinuxOS 2009 using
# Python 2.5.2, Debian Linux using Python 2.6.6 and 2.7.2, a stock AMIGA A1200 using
# Python 1.4.0 and WinUAE with standard AMIGA OS 3.1 using Python 2.0.1.
# I have no idea whether this works on Windows 7 or MAC OSX as I have not got either.
# DEMO mode ONLY works in E-UAE with standard AMIGA OS 3.1 and Python 1.4.0 or Python 2.0.1.
#
# IMPORTANT NOTE:- The Linux platforms assume running Python from a root default Terminal in NONE DEMO mode.
#
# (Version set in Classic AMIGA format... ;o)
# $VER: DataLogger.py_Version_0.00.20_(C)2011_B.Walker_G0LCU.
# Imports required so far...
import sys
import os
import random
import time
def main():
# Deliberately set all parameters as global, (my choice!).
global LoggerScreen
global MyFiles
global savefile
global plot
global position
global horiz
global demo
global pause
global pausestring
global serialport
global mybyte
global grab
global csvdata
global autosave
global filestr
# global n
# initial parameter settings...
LoggerScreen="(C)2011, B.Walker, G0LCU."
MyFiles="Data_Logger-Transient_Recorder."
savefile="/tmp/LoggerStartup.txt"
# Default DEMO mode, set to 0 for REAL mode.
demo=1
plot=0
horiz=1
position=79
pause=1
pausestring="1"
# The latest Linux device name for current Arduino variants, (01-01-2011).
serialport="/dev/ttyACM0"
mybyte="?"
grab=255
csvdata="?"
# Temporarily set to autosave enabled for testing, set to 0 to disable.
autosave=1
filestr="0000000000.CSV"
# n=0
# Determine AMIGA, Windows-(32 bit), WinUAE or Linux for serial access.
if sys.platform=="amiga":
# The AMIGA serial port may need to be changed to 1200 baud, no parity,
# 8 bit data and 1 stop bit, this applies to WinUAE too.
serialport="SER:"
if sys.platform=="linux2":
# Assumed running from root for the time being.
# /dev/ttyUSB0 the device on my test systems, the Arduino Diecimila Board.
# It may need to be changed for your needs.
serialport="/dev/ttyUSB0"
os.system("chmod 666 "+serialport)
os.system("stty -F "+serialport+" 1200")
os.system("stty -F "+serialport+" raw")
if sys.platform=="win32":
# This is the COM port number generated on a test system.
# It may need to be changed for your needs.
serialport="COM3:"
os.system("MODE "+serialport+" BAUD=1200 PARITY=N DATA=8 STOP=1 to=on")
# A clear screen function for the platforms shown.
def clrscn():
if sys.platform=="amiga": print "\f",
if sys.platform=="linux2": print os.system("clear"),chr(13)," ",chr(13),
if sys.platform=="win32": print os.system("CLS"),chr(13)," ",chr(13),
# Save the initial screen for future use function.
def savescreen():
global MyFiles
global savefile
global LoggerScreen
if sys.platform=="amiga": savefile="S:LoggerStartup.txt"
if sys.platform=="linux2": savefile="/tmp/LoggerStartup.txt"
if sys.platform=="win32": savefile="C:\\Windows\\Temp\\LoggerStartup.txt"
MyFiles=open(savefile,"wb+")
MyFiles.write(LoggerScreen)
MyFiles.close()
# This function does the plotting and generates a text variable in CSV format.
# It also sets the timebase values as required, not implimented yet.
def doplot():
global horiz
global position
global savefile
global MyFiles
global LoggerScreen
global demo
global pause
global pausestring
global plot
global mybyte
global serialport
global grab
global csvdata
csvdata=""
horiz=1
while horiz<=64:
# Generate a byte as though grabbed from Arduino.
if demo==1: grab=int(random.random()*256)
# Generate a byte from Arduino.
if demo==0:
MyFiles=open(serialport,"rb",2)
mybyte=str(MyFiles.read(1))
MyFiles.close()
# Convert to a decimal value, assume 8 bit integer.
grab=ord(mybyte)
# Generate the 64 byte CSV string on the fly...
csvdata=csvdata+str(grab)+"\r\n"
# Convert to 4 bit depth.
plot=int(grab/16)
# Invert to suit the text display window.
plot=15-plot
if plot<=0: plot=0
if plot>=15: plot=15
# Set up the plot position per grab.
position=79+horiz+plot*79
MyFiles=open(savefile,"rb+")
MyFiles.seek(position)
MyFiles.write("o")
# Now get the whole array.
MyFiles.seek(0)
LoggerScreen=MyFiles.read(1659)
MyFiles.close()
# End of screen array update per plot.
# Wait for a period for none AMIGA platforms.
if sys.platform!="amiga": time.sleep(pause)
# time.sleep() does NOT work on an A1200, WinUAE and E-UAE so pause......
if sys.platform=="amiga":
pausestring=str(pause)
os.system("C:Wait "+pausestring)
# ......and then do a clear screen.
print "\f",
# Do a clear screen for other platforms.
if sys.platform=="linux2": print os.system("clear"),chr(13)," ",chr(13),
if sys.platform=="win32": print os.system("CLS"),chr(13)," ",chr(13),
# Now print the whole on screen...
print LoggerScreen
horiz=horiz+1
# This function saves a file to disk every 64 plots in CSV format.
def datafile():
global MyFiles
global filestr
global savefile
filestr=str(int(time.time()))+".CSV"
if sys.platform=="amiga": savefile="S:"
if sys.platform=="linux2": savefile="/tmp/"
if sys.platform=="win32": savefile="C:\\Windows\\Temp\\"
savefile=savefile+filestr
MyFiles=open(savefile,"wb+")
MyFiles.write(csvdata)
MyFiles.close()
# This is the main running code.
while 1:
# Set up DataLogger screen, use "\r\n" to suit Windows, "\r" is *ignored* on Linux and AMIGA_OS.
# This is for the default Command Prompt, (Windows), Terminal, (Linux) and CLI, (AMIGA), modes.
LoggerScreen="+-------+-------+-------+-------+-------+-------+-------+--------+ +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | |>(R)UN |\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"+-------+-------+-------+-------+-------+-------+-------+--------+ | Ctrl-C |\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | | (K)B |\r\n"
LoggerScreen=LoggerScreen+"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++ +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | | (S)LOW |\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +---------\r\n"
LoggerScreen=LoggerScreen+"+-------+-------+-------+-------+-------+-------+-------+--------+ +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | | 1(0)S |\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | +--------+\r\n"
LoggerScreen=LoggerScreen+"| | | | + | | | | |>(1)S |\r\n"
LoggerScreen=LoggerScreen+"+-------+-------+-------+-------+-------+-------+-------+--------+ +--------+\r\n"
LoggerScreen=LoggerScreen+"+----------------------------------------------------------------+ +--------+\r\n"
LoggerScreen=LoggerScreen+"| Status:- Running in DEMO mode. | | (U)NCAL|\r\n"
LoggerScreen=LoggerScreen+"+----------------------------------------------------------------+ +--------+\r\n"
# Save the startscreen to write to.
savescreen()
# Clear the screen every 64 plots and restart.
clrscn()
print LoggerScreen
# Grab the 64 plots.
doplot()
# Automatically save to disk when autosave is set to 1.
if autosave==1: datafile()
main()
# DataLogger program end.
# Enjoy finding simple solutions to often very difficult problems.
|
This is the second and final feeder/feeler upload only and if there STILL appears to be interest in it, (views and/or comments), then it WILL become a serious(ish) program proper.
All comments welcome...
Well, with over 450 VIEWS, (not downloads), in exactly the first 2 weeks, I am satisfied that some, assuming at least 5% of that figure, have a growing interest for me to continue further.
The code now includes AUTO-saving of the data is CSV format. To disable auto-saving change autosave=1 to autosave=0 and it will perform as before.
I am now experimenting in getting this to work on Python 3.x.x inside the same code too, so IF it is successful this will be the next upload, otherwise the next step will be some simple keyboard access...
See the code for the Python versions and machines this code has been tested on...
Enjoy finding simple solutions to often very difficult problems.
Bazza, G0LCU...
21-08-2012.
Although NOT coded for Apple OSX 10.7.3 hardware wise, the DEMO mode works for this platform on Python Version 2.7.1...
If you like what you see then I will carry on with this project.
Email:- wisecracker at tesco.net