Tag Archives: Macbook Pro

Arduino Diecimila Board Access…

By wisecracker

This is a very simple starter DEMO to access Arduino Diecimila Board for the
Macbook Pro 13″ OSX 10.7.5…
A potentiometer is connected between 5V and Gnd with the wiper connected to
ANALOG IN 0 on the Arduino. This was adjusted to give the Ms and Ls as seen…

I now have DC in for this machine AND Linux too as on my Linux tools the device
becomes /dev/ttyUSB0 …

NOTE:- The device below is for MY machine and WILL be different for yours…

It is assumed that you have a Terminal up and running AND you have NOT
plugged in your USB Arduino Board yet…

Enjoy finding simple solutions to often very difficult problems…

Public Domain and you may do with it as you please…

Code:

Last login: Thu Jul 18 21:58:14 on ttys000
AMIGA:barrywalker~> # Find the USB device first.
AMIGA:barrywalker~> ls /dev/*usb*
ls: /dev/*usb*: No such file or directory
AMIGA:barrywalker~> # Now plug in the Arduino Diecimila Board...
AMIGA:barrywalker~> ls /dev/*usb*
/dev/cu.usbserial-A7007cvs /dev/tty.usbserial-A7007cvs
AMIGA:barrywalker~> # USE the /dev/cu.usbserial-A7007cvs device...
AMIGA:barrywalker~> cat < /dev/cu.usbserial-A7007cvs
MLMMLMMMMMMLMMMMLMLMMLLLLLLMLLMMMMMLMMMLMLLMLMLMMMMMMMMMMMLLMLLLMLLLLLLMLLLMLLM
MMMLMLLMLMMMLMMMMMLMLMLMLMMMLLLMMLLMMMMMMLLLMLLMMLMLLLLLMMMMLMLLLLMMMMMMMLLLMML
MMLMMMLLMLMLMLLMMMMLLLMLMMMMMLLMMLMMMLLMMMLLMMMMMMMMMMLLMLLLMMLLLMLMLMMLMMLMLML
MMMMMLLMMMMLLLLLLMMMMMMLLMLMMMMMLMMMLLMLMLMLLMLMLLLLMMMLMMLMMMMLMLMLMMLMMLMLMML
MLMLLLMLLLLLLMLLMMLMMMLMMMLMMLMLMMLMLMLMMLMLMMMLLLMLMLLLMMLLLMLMLMLLLLLLLMLMMML
LMcMMLLLLMLMMMMLMMMMMLMMLLMLMMMMMMLMLLMMMMMLMMMMLMLLMLMMMLLLMMMMMLLLMLMMLMLMMLM
MLMLLMLMMMMMLLLMMMMLLLMLMMLLMMLLMLLLMMMLLMMMLLMLLLLMMLLMMMMLLMMMMMLLLLLMMLLMMML
MLMMLLLMLLLLM^C
AMIGA:barrywalker~> _


The .PDE file for the Arduino as a test piece, this uses an early version of the
programming SW and I know it won’t compile on current versions so you will have
to modify slightly as required…

Code:

/* Using the Arduino as a DEMO single channel ADC for Windows (TM), Linux, */
/* AMIGA, WinUAE and now the Macbook Pro 13 inch OSX 10.7.5... */

/* Set up a variable for basic analogue input. */
int analogue0 = 0;

void setup() {
/* Open the serial port at 9600 bps. */
Serial.begin(9600);

/* Set the analogue voltage reference, DEFAULT is 5V in this case. */
analogReference(DEFAULT);
}

void loop() {
/* Read the 10 bit analogue voltage on analogue input 0. */
analogue0 = analogRead(0);
/* Convert to a byte value by dividing by 4. */
analogue0 = analogue0/4;

/* Send to the Serial Port the byte value. */
Serial.print(analogue0, BYTE);
}


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Use The Terminal To Test Arduino Is Working.

By wisecracker

Hi all…

(Apologies for any typos at all.)

