Help needed: Building an LED Scanner (Knight Rider style)

thansen090

New Member
Hello all. I'm new to PICAXE and don't have a lot of experience with electronics. Please go easy on me. :) I found out about PICAXE in Nuts+Volts magazine and it seemed like a great system for my rather basic projects.

I'd like to build an LED scanner for my car. I couldn't find a commercial unit available of the right size or resolution, so I figured I'd build my own. I'm finding there are several ways to go about this so I wanted to get some feedback before I invest in parts. I'm a little disappointed there isn't more info about "Knight Rider" scanners. Using 8-16 LEDs, yes, but I want to use 64. Any help/links would be greatly appreciated.

I recently discovered addressable RGB LEDs. These seem ideal for a project like mine. The initial cost for the LEDs would be a little higher but these would pay for themselves through savings elsewhere. I've only seen some basic info on these. I'd like to know how these are wired and programmed. Pros and cons?

My original plan was to use 16 outputs from a 28X2 to control the 64 LEDs. (8 groups of 8 LEDs) Yes, I looked into Charlieplexing but I want to be able to turn on all the LEDs at once. Multiplexing like this is still worth studying but I'm hoping the addressable LEDs make this plan obsolete.

My last obstacle is figuring out how to power all this. I can build a 7805-based power supply but that won't be enough to power all 64 LEDs at once. I need a higher capacity 12v(car)-5v power supply. Suggestions?

Thanks for your help!!!
 

BESQUEUT

Senior Member
My last obstacle is figuring out how to power all this. I can build a 7805-based power supply but that won't be enough to power all 64 LEDs at once. I need a higher capacity 12v(car)-5v power supply. Suggestions?

Thanks for your help!!!
Maybe a step-down converter :
DC-Step-Down-Converter-DC-4-0-38V-to-1-25V-36V-5A-75W
12A-200W-Adjustable-DC-DC-Step-Down-Converter-Buck-Module-4-5-30V-
5A-DC-DC-Adjustable-Step-Down-Module-Power-Supply-Converter-1-25-36V
PS : do you want unicolor or multicolor "scanner" ?
 

premelec

Senior Member
Welcome to the forum... without complete information on how fast you want to scan etc it's hard to know just what to recommend - however the APA102 RGB units are easy to drive [once you understand what they require!] and very bright - indeed a step down converter to 3 amps ought to do the job for very bright strings. I'm running some on a lithium 3.7 volt battery. If you search this forum you'll find some example code. Have you got experience writing programs? Different PICAXEs have different output capability - and might determine how you drive the APA102s - I'm using some old 08M [255 byte memory!] units with simple two wire bit banged signals [data & clock]. Not very fast but fast enough for my use... Commonly strings are 60 pixels - take a look at youtube for various APA102 capabilities and effects and see if they may suit you...
 

Bill.b

Senior Member
The schematic below is part of an installation where is have used the APA 102 LED strip of 60 LEDS.

The program is for a kit style scanner based on the example programs supplied by technical.

This may be of some help

apa102 driver.jpg

Code:
#picaxe 28x2
#no_table
#no_data
setfreq em32
; drop LED Strip light control
;
;         28X2                 5V -.-   Light strip
;     .-----__-----.                |
;     | RST    B.7 |                `-->  +V
;     |            |  .--> SCK -------->  CK
;     | C.2    C.5 |--|--> SDO -------->  DI
;  .--| C.3    C.4 |  |             .-->  0V
;  |  |            |  |         0V _|_
;  |  `------------'  |
;  `------------------'

; Set how many LED modules in the strip
Symbol HOW_MANY_LEDS = 60
`
Symbol HOW_MANY_LEDS_MINUS_1 = HOW_MANY_LEDS - 1
Symbol HOW_MANY_LEDS_TIMES_3 = HOW_MANY_LEDS * 3

; Set the maximum brightness of the LED while testing
; Use small values to keep current consumption low
Symbol MAX_BRIGHTNESS = 31 ; 0 to 255 (full)

