Warning: Cannot modify header information - headers already sent by (output started at /home/jchigh2/public_html/wp-content/plugins/twitter/widget_twitter_vjck.php:171) in /home/jchigh2/public_html/wp-includes/feed-rss2.php on line 8
Highlightpro | Highlightpro http://www.jchighlightpro.com Projects from Highlightpro Tue, 29 Jan 2013 12:43:12 +0000 en-US hourly 1 http://wordpress.org/?v=3.6 Relay Controller http://www.jchighlightpro.com/2012/12/31/relay-controller/ http://www.jchighlightpro.com/2012/12/31/relay-controller/#comments Tue, 01 Jan 2013 01:57:22 +0000 highlightpro http://www.jchighlightpro.com/?p=95 I have been working on expanding the output of the raspberry pi to control this relay board I ordered from Amazon. I have successfully operated a single 8 port board through a shift register on a bread board straight through the Raspberry Pi.

According to the documentation, the 5v power supply for the relay board requires 400ma for all 8 on. This might cause the Pi to reset or possibly blow a fuse if we were to push it any harder. If I plan on adding any additional relay boards, I need to find another way to power it.

It looks like the 3.3v inputs on the relay only require 0.18ma so it should be ok to power that directly from the GPIO output.

Daisy chaining the shift registers was actually very easy and on the breadboard I was able to control 16 leds using the shift register class I posted previously.

The next step is making it a little more permanent. The top of the board has a 6 pin male header for the input and power to the shift register chips; +3.3v, SER, OE, RCLK, SRCLK, GND. The two port connector is for external 5v power supply that will be routed through the output header to the relay boards.

Running two shift registers in parallel I had a lot of flickering on the leds. Following the Arduino Tutorial recommendations, I used a small cap to even out the latch pin.

Top of the shift register output expander prototype.

Top of the shift register output expander prototype.

I tried to keep the top nice and clean but, that meant the bottom is an ugly mess.

Messy wires on the underside of the proto board

Messy wires on the underside of the proto board

This is my first experience mounting electronics so I did get turned around on the input pins. I had everyone of them backwards and they had to be desoldered and moved. Luckily, I caught it before I applied any power. I hooked it up to a few leds and it worked!

Next I need to try it with an external 5v power supply to see if I can make it control a relay board.

]]>
http://www.jchighlightpro.com/2012/12/31/relay-controller/feed/ 0
Guitar Complete http://www.jchighlightpro.com/2012/12/31/guitar-complete/ http://www.jchighlightpro.com/2012/12/31/guitar-complete/#comments Tue, 01 Jan 2013 00:35:42 +0000 highlightpro http://www.jchighlightpro.com/?p=86 Finally finished the 3/4 scale guitar for my son, just in time for Christmas. He still has a few years before he will be big enough to actually play it but, it seems everyone in the family was getting a guitar this year and we couldn’t leave him out.

3/4 scale guitar completly finished

3/4 scale guitar completly finished

The sunburst effect turned out to be pretty easy just free handing it with the spray paint. Originally, I tried doing it with the wood dye but I couldn’t get it dark enough.

After several coats of lacquer and wet sanding, I buffed it with Scratch-X before finishing it off with regular car wax.

I snapped one of the strings the first time I tried to string it. All I had on had where some acoustic strings but they will work for now.

When I first assembled the electronics, you could hear a lot of static in the onboard speaker. I am pretty sure I had a loose ground wire. After playing with it for a while, it went away. I guess I’ll worry about it if/when it comes back.

Playing it through an external amp, it actually sounds pretty good. It needs some work getting it setup. Right now the strings are too high and the truss rod probably needs to be adjusted.

Overall this was a very satisfying project.

 

]]>
http://www.jchighlightpro.com/2012/12/31/guitar-complete/feed/ 0
Raspberry Pi Shift Register Model http://www.jchighlightpro.com/2012/10/25/raspberry-pi-shift-register-model/ http://www.jchighlightpro.com/2012/10/25/raspberry-pi-shift-register-model/#comments Fri, 26 Oct 2012 02:52:53 +0000 highlightpro http://www.jchighlightpro.com/?p=73 I purchased a set of 74HC595 shift registers from Adafruit. This was my first experience doing anything with an IC so I wasn’t sure what to expect. With some help from a real engineer, I figured out the pin pattern and was able to build a php model to make it all work.

Let’s start with a simple LED example on the breadboard.
File: shift_register_model.php