This is a step by step _script_ to check if your Arduino is talking to your Linux or Macbook Pro computer using the Terminal…

It works on at least 3 Linux flavours and now the Macbook Pro

I hope you find it useful as a simple check for your Arduino setup…

This is issued as Public Domain.

The “Test.pde” is the code to program the Arduino with.
My Arduino programming SW is old and I am aware that the “Test.pde” script will not compile on current Arduino programming SW. I am assuming you will know what to do with it…

Code:

A basic, terminal, test sequence to check that the Arduino Diecimila board is _talking_ to your computer.

Step by step testing inside a Linux , OR, Macbook Pro Terminal usage for the USB Arduino Diecimila Board...
Issued as completely Public Domain by B.Walker, G0LCU, 2011-2013.

Common to both systems:-
------------------------

1) Boot up to your Linux flavour or Macbook Pro as root, (or run in a root Terminal).
2) Temporarily disable any net access or use a stand-alone machine.
3) Plug in the USB Arduino board.
4) Open up a, (root), Terminal and clear the screen.
5) clear

Linux flavours first:-
----------------------
6) Check that you have a device as ttyUSB?
IMPORTANT NOTE: Arduino boards are now detected as ttyACM? so although NOT tested this might still work...
If this is the case then replace ttyUSB? with ttyACM? below...

7) ls /dev
NOTE:- ? above will probably be 0.
8) If ttyUSB0, (to 7), appears then carry on; otherwise ignore the remainder of this text.

NOTE:- Assuming the device is ttyUSB0 from now on, change below if needed to your ttyUSBx device.
9) Place a wire link between ANALOG 0 and the 3.3 V terminals, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...

NOTE:- 'chmod' is probably not really needed but added for fullness!
10) chmod 666 /dev/ttyUSB0

11) Set up the on board serial I/O to 9600bps and RAW data transfer for PCLinuxOS and Debian.
12) stty -F /dev/ttyUSB0 1200
13) stty -F /dev/ttyUSB0 raw

14) Now start printing characters to the screen...
15) cat < /dev/ttyUSB0
NOTE:- The wire link characters will be from about 168 to 174 decimal allowing for bit error of the Arduino ADC.

16) Remove and replace the wire link from ANALOG 0 and GND or ANALOG 0 and 5 V too, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...
17) Press 'Ctrl-C' to stop any characters being printed to the Terminal.
18) Unplug the USB Arduino board.
19) Power down the computer IF REQUIRED.

Now the Macbook Pro:-
---------------------
6) Now find the device name, mine is tty.usbserial-A7007cvs, yours will probably be much different...

7) ls /dev
8) If you have a new tty* note its name then carry on, otherwise ignore the rest of this text.
(I will use my device name for this example.)

9) Place a wire link between ANALOG 0 and the 3.3 V terminals, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...

NOTE:- 'chmod' is probably not really needed but added for fullness!
10) chmod 666 /dev/tty.usbserial-A7007cvs

11) Now start printing characters to the screen...
(The command stty does NOT work for this on the Macnook Pro so revert to the command cu instead.)
12) cu -l /dev/tty.usbserial-A7007cvs -s 9600

13) Ctrl-C does not work so just close down the Terminal COMPLETELY.
14) Unplug tha Arduino board.
15) Power down the computer IF REQUIRED.

=============================================================

This is the "test.pde" code for the Arduino Diecimila board:-
-------------------------------------------------------------

/* Test.pde */
/* Using the Arduino as a DEMO single channel ADC for WinUAE. */
/* For use with AF2005 or greater. This is just demonstration code */
/* only and shows that I/O is possible through WinUAE by other means. */

/* Set up a variable 1 byte in size for basic analogue input. */
int analogue0 = 0;

void setup() {
/* open the serial port at 9600 bps. This rate is used for purely */
/* for simplicity only. */
Serial.begin(9600);

/* Set the analogue voltage reference, DEFAULT is 5V in this case. */
analogReference(DEFAULT);
}