; Initialise the HSPI interface
#macro init()
  hspisetup spimode00, spifast
#endmacro

; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
  hspiout( n1, n2, n3, n4 )
#endmacro

; Send the start of data header
#macro head()
  sendPacket( $00, $00, $00, $00 )
#endmacro

; Send a LED controlling command
#macro send( red, green, blue)
  sendPacket( $FF, blue, green, red )
#endmacro

; Send the end of data tail
#macro tail()
  sendPacket( $FF, $FF, $FF, $FF )
#endmacro

PowerOnReset:

  ; Initialise the HSPI interface
  init

  ; Turn all LED modules off
  head
  for w0 = 1 To HOW_MANY_LEDS
    send( $00, $00, $00 ) ; 1 to last = Off
  next
  tail

BounceLed:
  ; Set three LED at a time
  ; 'w0' indicates which LED to set
  do
     for w0 = HOW_MANY_LEDS_MINUS_1 to 2 step -1
      Gosub SetLeds
	next w0
	pause 200
    for w0 = 1 to HOW_MANY_LEDS_MINUS_1
      Gosub SetLeds2
    next w0
  loop 
SetLeds:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
    		b10 = 50
		b11 = 00
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 5
		b11 = 0
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 1
		b11 = 0
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
	
    else
      send( $0, $00, $0 ) ; off
    end if
'pause 10                  'adjust scan period if required
  next
  tail
  return

SetLeds2:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
   		b10 = 1
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
		b10 = 5
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
		b10 = 50
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
	
    else
      send( $00, $00, $00 ) ; off
    end if
	'pause 10                  'adjust scan period if required
  next
  tail
  return
Bill
 

jims

Senior Member
The schematic below is part of an installation where is have used the APA 102 LED strip of 60 LEDS.

The program is for a kit style scanner based on the example programs supplied by technical.

This may be of some help

View attachment 19105

Code:
#picaxe 28x2
#no_table
#no_data
setfreq em32
; drop LED Strip light control
;
;         28X2                 5V -.-   Light strip
;     .-----__-----.                |
;     | RST    B.7 |                `-->  +V
;     |            |  .--> SCK -------->  CK
;     | C.2    C.5 |--|--> SDO -------->  DI
;  .--| C.3    C.4 |  |             .-->  0V
;  |  |            |  |         0V _|_
;  |  `------------'  |
;  `------------------'

; Set how many LED modules in the strip
Symbol HOW_MANY_LEDS = 60
`
Symbol HOW_MANY_LEDS_MINUS_1 = HOW_MANY_LEDS - 1
Symbol HOW_MANY_LEDS_TIMES_3 = HOW_MANY_LEDS * 3

; Set the maximum brightness of the LED while testing
; Use small values to keep current consumption low
Symbol MAX_BRIGHTNESS = 31 ; 0 to 255 (full)

; Initialise the HSPI interface
#macro init()
  hspisetup spimode00, spifast
#endmacro

; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
  hspiout( n1, n2, n3, n4 )
#endmacro

; Send the start of data header
#macro head()
  sendPacket( $00, $00, $00, $00 )
#endmacro

; Send a LED controlling command
#macro send( red, green, blue)
  sendPacket( $FF, blue, green, red )
#endmacro

; Send the end of data tail
#macro tail()
  sendPacket( $FF, $FF, $FF, $FF )
#endmacro

PowerOnReset:

  ; Initialise the HSPI interface
  init

  ; Turn all LED modules off
  head
  for w0 = 1 To HOW_MANY_LEDS
    send( $00, $00, $00 ) ; 1 to last = Off
  next
  tail

BounceLed:
  ; Set three LED at a time
  ; 'w0' indicates which LED to set
  do
     for w0 = HOW_MANY_LEDS_MINUS_1 to 2 step -1
      Gosub SetLeds
	next w0
	pause 200
    for w0 = 1 to HOW_MANY_LEDS_MINUS_1
      Gosub SetLeds2
    next w0
  loop 
