image2x

Cloud Services overview

0

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

This is a cloud services overview. A brief audio intended to wet your interests to find out more.

 

Additional files at: https://bitly.com/bundles/jcoffey1138/1

An Arduino Project

Computer on a punch card

0

My latest Arduino excursion is the Paperduino Tiny. It is an eight pin package, the ATtiny85-20PU. It is an interesting circuit, laid out on a paper card and connected on the back with long leads and a few extra wires. It appears to be based on a small version of the Arduino family called Digispark.

You will be pointed to the digispark site for the IDE.

The instructions are set out for you to acquire all the components and assemble it, including burning the bootloader into the chip. I opted for the kit version offered on the site, but it appears the kit is no longer available.

If you decide to give it a try, go slow and use care.

My paperduino sketch, a mix of the fade and melody sketches, is posted on github.

My Paperduino project.

My Paperduino project.

 

 

 

 

 

 

 

 

The sketch

/*
 Fading
 
 This example shows how to fade an LED using the analogWrite() function.
 
 The circuit:
 * LED attached from digital pin 9 to ground.
 
 Created 1 Nov 2008
 By David A. Mellis
 modified 30 Aug 2011
 By Tom Igoe
 
 http://arduino.cc/en/Tutorial/Fading
 adapted to paperduino
 This example code is in the public domain.
 
 */
#define NOTE_C4  262
#define NOTE_G3  196
#define NOTE_A3  220
#define NOTE_B3  247

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };
  
int ledPin = 1;    // LED connected to digital pin 1
int ledPin2 = 0;   // LED connected to digital pin 0
void setup()  { 
  // nothing happens in setup 
  
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(4, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(4);
  }
} 

void loop()  { 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    analogWrite(ledPin2, fadeValue - 30); 
    
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    analogWrite(ledPin2, fadeValue - 30);    
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 
}


 

An Arduino Project

Musical Message Board

0

hi

My latest Arduino project is a lcd message board that plays a short tune on power up.

I used the 16×2 lcd with I2C communication and the tone() command.

It plays a few bars of the Little Mermaid tune when powered up and then begins cycling through a series of messages stored in an array. I have tried to explain it in the program comments.

The definition of the notes for the tone command are in an included file call pitches.h

Below is the program and a link to the files on github.

https://github.com/jcoffey42/Arduino/blob/master/project_2014_A002b

https://github.com/jcoffey42/Arduino/blob/master/pitches.h

 

/****************************************
 * project_2014)A002b
 * Use a arduino as a message board
 * Print the messages to a SainSmart IIC/I2C/TWI 
 * 1602 Serial LCD Module Display For Arduino
 * Play a short tune to get attention 
 ****************************************/

 /*
  I2C Connection
 *GND (ground)
 *VCC  (+5)
 *SDA  A4
 *SCL  A5
 */

/******************************
include libraries and declare initialize commands before void setup()
******************************/

// include the library code:
#include <Wire.h> //http://arduino.cc/en/reference/wire#.UyhwYflkTh4
#include <LiquidCrystal_I2C.h> // A version of the LCD library that allows I2C communication

/*
 * Library for LCD display //https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
 * see this for how to use https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
 * new LiquidCrystal is not needed but may be faster
 * Liquidcrystal library at http://arduino.cc/en/Reference/LiquidCrystal#.UyhwBvlkTh5
*/

/*
 *some settings for I2C that works with this LCD from 
 *http://www.amazon.com/review/R3JN683O0YUPAD/ref=cm_cr_pr_viewpnt#R3JN683O0YUPAD
 *define I2C variables for LiquidCrystal_I2C.h
 *Address of LCD (Sainsmat shows 0x3f but I found via 
 *http://arduino.arigato.cz/I2C_LCD_BackPack_for_1602_and_2004/LCD_16x2_BackPack_v003.ino it was 0x27
*/
#define I2C_ADDR 0x27 
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

//Initialize LCD
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

#include "pitches.h" // The tone description file

// notes in the melody:
int melody[] = {
  NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_D5, NOTE_D5, NOTE_F4, NOTE_C5, NOTE_DS5, NOTE_D5, NOTE_AS4,
  NOTE_AS3, NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_AS4, NOTE_C4, NOTE_A4, NOTE_C5, NOTE_AS4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  8, 8, 8, 4,4,8,4,4,4,4,8,8,8,4,4,8,4,4,4  };


void setup() {

  Serial.begin(115200); //setup serial communications for monitoring

  // set up the LCD's number of columns and rows: 
 
  lcd.begin (16,2,LCD_5x8DOTS);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
   
  // Iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 19; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    // initialize the digital pin as an output.
    }
 pinMode(led, OUTPUT);  
}
void loop() {
   // A guage to tell where you are in the messge display
   // Setup an array with the messge text for each line as a element of the array
  // 1234567890123456
  char* message[]={
    "Welcome to the ",
    "Arduino Badge",
    "message board",
    "It displays two ",
    "lines of text",
    "and sixteen ",
    "characters",
    "7",
    "8",
    "9",
    "10",
    "11",
    "12"};
/* Above is the message array. Add elements to increase messages displayed    
*/


int number = 10; // The number of message lines to display
for (int x=0; x < number; x++){
  Serial.println (message[x]); //Print message line #x to serial port
  
  lcd.clear();// clear LCD 
  lcd.setCursor(0, 0);  //cursor to top left of row 0
  lcd.print(message[x]);     // Print messge line  #x from array
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(300);
  lcd.setCursor(0, 1);  //cursor to top left of row 1
  lcd.print(message[x+1]);     // Print messge line #x+1 from array
    
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1500);
  }

  
}


 

 