void loop() {
/* Read the 10 bit analogue voltage on analogue input 0. */
analogue0 = analogRead(0);
/* Convert to a byte value by dividing by 4. */
analogue0 = analogue0/4;

/* Send to the Serial Port the byte value. */
Serial.print(analogue0, BYTE);

/* Delay 500 milliseconds before taking the next reading. */
delay(500);
}

=============================================================

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

Bazza, G0LCU...


Source: FULL ARTICLE at The UNIX and Linux Forums

The Start Of A Simple Audio Scope Shell Script…

By wisecracker

This is a DEMO shell script to generate a simple graticule and plot inside it…

Apologies for any typos…

it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope…

The fist upload I posted recently was to show how to animate colours, the second was to be able to manipulate a known bainary file to become a timebase and now this simple display…

The next upload will be a simple working unit using “/dev/dsp” for Linux through either the internal micrphone or the external mic input… The limitations of this device is that by default it samples at 8KHz, to 8 bit depth, mono, so don’t expect anything wondrous…

There is a FLAW in this DEMO. It is NOT a bug! What is it? ;o)

You need to know how the console or terminal works to find it…

Be aware of wordwrapping, etc…

Code:


# !/bin/sh
#
# AudioScopeDisplay.sh
#
# This method can also be used for a simple kids level Analogue Data_logger/Transient_Recorder
# Cannot use "setterm -cursor off" as Mac OSX 10.7.5 has not got "setterm", thought of another way for the Macbook Pro... ;o)
#
# $VER: AudioScopeDisplay.sh_Version_0.00.01_Public_Domain_B.Walker_G0LCU.

display()
{
clear
graticule="+-------+-------+-------+-------+-------+-------+-------+--------+n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"| | | | + | | | |n"
graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+n"
printf "$graticule"
}

while true
do
display
for horiz in {2..65}
do
# Simulate an 8 bit grab and divide by 16 to give 4 bit depth. Add offset of 2 to allow
# for mssing the top graticule line...
vert=$[ ( $RANDOM % ( 256 / 16 ) + 2 ) ]
# There IS a FLAW here at _printf_, NOTE, not a bug! What is it? ;o)
printf "x1B["$vert";"$horiz"fo"
# Slow it down so you can see it working...
sleep 0.05
done
printf "x1B[20;1f"
sleep 1
done


Enjoy finding simple solutions to often very difficult problems… ;o)

Bazza, G0LCU…

Source: FULL ARTICLE at The UNIX and Linux Forums

Python, Platform Independent, Pure Audio Sinewave Generator…

By wisecracker

IKHz_SW_OSX.py

A DEMO mono _pure_ sinewave generator using standard text mode Python 2.6.7 to at least 2.7.3.

This code is EASILY modifyable to Python version 3.x.x…

This DEMO kids level 1KHz generator is mainly for a MacBook Pro, (13 inch in my case), OSX 10.7.5 and above. See below…

It is a simple piece of testgear for the young amateur electronics enthusiast and uses pyaudio fully installed for it to work.

PyAudio pointer can be obtained from inside the comments in the code…

Macbook Pro hardware earphone plug modifications pointer inside the code too…

(I am not sure if the moderators will delete those lines from the code so search the WWW instead if they are…)

This was primarily for a MacBook Pro 13 inch, but works on at least 2 Linux flavours and Windows Vista 32 bit…

The sinewave generated is near excellent…

Enjoy finding simple solutions to often very difficult problems… Bazza, G0LCU…

(This was uploaded elsewhere and has had a lot of hits.)

Issued as GPL3…

Code:

# 1KHz_SW_OSX.py
#
# A mono _pure_ sinewave generator using STANDARD text mode Python 2.6.7 to at least 2.7.3.
# This DEMO kids level 1KHz generator is mainly for a MacBook Pro, (13 inch in my case), OSX 10.7.5 and above.
# It is another simple piece of testgear for the young amateur electronics enthusiast and
# uses pyaudio fully installed for it to work. Enjoy... ;o)
# PyAudio can be obtained from here:- http://people.csail.mit.edu/hubert/pyaudio/
#
# It also works on Windows Vista, 32 bit, on various machines with Python 2.6.x to 2.7.3.
# It also works on Debian 6.0.0 using Python 2.6.6 on an HP dv2036ea notebook.
# It also works on "Ubuntu 12.04, Python 2.7, Dell built-in soundcard", with many thanks to Hubert Pham, author
# of pyaudio itself, for testing...
#
# The hardware modifictions can be found here:-
# http://code.activestate.com/recipes/578282-for-macbook_pro-heads-only-simple-lf-audio-oscillo/?in=lang-python
#
# Ensure the sound is enabled and the volume is turned up. Use the volume control to vary the amplitude...
#
# Copy the file to a folder/drawer/directory of your choice as "1KHz_SW_OSX.py" without the quotes.
#
# Start the Python interpreter from a Terminal/CLI window.
#
# To run the sinewave generator, (depending upon the platform), just use at the ">>>" prompt:-
#
# >>> execfile("/full/path/to/1KHz_SW_OSX.py")
#
# And away you go...
#
# This code is issued as GPL3...
#
# Connect an oscilloscope to the earphone socket(s) to see the sinewave waveform(s) being generated.
#
# $VER: 1KHz_SW_OSX.py_Version_0.00.10_(C)2012_B.Walker_G0LCU.

# The only import required...
import pyaudio

# Initialise the only _variable_ in use...
n=0

# Set up a basic user screen...
# This assumes the minimum default 80x24 Terminal window size...
print("nnnnnnnnnnnnnnnnnnnnnnnnn$VER: 1KHz_SW_OSX.py_Version_0.00.10_(C)2012_B.Walker_G0LCU.n")
print("A DEMO kids level, platform independent, 1KHz _pure_ sinewave generator.nnnnnnnnnnnnnnnnnn")

# Open the stream required, mono mode only...
stream=pyaudio.PyAudio().open(format=pyaudio.paInt8,channels=1,rate=16000,output=True)

# Now generate the 1KHz signal at the speakers/headphone output for about 10 seconds...
# Sine wave, to 8 bit depth only...
for n in range(0,10000,1): stream.write("x00x30x5ax76x7fx76x5ax30x00xd0xa6x8ax80x8axa6xd0")

# Close the open _channel(s)_...
stream.close()
pyaudio.PyAudio().terminate()

# End of 1KHz_SW_OSX.py program...
# Enjoy finding simple solutions to often very difficult problems... ;o)


Source: FULL ARTICLE at The UNIX and Linux Forums

At A Glance Coloured Real Time Bargraph Generator…

By wisecracker

Not sure if anyone is interested but I am just getting into UNIX like shell scripting…

I have great interest in pseudo-animations in text mode and accessing HW like /dev/dsp for example…

All the information is inside the code and this has been uploaded to code.activestate.com…

Have fun, I do… ;o)

Code:


# !/bin/sh
#
# Bargraph_Generator.sh
#
# A DEMO 6 bit coloured bargraph animation for a default Bash and Terminal window on OSX 10.7.5...
# A simple Shell script to display an _AT_A_GLANCE_ real time analogue bargraph generator. It
# starts off with GREEN for OK, then YELLOW for warning and finally ending with RED for danger
# with a critical beep for values 61 to 63 inclusive.
# It assumes an 8 bit value being injected into the script which is then divided by 4 to give
# a 6 bit value which is 64 spaces width inside the Terminal. The DEMO uses a random number
# generator to give a representation of an 8 bit value so you can see it working...
#
# A shell derivative of my Python code:-
# http://code.activestate.com/recipes/577612-seven-bit-colored-analogue-bar-graph-generator-dem/?in=user-4177147
#
# To run, ensure the script is executable and change if required, then type from a Terminal:-
#
# xxxxx$ /full/path/to/Bargrapth_Generator.sh
#
# And away you go...
#
# Written in such a way that kids and newbies can understand what is going on.
#
# Originally written for a Macbook Pro 13 inch, OSX 10.7.5 using the default Terminal.
# It MIGHT work on some Linux variants but WAS intended for MacOS OSX 10.7.x and above only.
#
# The Terminal colours WILL be changed to Black background and Various foreground colours.
# It will NOT be returned back to its original state although it can be easily. If you
# need to rerturn back to default state then there are a couple of easy methods the
# simplest being type:-
#
# xxxxx$ reset
#
# And all will be corrected...
#
# Issued entirely as Public Domain and you may do with it as you please
#
# $VER Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.
#
# Enjoy finding simple solutions to often very difficult problems...

