The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
ive just got a Netduino Plus 2 and im a complete beginner, ive worked through the "getting started with netduino" and the "Experimenter’s guide to netduino"
im currently trying to setup a single 7 segment display to be driven from a 74HC595 shift register, and to display from 0 - 9.
ive looked around and i understand that i need the follow the following ROUGH construct of :
//initialise the outputports
//specify the array
create a loop to cycle through &
Read the array value @ beginning ([color=rgb(0,0,0);font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:13px;]Digits[i])[/color]
extract the bits from the array value (somehow to break the hex down into its bits and clock each)
Output the value to the outputport //latch the above data
Wait
End loop
Dispose the clock/latch
//initialize the output portsstatic OutputPort data = new OutputPort(Pins.GPIO_PIN_D2, false); static OutputPort clock = new OutputPort(Pins.GPIO_PIN_D3, false); static OutputPort latch = new OutputPort(Pins.GPIO_PIN_D4, false);//create array/buffer of byte patterns for the numbers:private static readonly byte[] digits = new byte[] { 0x00, // B00000000 = 0 0x01, // B00000001 = 1 0x02, // B00000010 = 2 0x03, // B00000011 = 3 0x04, // B00000100 = 4 0x05, // B00000101 = 5 0x06, // B00000110 = 6 0x07, // B00000111 = 7 0x08, // B00001000 = 8 0x09 // B00001001 = 9 };//create a for loop to read the array bits and send to registerfor (int i = 0; i < 8; i++) {
At this point i know i need to read from the array and then output the value using a data.write(array)...
However ive looked around and i cant seem to find an example or tutorial that explains or helps me advance.
Forgive the crudeness of the above hope this explains my situation....
The Netduinos have an SPI controller that will write the data to a 74HC595 for you.
I found it was easy to use.
I put my own code together for a Netduino plus v1 based on the Wiki page by Mike P
This is what I think you might end up with, it is Netduino Plus v1 code that compiles.
Note that I have not run this code, I have just put it toegther from my own classes:
using System.Threading;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace Temp_SPI_Demo{ public class Program { public static void Main() { // Lookup table to turn a digit into a segment pattern byte[] digits = new byte[] { // These values are binary, // they need to be reworked to set the // segments a,b,c,d,e,f,g,dp in the display 0x00, // B00000000 = 0 0x01, // B00000001 = 1 0x02, // B00000010 = 2 0x03, // B00000011 = 3 0x04, // B00000100 = 4 0x05, // B00000101 = 5 0x06, // B00000110 = 6 0x07, // B00000111 = 7 0x08, // B00001000 = 8 0x09 // B00001001 = 9 }; SPI.Configuration xSPIConfig; // SPI configuration SPI xspi; // The actual SPI object // Setup the configuration D4 is the latch / strobe pin xSPIConfig = new SPI.Configuration(Pins.GPIO_PIN_D10, //Chip Select pin false, //Chip Select Active State 0, //Chip Select Setup Time 0, //Chip Select Hold Time false, //Clock Idle State true, //Clock Edge 32, //Clock Rate (kHz) SPI.SPI_module.SPI1);//SPI Module xspi = new SPI(xSPIConfig); // Create the SPI port byte[] byteArray = new byte[1]; // Array to send to SPI port (just one byte) for (int i = 0; i < 10; i++) { byteArray[0] = digits[i]; // Turn number to segment pattern xspi.Write(byteArray); // write pattern Thread.Sleep(1000); // Sleep for a while } } }}
You may have to make some adjustments to the classes for the v2 Netduino - I don't have a v2.
Also you are going to have to set up your digits array so that the bits activate the correct segments in your 7-segment display. (Initially, justleave it as binary so you can see something that works). The actual patterns depend on which 74HC595 pin is connected to which 7-segment LED, and whether the LEDs are arranged as common anode or common cathode.
The 74HC595 is great for 8 outputs ( or a few more if you chain the 74HC595s together), but if you are doing a whole clock display, there is a better devce to use.
The maxim MAX7219/MAX7221 is a display driver chip that will drive up to eight 7-segment displays (with dp).
It has to be used with common-cathode displays connected in a matrix.
The displays don't have to be 7 segment, it can also drive an 8x8 pixel LED display.
It connects to the Netduino in the same way as the 74HC595 (e.g. it also uses the SPI interface).
Writing to it is a bit different, rather than just sending out 8 bits to set the outputs, you send out a 16-bit word, where one byte is the digit (e.g 0 to 7), and the other byte is the output pattern for that digit.
Hi Paul,
Yeah I was just getting started with shift registers and thought id start with the 74HC595 looked the most common....
I've modified the code and wired up the components but just trying to work out the values needed to specify the right numbers (getting random illuminations atm). I've got a few Q's
Does the SPI method convert the hex values to binary?
And does it then send the first bit of the 8 to pin 1 (qa0) for example:
Number 3
11110100 0x2F
Does this mean:
Q0=high
Q1=high
Q2=high
Q3=high
Q4=low
Q5=high
Q6=low
Q7=low
Or am I barking up the wrong tree
Cheers Ade
Think I may be getting somewhere, got it to display 1 then 2....
Just gotta work out the hex for the other inputs of my display. And fingers crossed it should work I think one of my issues was the pin layout on the wiki above put OE to D11 however on http://forums.netdui...gister-example/ it goes to GND
Ade
I have a couple of projects I want to do, and it looks like the MAX 7221 will be the best bet for me.
Here is what I want to do, and then I'll ask my questions.
Project 1:
An LED clock that has 60 leds in a circle with an additional 12 leds in a circle inside the 60. Think clock face. The outer ring moved a lit led one space every minute and an inner led every hour. I think the MAX7221 will let me control the outer ring and a second MAX7221 will do the inner ring.
Project 2:
A 5x7 led matrix, a 5x6 led matrix, and a 5x40 led matrix. These matrix will be randomly lit. The goal is a total random flash pattern. I am guessing each matrix controlled by an individual MAX7221.
My question is this. I have been following this and other threads on the MAX chips, and I think I understand that the chips will connect via the SPI port on the Netduino. I can follow the physical wiring no problem, I am just having issues comprehending HOW to light the various LEDs, and more important, how to control multiple MAX chips.
I can copy the code in a previous post in this thread, but I am trying to learn what to modify to get the result I am looking for.
I hope I have been clear on my question, and I hope I am not asking too basic a question.
I had trouble using this chip with the Plus and I think this was because of a problem with the reset conditions of the Plus (digital pins high on startup). Not worked with this chip since the Plus 2 came along with it's reversed startup state of the digital pins.
Ade, if I am following the code correctly, what you are doing is every 3 seconds ([color=rgb(102,0,102);]Thread[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]Sleep[/color][color=rgb(102,102,0);]([/color][color=rgb(0,102,102);]3000[/color][color=rgb(102,102,0);]))[/color] you are writing the next number in a series[color=rgb(102,102,0);] ([/color]xspi[color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]Write[/color][color=rgb(102,102,0);]([/color]byteArray[color=rgb(102,102,0);])).[/color]
So this will count from 0 to 9 and start over.
Where I am falling short is how does it know which array to write? I realize you are incrementing a indexer (i), but does the controller inherently know to follow the indexer?
Hmm interestingly the code i placed above only shows the last entry in the array (does not cycle through) so it shows only 9 and if i comment half of the array out and change the array size it then shows 5....
so i think that i need the loop to tell the xspi.Write(byteArray); to read the value of 'i' ? will this then instruct the xspi.write to output the value at position 'i'?????
im sure its something simple just cant see it yet.
As for the arrays, my own SPI class allows daisy chaining of SPI devices - it results in a whole lot of arrays being created and copied into ever bigger ones until the complete array of data is ready.
C# is quite good at this sort of thing.
You could make the loop more efficient by putting the
byte[] WriteBuffer = new byte[1];
before the for loop.
That way the framework will not have to create and destroy it every time around the loop.
Don't forget to add the patterns for A to F into byteArray for when you decide to go for a Hex display in the future.
Hi Paul,
Thanks for the update, have you got a copy of your class I could take a look at as a step up. As my next step will be several chained registers.
And by hex display do you mean outputting alpha numeric characters on something like a LCD display?
Ade
In my work I spend a stupid amount of time debugging 3rd party software from big companies. (Operating system code and drivers, etc.) It is not much fun when you can't write any of your own code because the tools don't do what they say they should. I cringe when developers tell me about how they want to use some library or framework to solve some trivial problem.
As a result I prefer to write my own code that does exactly what I want - rather than risk getting stuck with someone else's libraries that may have little surprises.
But things are a little different in the open source world, writers actually seem to take notice of feedback and fix things because they want to, rather than because we paid for a support contract.
In the first instance, I recomend having a look at Stefan and Fabiens libraries, I understand from the Forums that many people are using them - see this post.
If you don't find what you want or are just curious then I am happy to pass on my code - let me know.
My question is this. I have been following this and other threads on the MAX chips, and I think I understand that the chips will connect via the SPI port on the Netduino. I can follow the physical wiring no problem, I am just having issues comprehending HOW to light the various LEDs, and more important, how to control multiple MAX chips.
With the 74HC595, you would wire the LEDs from the 595 output pins to ground. Loading an 8-bit value into the register will cause the 8-bit pattern to appear on the outputs until it is changed by another write. The only "problem" is that you can only have 8 LEDs with one chip.
With the MAX chips, the LEDs are arranged in a matrix of rows and columns. (8 x 8 = 64 LEDs). Each LED is connected to one row line and one column line. When that pair of lines are set to the correct (opposite) polarity, the LED will light. The LEDs might be part of a seven segment display, a dot matrix display, a bar graph, etc., or some hybrid setup.
Being a matrix, means that you can't setup an arbitary pattern with a constant drive to the rows and columns. So the MAX chip continuously cycles through the LEDs.
When you write data to the MAX chip, you give it an address (the column number 0-7) and the data (row patten 0-255). The MAX chip remembers the row pattern for each column that has been configured, and cycles through them for ever. (Until you load new data.)
As for connecting multiple chips, you have a choice.
1/ You can connect all the chips directly to the Netduino's clock and data lines, but use different latch/strobe pins. (In software, this means having multiple SPI configurations and only writing to one SPI device at any moment.) With this method all of the chips see the same data but only one will respond - the latch/strobe pins for the other chips are not energised so they will just ignore the clock pulses and data.
This method might be a requirement where the devices are different and have opposite requirements (such as different clock edges or latch polarity).
2/ Where the devices are the same or are compatible, you can daisy chain them. Here you connect the first device directly to the Netduino, and you connect the data output of that device to the input of the next device. In this case, all the devices see the same clock and latch, but the later devices see a delayed version of the data. With the 74HC595s you are effectivly creating a longer shift register.
You might also want to use a hybrid scheme with a combination of devices and connections.
Note that with the MAX chips, there is a reason for not wanting to dasiy chain them - this is because of the way they are written to. You need to write address and data to all devices in the chain so that when the latch/strobe is triggered they all get a valid update. This might make your software more complicated if you only want to update one digit of 8 LEDs at a time. Hence you may wish to use separate latch/strobe lines for each device so that each device can be controlled independantly of the others.
I think I am getting there. I'm just gonna have to jump on starting to write the code. But first, I need to get my hands on a few MAX chips so i can see the output.
I am sure I will be asking more questions as I get into this.