SetLeds:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
    		b10 = 50
		b11 = 00
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 5
		b11 = 0
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 1
		b11 = 0
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
	
    else
      send( $0, $00, $0 ) ; off
    end if
'pause 10                  'adjust scan period if required
  next
  tail
  return

SetLeds2:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
   		b10 = 1
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
		b10 = 5
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
		b10 = 50
		b11 = 0
		b12 = 00
	send( b10, b11, b12 ) ; varying colour
	
    else
      send( $00, $00, $00 ) ; off
    end if
	'pause 10                  'adjust scan period if required
  next
  tail
  return
Bill
Bill.b----I like your schematic. What program did you use to create it?? JimS
 

erco

Senior Member
Neat project. 64 RGB LEDs could get complicated if you're really new to electronics & Picaxe. It might pay to start small and build up. Maybe start with a breadboard and 8 LEDs? Here's a 20M2 using 3 I/O pins thru a 3-8 decoder, driving 7 LEDs and a beeper.

 

Bill.b

Senior Member
Hi Jims

paintshop Pro 5 very early version.

I also have later schematic drawing programs but I prefer this one.

Bill
 

westaust55

Moderator
Hi Jims

paintshop Pro 5 very early version.

I also have later schematic drawing programs but I prefer this one.

Bill
Hello Bill,

While clearly using Paintshop Pro 5 is allowing you to present the circuit schematic clearly,
You may also wish to consider a program specifically intended to drawing schematics and even PCB layout. I do note you indicate you have schematic drawing program(s) also.

I use DIPTRACE which is free to use with the only limitation on the free version being around 300 holes.
http://diptrace.com/download-diptrace/
This saves having to cut and paste to place parts and getting wires lined up. Just click and drag for parts and click on start and end points for wires/traces.

There are some libraries posted on this forum by past forum member Mycroft and myself with specific PICAXE parts and other chips offered used with PICAXE.
Others could no doubt recommend other similar circuit drawing programs ( such as EagleCAD).
 

thansen090

New Member
Thanks for the feedback. Addressable LEDs definitely seem like the way to go. Too bad in a way: I was enjoying figuring out how to wire and activate all those "dumb" LEDs.

I have a lot of experience programming in Basic. However, I have zero experience selecting components. I have no idea why one capacitor or diode would be used instead of another. It's a steep learning curve. I do have David Lincoln's PICAXE book and some other materials. I just need to do my homework. I have a few 08M2 chips and breadboards and such. Some experimenting is forthcoming.

My car has a "hoodscoop" that's about an inch tall and 18" wide. It seems pretty obvious that a set of KITT lights has to go there. Originally I just wanted to have a simple red scanner. I'd be happy with a single sweep per second. Other effects and colors would just be a bonus.

A few follow-up questions:
Is there any reason why I couldn't use an 08M2 for this project?
Is there something available to simulate a light strip? (for programming purposes)
Are there any plans for a suitable power supply?
Now the only problem is how to get a flat strip to face forward. Ideas?
(Is there such a thing as a side-emitting APA102?)

Thanks for your help with this. I'd appreciate any more thoughts.
 

premelec

Senior Member
You could do the project with 08M2 - just bit bang the data out - 4 bytes per pixel [and start/stop sequences]
I suggest you get some APA102s and play with them.
5 Volt supply regulated from your 12v system should works well
Lots of step down and LM317 type supplies available...
You can buy individual pixels on small circuit boards and arrange as you please
No side emitting that I know of - you'll need some sort of diffuser.. point source LED not not quite right for your app.

Time for empiricism - whatever works!
 

binary1248

Senior Member
Many thanks Bill.b for your program. Worked perfect for exploring the control of the led strip. I used 20x2 instead of the 28x2, some minor compatibility changes, but it worked straight out of the box, so to speak. Now I can study your code (very well laid out, and good examples of macro use in picaxe) and the details I will want for my future led strip coding.
Paul
 