# The required _varibales_ for ease of coding, these are the colours...
# White On Black.
WOB="x1B[1;37;40m"
# Black On Green.
BOG="x1B[1;30;42m"
# Black On Yellow.
BOY="x1B[1;30;43m"
# Black On red.
BOR="x1B[1;30;41m"
# Green On Black.
GOB="x1B[1;32;40m"
# Yellow On Black.
YOB="x1B[1;33;40m"
# Red On Black.
ROB="x1B[1;31;40m"

# Set the pseudo 6 bit value to zero.
SIX_BIT_DEPTH=0

# Do a clear screen to White On Black.
printf $WOB
clear

while true
do
# Set up the screen per scan and prepare for the bargraph.
clear
printf $WOB"n $VER: Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.nn"
printf " A horizontal, at a glance, coloured, analogue bargraph display forn"
printf " a default Terminal inside OSX 10.7.5..nnnnn"
printf " 0 10 20 30 40 50 60"
printf $GOB"n +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--n"
printf $GOB" (| "$ROB")n"
printf $GOB" +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--nnnn"
# If the 6 bit value is 0, zero, do no more until printing the 6 bit value and generating another 6 bit value...
# Anything greater than or equal to 1 enters this conditional branch.
if [ "$SIX_BIT_DEPTH" -ge "1" ]
then
# If the 6 bit value is less than or equal to 46 then _plot_ the green section only.
# The 'x1B[12;8f' is the ANSI 'Esc' code that forces the print position to 12 lines by 8 columns.
if [ "$SIX_BIT_DEPTH" -le "46" ]
then
BARGRAPH=$GOB"x1B[12;8f("$BOG
for green in $(seq 1 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
# If the 6 bit value is greater than or equal to 47 then print the green section and _plot_ the yellow section.
if [ "$SIX_BIT_DEPTH" -ge "47" ]
then
BARGRAPH=$GOB"x1B[12;8f("$BOG" "$BOY
for yellow in $(seq 47 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
# If the 6 bit value is greater than or equal to 57 then print the green and yellow section and _plot_ the red section.
if [ "$SIX_BIT_DEPTH" -ge "57" ]
then
BARGRAPH=$GOB"x1B[12;8f("$BOG" "$BOY" "$BOR
for red in $(seq 57 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
printf "$BARGRAPH"$GOB"nnnnn"
fi
# When the 6 bit value is greater than or equal to 61 sound a system error beep.
if [ "$SIX_BIT_DEPTH" -ge "61" ]
then
printf "a"
fi
# Print the 6 bit value in White On Black...
printf $WOB" Random number generated "$SIX_BIT_DEPTH"...nn"
printf " Press Ctrl-C to stop the program...nn"
# Generate another 6 bit value as though from an 8 bit value...
SIX_BIT_DEPTH=$[($RANDOM % (256/4))]
# A practical lower limit for the sleep command is 'sleep 0.05'...
sleep 1
done

# End of Bargraph_Generator.sh DEMO.
# Enjoy finding simple solutions to often very difficult problems... ;o)


Source: FULL ARTICLE at The UNIX and Linux Forums