I recently received one of the cheap 8 digit led displays run by a max7219.
When I went looking for a demo, all I could find was demos for a max7219 hooked up to an 8x8 led matrix, and using the GLCD graphic display driver.
I can see from these demos how to do the front end. Connect the spi pins for clock and data, and two random pins connected to cs and di. Since I'm not planning on reading the display, I guess DI is unnecessary. From one of the demos (comments are mine and may be incorrect) -
Then I am at a loss for what to do next. Since this not set up as an 8x8 matrix, it doesn't make sense to use the graphic GLCD display driver routines.
What do I use to simply show a number on the display?
I'm going to press on, and I'll figure it out in a few days, but I thought someone must have used one of these before and could save me some time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got same display but 4 connected and there's a scrolling demo but I never worked out what was happening..ie understood it.
I have two that can be joined and wanted a pixel/led addressable 16x32 display...made from two 8x32.. each an 8x8 unit. Too hard for me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been using these for a couple years. I almost made a library for them but was distracted and never finished. Just copy in the subs and use. This little project ,I was measuring a positive/ negative voltage on the input to a servo(not the toy ones).
'Plus and minus voltage +-10 vdc input to the adc'using resistor network of 3 resistors - no opamps' Vcc+5 -<22K >---adc input^|-----<12k>--gnd' inputvoltage --<80K>------|'10bit adc reads 300 dec when input touched to gnd'' MAX7219 Driver for Great Cow Basic'' using Hardware SPI routines for Great Cow BASIC' Copyright (C) 2016 - Mike Otte ,PearlCity IL' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' This library 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' Lesser General Public License for more details.' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'********************************************************************************'IMPORTANT:'THIS FILE IS ESSENTIAL FOR SOME OF THE COMMANDS IN GCBASIC. DO NOT ALTER THIS FILE'UNLESS YOU KNOW WHAT YOU ARE DOING. CHANGING THIS FILE COULD RENDER SOME GCBASIC'COMMANDS UNUSABLE!'********************************************************************************'Changes: Aug 2016 written'Register Address map of commands'NO-OP 0xX0 0x00'Digit 0 0xX1 0x01'Digit 1 0xX2 0x02'Digit 2 0xX3 0x03'Digit 3 0xX4 0x04'Digit 4 0xX5 0x05'Digit 5 0xX6 0x06'Digit 6 0xX7 0x07'Digit 7 0xX8 0x08'Decode 0xX9 0x09'Intesity 0xXA 0x0A'ScanLim 0xXB 0x0B'Shutdown 0xXC 0x0C'DispTest 0xXF 0x0F' 16 bits spi transfer for each digit/COMMANDS'clock rising - data read'Load pin low to allow clocked in data'Sub routines list'Initialize'set decode mode'set intensity of digit x'set san limit'writeToDigitX(address,data)'TurnOn Display'Changes:#chip 16F886, 8#define CS PortA.5 ' out#define SCK PortC.3 'clk out#define MOSI PortC.4 'in#define MISO PortC.5 'outCS=1'Set SPI pin directionsdirPORTC.5out'SDOdirPORTC.4in'SDIdirPORTC.3out'SCKdirPORTA.5out'SS loadDimcount,myValueasWord'Set SPI Mode to master, with fast clock'SPIMode MasterFast,0SPIMode(MasterFast,SPI_CPOL_0+SPI_CPHA_0)'SSPSTAT = 0x40 'spimodewasnotsetcorrectlyinmyGCcompiler'SSPCON1 = 0x20InitMax7219_7segdomyValue=ReadAD10(AN1)IfmyValue>=297thenmyValue=(myValue-297)*10/16MLED_write(5,0x0F)elsemyValue=(297-myValue)*10/16MLED_write(5,0x0A)endifMLED_Dec(myValue,4)wait1sLoopsubInitMax7219_7segcs=1wait100ms'set decode modeMLED_write(0x09,0xFF)'set intensity 3/4MLED_write(0x0A,0x06)'set scan limitMLED_write(0x0B,0x07)'set display ONMLED_write(0x0C,0x01)Forcount=1to8MLED_write(count,0x0F)'Clear digitsnextendsubsubMLED_write(cmd,dayta)#NRcs=0serBuf=0x00'empty bucketSPITransfercmd,serBufserBuf=0x00'empty bucketSPITransferdayta,serBufcs=1endsubSubMLED_Int(InMLEDValue,InNumDig)MLEDValueTemp=0MLED_write(NumDig,0x0F)MLED_write(NumDig-1,0x0F)MLED_write(NumDig-2,0x0F)IFMLEDValue>=100ThenMLEDValueTemp=MLEDValue/100MLEDValue=SysCalcTempXMLED_write(NumDig,MLEDValueTemp)'NumDig--EndIfIfMLEDValueTemp>0OrMLEDValue>=10ThenMLEDValueTemp=MLEDValue/10MLEDValue=SysCalcTempXMLED_write(NumDig-1,MLEDValueTemp)'NumDig--EndIfMLEDValueTemp=MLEDValueMLED_write(NumDig-2,MLEDValueTemp)EndSubSubMLED_Dec(InMLEDValueasword,InNumDig)MLEDValueTemp=0MLED_write(NumDig,0x0F)MLED_write(NumDig-1,0x0F)MLED_write(NumDig-2,0x0F)MLED_write(NumDig-3,0x0F)IFMLEDValue>=1000ThenMLEDValueTemp=MLEDValue/1000MLEDValue=SysCalcTempXMLED_write(NumDig,MLEDValueTemp)'NumDig--EndIfIFMLEDValueTemp>0OrMLEDValue>=100ThenMLEDValueTemp=MLEDValue/100MLEDValue=SysCalcTempXMLED_write(NumDig-1,MLEDValueTemp)'NumDig--EndIfIfMLEDValueTemp>0OrMLEDValue>=10ThenMLEDValueTemp=MLEDValue/10MLEDValue=SysCalcTempXMLED_write(NumDig-2,MLEDValueTemp+0x80)'NumDig--EndIfMLEDValueTemp=MLEDValueMLED_write(NumDig-3,MLEDValueTemp)EndSub
Have fun!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I tried mmotte's program and got the same results. Any write to the max7219 results in all segments on, just as if I did a "display test ". Either a wiring error, which I've check multiple times, or this unit from China is just no good.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are absolutely correct. I did have the pps screwed up. Too much cut and paste. At least I'm getting something now, not correct, but encouraging! Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You will see this is most demos where SPI is used, or, can be used. There may be a variant of #define SPI_HardwareSPI for a specific device.
What does this do? If you comment this out then the software SPI is supported. This means that you do not need PPS or any SPIMode commands. As software SPImode does not required PPS of the setting of SPMode.
To complete the picture. Some SPI impmentations across the PIC range require SPIBAUD. The demos show how to use but essentially this is a speed adjuster.
My rule of thumb advice.
Always, always start with software SPI. Get the device operational then use hardware SPI.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I recently received one of the cheap 8 digit led displays run by a max7219.
When I went looking for a demo, all I could find was demos for a max7219 hooked up to an 8x8 led matrix, and using the GLCD graphic display driver.
I can see from these demos how to do the front end. Connect the spi pins for clock and data, and two random pins connected to cs and di. Since I'm not planning on reading the display, I guess DI is unnecessary. From one of the demos (comments are mine and may be incorrect) -
Then I am at a loss for what to do next. Since this not set up as an 8x8 matrix, it doesn't make sense to use the graphic GLCD display driver routines.
What do I use to simply show a number on the display?
I'm going to press on, and I'll figure it out in a few days, but I thought someone must have used one of these before and could save me some time.
edit - deleted as newer code shown later
Last edit: Jim giordano 2019-11-15
I am stupid but shouldn't it be
I got same display but 4 connected and there's a scrolling demo but I never worked out what was happening..ie understood it.
I have two that can be joined and wanted a pixel/led addressable 16x32 display...made from two 8x32.. each an 8x8 unit. Too hard for me.
I have been using these for a couple years. I almost made a library for them but was distracted and never finished. Just copy in the subs and use. This little project ,I was measuring a positive/ negative voltage on the input to a servo(not the toy ones).
Have fun!
Thanks for that, I'll give it a try shortly.
Well, I think this should work unless I'm missing something important. Or I misunderstand how it works in general.
Yup, I was definately misunderstanding. Bad code deleted. Final working code below.
Last edit: Jim giordano 2019-11-15
Well, I tried mmotte's program and got the same results. Any write to the max7219 results in all segments on, just as if I did a "display test ". Either a wiring error, which I've check multiple times, or this unit from China is just no good.
Might it be the PPS setup?
• SDI must have corresponding TRIS bit set
• SDO must have corresponding TRIS bit cleared
• SCK (Master mode) must have corresponding
TRIS bit cleared
SDO instead of sda(i2c)
SPIMode gave me trouble those years ago. it is probably ironed out now.
SPIMode Master in yours
--
I see I must add #define SPI_HardwareSPI which we didn't need back then.
73
Mike
You are absolutely correct. I did have the pps screwed up. Too much cut and paste. At least I'm getting something now, not correct, but encouraging! Thanks.
And the final working solution :)
later- nope, still had pps screwed up.
Code deleted. New version farther down.
Last edit: Jim giordano 2019-11-15
An insight
#define SPI_HardwareSPI
You will see this is most demos where SPI is used, or, can be used. There may be a variant of
#define SPI_HardwareSPI
for a specific device.What does this do? If you comment this out then the software SPI is supported. This means that you do not need PPS or any SPIMode commands. As software SPImode does not required PPS of the setting of SPMode.
To complete the picture. Some SPI impmentations across the PIC range require SPIBAUD. The demos show how to use but essentially this is a speed adjuster.
My rule of thumb advice.
Always, always start with software SPI. Get the device operational then use hardware SPI.
New demo program. Finally got pps right (thanks mmotte)
Edit- found undocumented mode MasterUltraFast, which at 32mhz no longer requires wait between sends, which makes the output MUCH faster.
Last edit: Jim giordano 2019-11-15