Welcome, guest | Sign In | My Account | Store | Cart

Hi experts...

A kids level project to do for yourselves...

This is a Python DEMO to show the power of the sound card using Linux for a specific usage that I need(ed). It is a kids level project that uses the sound card as a variable DC Voltage reference for projects like stabilised linear PSUs. Why linear? Relatively clean RF wise...

The TEST circuit is inside the code and is SOOO simple a dexterous 10 year old could make it in less than an hour and have it up and running to start using...

My own circuit is just as simple, isolated, and, gives me MUCH more voltage range than the one inside the code... How did I do it? ;o)

This is for Python 2.x.x, (probably even down to 1.5.2) but it would be just as easy to make it work on 3.x.x. I'll let the big guns do that...

Enjoy finding simple solutions to often VERY difficult problems...

Be aware of word wrapping etc...

Bazza, G0LCU...

Python, 83 lines
 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
# AC2DC.py
#
# This is a demo to show the power of the audio hardware under the
# influence of standard text mode Python.
#
# (C)2010, B.Walker, G0LCU. Now issued as Public Domain; you may do
# with this code as you please.
#
# Tested on PCLinuxOS 2009 and Debian 6.0.0 using Python 2.5.2, 2.6.6
# and 2.7.2; (it may well work on Python versions earlier than the
# above but it is untested).
#
# The device "/dev/dsp" is needed for this to work so you might have
# to install "oss-compat" from your distribution's repository...
#
# A very simple voltage doubler and passive filter TEST CIRCUIT ONLY...
# Best viewed in pure text mode.
# (Connect DC OUT & GND to a DC coupled oscilloscope to see it working.)
#
# Headset O/P. C1.             |\|D2.
#  O--------o--||--o-------o---| +---o-------o-------O +VE DC OUT.
#           |      |       |   |/|+  |       |
#  O       <       | +    <          |      <
#  |         >   --+--      >        | +      >
#  | * R1. <      / \ D1. <  R2.    === C2. <  R3.
#  |         >   +---+      >        |        >
#  |       <       |      <          |      <
#  |        |      |       |         |       |
#  +--------o------o-------o---------o---o---o-------O -VE.
#                                        |
# Parts List.                         ---+--- GND.
# -----------                         ///////
# C1 = 1.0 uF, 50V.
# C2 = 10 uF, electrolytic, 10V.
# R1 = 47 KilOhms, (* this can be ommitted).
# R2 = 1 MegOhm.
# R3 = 100 KilOhms.
# D1, D2 = OA90 or any similar germanium diode.
# 3.2 mm stereo jack plug for headset socket.
# Coaxial connecting cable.
# Sundries as required, stripboard, etc.

import os
# The running code...
def main():
	# Set globals, my choice... ;o)
	global waveform
	global value
	global count
	# Choose startup values...
	waveform=chr(0)+chr(0)
	value="(C)2010, B.Walker, G0LCU."
	count=0
	while 1:
		# Use the Linux system clear-screen command.
		os.system("clear")
		# A simple user screen...
		print "\nA DEMO variable AC to DC Generator using the sound card in Linux.\n"
		print "(C)2010, B.Walker, G0LCU; now issued as Public Domain...\n"
		value=raw_input("Input any integer from 0 to 255, [RETURN/ENTER] to Quit:- ")
		# Don't allow any errors...
		if value=="": break
		if len(value)>=4: value="255"
		count=0
		while count<=(len(value)-1):
			if value[count]>=chr(48) and value[count]<=chr(57): count=count+1
			else: value="255"
		if int(value)>=255: value="255"
		if int(value)<=0: value="0"
		# Create a symetrical triangle waveform with an amplitude of "value".
		print "\nOutput level value is "+value+"..."
		waveform=chr(0)+chr(int(value))
		# Generate this signal for about 10 seconds for this DEMO.
		if int(value)>=1:
			count=0
			audio=open("/dev/dsp", "wb")
			while count<=40000:
				audio.write(waveform)
				count=count+1
			audio.close()
main()
# End of AC2DC.py program.
# Enjoy finding simple solutions to often very difficult problems... ;o)

My requirement was a variable voltage reference for a specific use. My particular circuit is equally simple but completely isolated with a much bigger range.

To keep it simple for kids to build for themselves along with understanding simple electronics and basic Python coding I decided that NO ICs could be used, USB was a NO-GOer and other complex I/O was out of the question.

This left only the sound card for I/O and this DEMO was the result. My own code however has a lot more in it but that is mine. This DEMO is a starter "kit" to get kids thinking, writing code and building simple hardware to solve very difficult problems. Getting DC into the computer is equally simple and I might be uploading that too.

This is for the big guns to ridicule... ;o)

Enjoy finding simple solutions to often very difficult problems...

Bazza, G0LCU...

1 comment

Barry Walker (author) 12 years, 5 months ago  # | flag

To the person(s) who voted this up...

You know who you are...

Many thanks from me...

Bazza, G0LCU...