jims

Senior Member
binary1248...Here's a fun program using the 20x2 driving an APA102 LED strip. I acts as a LED tape measure. JimS
Code:
'*********************************************************************
'*'* 20x2 controls one 60 LED Dotstar APA102 LED strip with Spiout.
'* Uses an SRF004 ultrasonic range finder, and shows the relative 
'* distance to object detected by the SRF004 on the LED strip, and
'* on the OLED display. Works like an LED tapemeasure. 
'* NOTE: Trig & Echo pins on the SRF004 are tied together with a 1.8K 
'* resistor to work as a single pin input for the "Ultra" command. 
'* Trig pin is connected to input C.0 on 20X2.
'**********************************************************************
							
'                                           SRF004
'   20X2                                  +-------+
'+---------+                    +5VDC+--->| +5VDC |
'|         |                              |       |
'|     C.0 | Pin 10 +-----------+-------->| Trig  |
'|         |                    |         |       |
'|         |                  +-+--+      |       |
'|         |                  |    |      |       |
'|         |                  |1,8K|      |       |
'|         |                  |ohm |      |       |
'|         |                  +----+----->| Echo  |
'|         |                              |       |
'|         |                              |       |
'|         |                    0VDC +--->| 0VDC  |
'|         |                              +-------+
'|         |
'|         |                   APA102 LED strip
;|         |			--------------------
;|         |            +5V  --> RED +V
'|	 B.3 |15----> spi sck----> YEL CK
;|     B.4 |14----> spi sdo----> GRN DI
;|         |             0V  --> BLK 0V
;|         |              (Wire colors are for my LED strip)
'          |
'|     B.1 | Pin 17 ------> AXE133Y Serial OLED
'|     C.2 | Pin  8 <------ IR Clicker
'+---------+

Symbol CLICKER =  C.2	'Pin 8; 
symbol trig = C.0		' C.0 (pin 10).Define output pin for Trigger/echo pulse.
Symbol OLED = B.1		'Pin 17.
symbol spi_sdo = B.4	'Pin 14.
symbol spi_sck = B.3	'Pin 15.
symbol IRData = b1
symbol range = w1       '16 bit variable for range (remember w1 = b2 + b3)
symbol inches=b4		'Range in inches.
Symbol Counter = b5
symbol red = b6
symbol green = b7
symbol blue = b8
'symbol brightness =b9
symbol marker = b10
symbol Freq = M64		'Used to increase frequency/speed for LED strip.
Symbol HOW_MANY_LEDS = 60  '* Number of LED modules in the strip.


;** Initialise the Spi interface
#macro Init()
  High spi_sck
#endmacro

;** Send the start of data header
#macro head()
  sendPacket( $00, $00, $00, $00 ) 
#endmacro

;** Send the end of data tail
#macro tail()
  sendPacket( $FF, $FF, $FF, $FF )
#endmacro

;** Send a four byte packet out via Spi
#macro sendPacket( n1, n2, n3, n4 )
  spiout spi_sck,spi_sdo,MSBFirst_H,(n1,n2,n3,n4)
#endmacro

;** Send a LED controlling command
#macro send(  red, green, blue )
  sendPacket( $FF, green,blue, red )
#endmacro

;** Turns all LED modules off.
  '"delay" sets speed that LEDs turn OFF.
#macro AllOff( delay )
	head	
      for counter = 1 To HOW_MANY_LEDS
     	 SpiOut Spi_Sck,Spi_Sdo,MSBFirst_H,( $FF,$00,$00,$00 )'; Turn all LED modules off
	 pause delay 
	next
      tail	; Send the end of data tail.
#endmacro

#macro clearoled
	serout B.1,n2400,(254,1):pause 30
#endmacro

AllOff(0)
pause 1000 : pause 30	'Initialize
clearoled