Python Programming

def PythonNest():

0

Hi

I am embracing this programming language Python and the tutorial on twit, Coding 101.

My ongoing project is a menu driven program of the small versions I am making while learning. It is on github.

The current additions are an encode, decode pair of routines. It will create a file of numbers that are related to a specific key file of text. You must have the same key file to decode the message. I have a sample key file and secret message on github as well.

 

 

I will put the encode program here for your review. Get the one linked above and try it all.

 

 

# Created on a win8.1 system with IDLE
# project2014-P007.py
# A program to create a file of numbers that are the line and field for a
# sustitution code. You provide a text file to use as the key. You will use the same text file to decrypt the message.
# The original messge will never be written to a file.


# first lets define some things

KeyFileName = “c:\data\key.txt” #The name of the key file
Message = “c:\data\secretmessage.txt” # the name message file
Line = []
def Encode(word): # Start the function definitiion
Continue = True # Prime the while loop
LineCount = 0 # Prime linr counter
export = “” # used to build the code for one word
Working = [] # Holds the line of the key to scan

while Continue: # Start the loop
for line in record: # Get a line of the key file

Working= line.split(” “) # Split it upinto a list
LineCount = LineCount+1 # Increment LineCount
for x in range (0,len(Working)): # start the search loop
if word == Working[x]: # Look for a matching word
Continue = False # End the while loop
# Build the coded string for export
export = str(“{}|{}|\n”).format (str(LineCount),str(x))
print export # Print the encoded word for manual storage
output.write(export) # Add the encoded word to the message file
return # Stop the search and get another word.
else:
x = x+1 #Increment the word counter and check again
return # Exit if the end of file is reached, no encoded string will be printed

 

# Now lets open the files
record=open(KeyFileName,”r”) # Open the key file

output=open(Message,”w”) # Open the message file

ans = True # Prime ans to keep the input loop running

while ans: # This is the beginning of the input loop

# Get the message, one word at a time, to encode
print ” Enter the message one word at a time, no punctuation.”
word = raw_input(“What is the word to encrypt? press enter to end “)
try: # setup to handle entry errors

if len(word) > 0 : #test for a string
Encode(word) # Call the Encode function and pass the string word

elif len(word) == 0 : # If the length of word is 0, you must be done
print “Good Bye” # Be polite and say good by
ans = False # Set ans to False to end the input loop

else: # You shouldn’t get to here but if you did…
print “wrong answer”

except ValueError: # how to deal with a ValueError
print “oops, try again!”

record.close() # Close the key file.
output.close() # Close the secret message file.

 

 

 

 

Python Programming

Theres a python in my catalog!

0

Here is another program installment.
This one solves a need I had at work, taking a pipe delimited file from a library program and extracting the publication year, call number and title field to output as one pipe delimited line each. So it could be opened in excel .

I had to step outside the current commands talked about but I tried to stay close. Hope I added enough comments to make it clear what I am up to.

The file is 8500 line long and my first try only found 150. :(
I had tried to use with and had something wrong.
I finally settled on the “for Line in record:” to loop and that worked.

The file is on github.
There is also a file catalog2.txt.
that has two of the records for testing.
you will have to change the file locations to match where you have put the file.

Below is the program.

# Created on a win system with IDLE
# Practice python script project 2014-003.py

# A script to pull in an output file with pipe delimited values, with a varied number
# of items per Title record.
# list of unused title to create a smaller list of title with the format
# Publication Year | Call# | Title

# Open file for read only access, change the filename to your needs
record = open(“c:\data\catalog.txt”, “r”)

# Open a file for output, write access, change the filename to your needs
output = open(“c:\data\export.txt”,”w”)

# Setup the empty lists

Title = [] # The Title of the item(s)

T = int(0) # A counter for the end

Item = [] # The item ID of the item(s)

Callnumber = [] # The Call Number of the items(s)

C = int(0) # A counter for the Call numbers

Pubyear = [] # The Publication Year of the Title

Finished = [] # Used to put together the data for export

Working = [] # The entire input from one file read, split by “|”

# Setup loop to read through entire file for processing
# Loads a line of text from the object record into lineuntil the file end

for Line in record:

# Split the record into a list called working by the pipe symbol
Working = Line.split(“|”)

# Find the location of ITEM tags, not used at this time
for x in range(0,len(Working)):
if Working[x] == “ITEM>”:
Item.append(x)

# Find the location of the Call number tags
for x in range(0,len(Working)):
if Working[x] == “CALLNUM>”:
Callnumber.append(Working[x+1])# Load the Call number
C=C+1 # Totaling the call numbers

# Find the location of the Title tag
for x in range(0,len(Working)):
if Working[x] == “Title”:
Title.append(Working[x+1])# Load the Title
Pubyear.append(Working[x-2])# load the Publication year
T= T+1 # Totaling the titles

# Pack the finished list for each Callnumber in the record, may be one or more
for x in range(0,len(Callnumber)):
Finished.append(Pubyear)
Finished.append(Callnumber[x])
Finished.append(Title)

# Prepare the final output string for wrting
export = str(“{}|{}|{}|\n”).format(Finished[0],Finished[1],Finished[2])
output.write(export)# Write the one item to the files
Finished = []# Clear the list for the next item
Title = []# Clear the Title list
Pubyear = []# Clear the Publication year list
Callnumber = []# Clear the Call Number list
print “Processed #”,T # To indicate work is being done.
# Indicate count of processed records for quality control

print T,” Titles processed”
print C,” Call Numbers processed”

# Close the files and end

output.close()
record.close()

raw_input() # To keep the window open on gui systems

Go to Top
Google+