<?php
/*
* Shift Register Model.
*
* This file has all the methods required for using a shift register with the Raspberry Pi
*
* PHP 5
* Copyright 2012, J.C. Highlight Productions (http://jchighlightpro.com)
*
* Licensed under The GNU GPL
* This  program  is  free  software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the  Free Software Foundation; either version 3 of the License, or (at your
		* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* @copyright     Copyright 2012, J.C. Highlight Productions (http://jchighlightpro.com)
* @link          http://www.jchighlightpro.com/home-automation/
* @license       GNU GPL License (http://www.gnu.org/licenses/gpl.html)
*/
class shift_register_model extends gpio_model{

	var $_serPin;
	var $_oePin;
	var $_rclkPin;
	var $_srclkPin;
	var $_bits;

	var $_current_state;

	function __construct($bits, $serPin,$oePin,$rclkPin, $srclkPin){
		$pins = array($serPin=>'out', $oePin=>'out',$rclkPin=>'out',$srclkPin=>'out',);
		echo("\nShift Register Loading...");
		parent::__construct($pins);

		$this->_bits			= $bits; // How many bytes can the shift register handle
		$this->_serPin			= $serPin;
		$this->_oePin			= $oePin;
		$this->_rclkPin			= $rclkPin;
		$this->_srclkPin 		= $srclkPin;
		$this->_current_state	= 0; //initialize to all off

		echo("Done\n");

		//echo("serPin: ".$this->_serPin." oePin: ".$this->_oePin." rclkPin: ".$this->_rclkPin." srclkPin: ".$this->_srclkPin."\n");
	}

	/**
	 * Takes a number and shifts it through the dataPin. Must be less than or equal to the total bits the shift register will allow.
	 * @param int $number
	 */
	function shift_out($number){

		$this->set_value($this->_rclkPin, LOW);		// make sure the clock lines are in the correct state, make no assumptions.
		$this->set_value($this->_srclkPin, LOW);

		$bin_num = decbin($number);

		for($i=0;$i_bits;$i++){
			$comp_val = pow(2,$i);
			if(($number & $comp_val) == $comp_val)  { $this->pulse_data(HIGH); } else{ $this->pulse_data(LOW); }
		}

		$this->set_value($this->_rclkPin,HIGH); 	// latch shift registers to the outputs.
		$this->set_value($this->_rclkPin, LOW); 	// Just for clean up.

		echo("\n");
	}

	/**
	 * Brings clock pin high, sets data pin to $value, brings clock pin low.
	 * @param int $value
	 */
	function pulse_data($value){

		echo($value);
		$this->set_value($this->_serPin,$value);	// 0 or 1
		$this->set_value($this->_srclkPin,HIGH);	// data is read on the positive clock edge.
		//usleep(50000);							// got to let the data line settle. temp included in set_calue
		$this->set_value($this->_srclkPin,LOW);		// set the clock back for next bit
	}

	/**
	 * Brings the oePin High which will disable the output on the shift registers.
	 */
	public function disable_outputs(){
		$this->set_value($this->_oePin,HIGH);
	}

	/**
	 * Brings the oePin Low which will enable the outputs.
	 */
	public function enable_outputs(){
		$this->set_value($this->_oePin,LOW);
	}

	/**
	 * Change the state of a pin.
	 * @param int $pin
	 * @param constant $state HIGH or LOW
	 */
	public function set_pin($pin,$state){

		if($state == HIGH){
			$this->_current_state = $this->_current_state | pow(2,$pin); //or
		}
		else{
			$this->_current_state = $this->_current_state ^ pow(2,$pin); //xor
		}
		$this->shift_out($this->_current_state);
	}
}
?>

This depends on the GPIO model I posted earlier and should be able to support any number of output channels on daisy chained shift registers.

The first step is to initialize the model. There are 5 parameters. The first is the number of bits the shift register array can handle. In this case we are just using one 8 channel shift register. The next is SER or the serial pin. This is the data pin and we are using GPIO4. Next, OE is the Output Enable pin – GPIO22. When it is HIGH, the output is disabled. Low enables the output. Technically, the OE pin can be shorted to 3.3v if you have to save a pin and don’t mind not being able to turn the outputs on or off.

The RCLK is the storage register clock – GPIO21. SRCLK is the serial register clock – GPIO17.

$shiftr = new shift_register_model(8,4,22,21,17); //numb_bits, SER, OE, RCLK, SRCLK

There are two main ways to use the shift register class. The first is using the shift_out function to set the binary value of the integer you pass to the functions

Ex:

$shiftr->shift_out(45);

File: shift_reg_test.php

#!/usr/bin/php -q
<?php 

include("gpio_model.php");
include("shift_register_model.php");

define("HIGH", 1);
define("LOW", 0);