main: 
	serout oled,n2400,(254,128,"  Use Clicker   ") 'Positions the underscore for data entry.
	serout oled,n2400,(254,192,"To Start Measure") 'Positions the underscore for data entry.
	irin clicker, irdata		'Use clicker to start program.
	serout oled,n2400,(254,128,"Dist from object")
	serout oled,n2400,(254,192,"Cm:      Inch:  ")
	do
	 call GetRange
	loop

'* Get the distanct to object & convert to inches.	
GetRange:
	ultra C.0,Range
	pause 10
	 inches = range * 39/100 +1 max 60 'Approx inches
	serout oled,n2400,(254,195,#range,"  ")
	serout oled,n2400,(254,206,#inches,"  ")
	pause 10 		' pause 10 ms 
	marker = inches - 1
	'sertxd(#marker,cr,lf) '*Use for testing.
	
'* Send range data to LED Strip.
SendData:
	setfreq Freq	'Set 20X2 frequency for LED strip (max m64 for 20x2).
	head  '		' Send the start of data header.
	send(0,1,0) 	'Send green base.
	if marker = 0 then None
	for counter= 1 to marker
	 send(4,5,4)  	'Send white tape.
	next counter

'* Turn on RED LED as marker for distance to object.
None:	send(1,0,0)		'Red marker shows distance measured with SRF004.
 	for counter = marker to 60
	 send(0,0,0)	'Turn OFF LEDs beyond the marker.
	next
	tail			' Send the end of data tail.
	setfreq MDEFAULT	'Reduce frequency for normal processing.
	return
 

Haku

Senior Member
Neat project. 64 RGB LEDs could get complicated if you're really new to electronics & Picaxe. It might pay to start small and build up. Maybe start with a breadboard and 8 LEDs? Here's a 20M2 using 3 I/O pins thru a 3-8 decoder, driving 7 LEDs and a beeper.
Here's what I did:



Looks good but because the Picaxe doesn't have 8 PWM outputs I had to run the Picaxe at maximum speed and use multiple Pulsout commands so the there's a little flickering happening when you're looking at it. On the upside it uses very little energy as only one LED is lit at any one time.
 

thansen090

New Member
I'm back. I finally got around to soldering some stuff together and making LEDs blink on a breadboard. I got 4 to scan nicely, 64 can't be too far away. :)

One major obstacle is still the LEDs themselves. There don't seem to be any addressable side-emitting strips that are dense enough. I'm wondering about the individual APA106 LEDs. There's no mention of these on this forum. Has anyone used them?

Assuming I build my own strip, I'd need some way to waterproof it for car use. Tips would be welcome.
 

premelec

Senior Member
I think the APA106 may be like WS2812 - which have very tight timing requirements are are hard to drive from PICAXE and have low flicker rate. I have had good results with PICAXE driving APA102 units which have much more lenient timing and a higher flicker rate... you can put a strip in a PEX pipe or buy sealed waterproof ones - see ebay...
 

thansen090

New Member
I thought I already posted this. Weird. Anyway...

A genius but simple solution to my LED problem finally came to me: a hinge. I'm kicking myself that I didn't think of that earlier. My plan is to mount an ordinary APA102 strip to a piano hinge and use a micro servo to position it. Low profile while driving, forward-facing & centered while "scanning". It's like having cake and eating it too.

I'm going to go ahead and order a 20X2 and some other bits and pieces. I might hold off on getting the LED strip until I get everything figured out. In the meantime, does anyone have some leftover strip with at least 8 LEDs on it?

BTW: What's the difference between a strip from eBay and one from Adafruit? The specs seem the same but eBay is about 1/2 the cost.
 

Haku

Senior Member
Assuming I build my own strip, I'd need some way to waterproof it for car use. Tips would be welcome.
Search for: clear conformal coating

Available in a liquid you can paint on or dip your thing you want to waterproof, but also available in spray cans.

Make sure your circuit works perfectly before applying because it makes it difficult to do any alterations afterwards.
 
Top