$shiftr = new shift_register_model(8,4,22,21,17); //numb_bits, SER, OE, RCLK, SRCLK

$shiftr->set_pin(4, HIGH);
sleep(1);
$shiftr->set_pin(2, HIGH);
sleep(1);
$shiftr->set_pin(0, HIGH);
sleep(1);
$shiftr->set_pin(7, HIGH);
sleep(1);
$shiftr->set_pin(2, LOW);

for($i=0;$i<255;$i++){
	$shiftr->shift_out($i);
	echo("Step $i Complete\n");
	sleep(1);
}
?>

To get more outputs you can daisy chain more than one shift register. Wire everything together just like you did for the first shift register except use the Qh’ pin from the first register as your input to the serial pin of second register.

I am working on a circuit diagram on circuits.io. Take a look at my project: Raspberry Pi Digital Output Expander

]]>
http://www.jchighlightpro.com/2012/10/25/raspberry-pi-shift-register-model/feed/ 1
Raspberry Pi – PHP GPIO Model http://www.jchighlightpro.com/2012/10/17/raspberry-pi-php-gpio-model-2/ http://www.jchighlightpro.com/2012/10/17/raspberry-pi-php-gpio-model-2/#comments Wed, 17 Oct 2012 22:59:08 +0000 highlightpro http://www.jchighlightpro.com/?p=65 I finally have the php Raspberry Pi GPIO Model in a decent state and I though I would share.  eLinux.org has a simple example using bash that I was able to use to build the php model. I replaced the shell commands with direct php writes for the pins and it runs much faster.

File: gpio_model.php

<?php
/*
 * GPIO Model.
 *
 * This file has all the methods required for accessing GPIO pins for the Raspberry Pi
 *
 * PHP 5
 * Copyright 2012, J.C. Highlight Productions (http://jchighlightpro.com)
 *
 * Licensed under The GNU GPL
 * This  program  is  free  software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the  Free Software Foundation; either version 3 of the License, or (at your
 * option) any later version. This program is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * @copyright     Copyright 2012, J.C. Highlight Productions (http://jchighlightpro.com)
 * @link          http://www.jchighlightpro.com/home-automation/
 * @license       GNU GPL License (http://www.gnu.org/licenses/gpl.html)
*/

class gpio_model{

	private $_base_path;
	private $_mapped_pins;
	private $_write_delay; // for usleep functions, No longer used.

	/**
	 * Construct that sets up the gpio interface. Uses mapped pins and executes exports through cli.
	 * @param array $mPins map of pins to direction example:$mPins = array(22=>"in",17=>"out",4=>"out");
	 * @param string $path path to the gpio file structure "/sys/class/gpio"
	 */
	public function __construct($mPins = false, $path = "/sys/class/gpio"){
		if($mPins!=false){
			$this->_base_path  = $path;
			$this->_mapped_pins = $mPins;
			$this->_write_delay = 500; 

			foreach($this->_mapped_pins as $pin => $direction){
				$this->activate_pin($pin);				//activate each of the pins we are setting up
				$this->set_direction($pin,$direction);	//set initial direction
			}
		}

	}

	/**
	 * Returns an array of active pins
	 * @return array:
	 */
	public function get_pins(){
		return $this->_mapped_pins;
	}

	/**
	 * Activates specific pin
	 * @param int $pin actual pin number
	 */
	public function activate_pin($pin){
		$this->write($this->_base_path."/export", $pin);//export sets up the directories
	}

	/**
	 * set_direction writes the appropriate direction to the GPIO file path
	 * @param string $direction "in" or "out"
	 */
	public function set_direction($pin, $direction){
		$this->write($this->_base_path."/gpio".$pin."/direction", $direction);
	}

	/**
	 * Set the pin to the specific value. Value is defined as HIGH, LOW
	 * @param int $pin
	 * @param constant $value HIGH or LOW
	 */
	public function set_value($pin, $value = LOW){
		$this->write($this->_base_path."/gpio".$pin."/value", $value);
		//usleep($this->_write_delay);
	}

	/**
	 * Removes the directory structure for the specific pins
	 * @param int $pin
	 */
	public function remove_pin($pin){
		$this->write($this->_base_path."/unexport", $pin);//export sets up the directories
	}

	/**
	 * Get the current value of the pin specified
	 * @param int $pin
	 * @return number
	 */
	public function get_value($pin){
		return $this->read($this->_base_path."/gpio".$pin."/value"); // do we need to flip the bit? Should we look HIGH or LOW
	}

	/**
	 * Get status from all predefined pins in the $this->_mapped_pins array
	 * @param string $type Can be json or array
	 * @return string/array
	 */
	public function get_status_all($type="array")
	{
		$data = array();

		foreach($this->_mapped_pins as $pin => $value)
			$data[$pin] = $this->get_status($pin);

		if($type=="json"){
			return json_encode($data);
		}
		elseif($type=="array"){
			return $data;
		}
	}

	/**
	 * Loops through each of the mappedPins and unexports them.
	 */
	function __destruct() {
		foreach($this->_mapped_pins as $pin => $direction){
			$this->remove_pin($pin);				//unexport the gpio directories
		}
	}

	////////////////////// Lower level functions /////////////////////////////

	public function read($path)
	{
		//read the contents of the file
		return file_get_contents ($path);
	}

	public function write($path, $value)
	{
		// Write the contents back to the file
		file_put_contents($path, $value);
	}

	////////////////////////// Test Functions ///////////////////////////////
	public function all_on()
	{
		foreach ($this->_mapped_pins as $pin => $value){
			$this->set_value($pin, HIGH);
		}
	}

	public function all_off()
	{
		foreach ($this->_mapped_pins as $pin => $value){
			$this->set_value($pin, LOW);
		}
	}

	public function test($delay = 1)
	{
		foreach ($this->_mapped_pins as $pin => $value)
		{
			$this->set_value($pin, HIGH);
			sleep(1);
			$this->set_value($pin, LOW);
		}

	}
}
?>

Now we just need to test it out. Using PHP CLI as root:

File: test.php

#!/usr/bin/php -q
'out',17=>'out',21=>'out',24=>'in');

$gpio = new gpio_model($pins);

//Write to individual pin
$gpio->set_value(4,HIGH);

//Read Pin
$pin_24_value = $gpio->get_value(24);

//loop through pins
for($i=0;$i<100;$i++){ 	
	foreach($pins as $key => $value){
		$gpio->set_value($key,HIGH);
		sleep(1);
	}
	foreach($pins as $key => $value){
		$gpio->set_value($key,LOW);
		sleep(1);
	}
}

?>

I’d like to find a way to use this without being root. If anyone has any ideas, please let me know.

I hope someone will find this useful. Let me know what you think.

]]>
http://www.jchighlightpro.com/2012/10/17/raspberry-pi-php-gpio-model-2/feed/ 0
Raspberry Pi http://www.jchighlightpro.com/2012/10/03/raspberry-pi/ http://www.jchighlightpro.com/2012/10/03/raspberry-pi/#comments Thu, 04 Oct 2012 01:17:39 +0000 highlightpro http://www.jchighlightpro.com/apps/wordpress/?p=47 I purchased a Raspberry Pi this summer but I wasn’t sure exactly what I wanted to do with it. A couple of weeks ago I finally found the inspiration I was looking for when I ran across someone using a Pi to control his sprinkler system.

The site seems to be down at the moment but in case it comes back up here is a link http://badgerbooth.com/

I purchased the Pi Cobbler Breakout kit from Adafruit. (http://www.adafruit.com/products/914) and have successfully been able to turn LEDs on and off with bash and using the GPIO php script from Badger Booth.

I think I’ll rewrite the php model to clean up some of the initialization. Once I get it working well enough, I’ll post it here.

20121003-134044.jpg

]]>
http://www.jchighlightpro.com/2012/10/03/raspberry-pi/feed/ 0
More Guitar Progress http://www.jchighlightpro.com/2012/08/20/more-guitar-progress/ http://www.jchighlightpro.com/2012/08/20/more-guitar-progress/#comments Mon, 20 Aug 2012 21:59:11 +0000 highlightpro http://www.jchighlightpro.com/apps/wordpress/?p=43 I made a little more progress on the guitar this weekend. Two coats of gloss and some black dye on the edges. Still need some work before the next coat.

20121003-140901.jpg

]]>
http://www.jchighlightpro.com/2012/08/20/more-guitar-progress/feed/ 0
Guitar Progress Photos http://www.jchighlightpro.com/2012/07/25/guitar-progress-photos/ http://www.jchighlightpro.com/2012/07/25/guitar-progress-photos/#comments Wed, 25 Jul 2012 14:02:31 +0000 highlightpro http://www.jchighlightpro.com/apps/wordpress/?p=30 Here are some photos from the build process. I’m trying to find some good photos where it is complete.

IMGP7157 IMGP7158 IMGP7174 IMGP7188 IMGP7190 IMGP7192 IMGP7195 IMGP7196 IMGP7168a

 

]]>
http://www.jchighlightpro.com/2012/07/25/guitar-progress-photos/feed/ 0