Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Hooking DM to DealExtreme display module
Author | Message | ||||
jdh2550 Regular Member Joined: 16/07/2012 Location: United StatesPosts: 62 |
File this one under "deal extreme success" A while ago bigmik pointed out some interesting stuff on the dx.com site: what to do with our 'mites I ordered 3 things one of which was this: 8x button, 8x LED, 8x 7-Segment Display Module It's only $7 and that includes free shipping! I think it's probably a great addition for a lot of projects out there. I'm going to use mine for my Prius CAN based project because I don't want to use a full keyboard in the car. So, I've spent the last couple of evenings playing with this module and managed to start to get it working tonight. In the end the code is actually pretty simple! The downside is that "out the box" when you power up the module there's no way to tell if it's a DOA unit (always a risk with DX). It took a little bit of playing around - but in the end it was actually simpler than I thought because this module is very forgiving with the clock signal. It was a relief to see the LEDs light up and to know that the unit works. BTW, I also recently bought a low cost logic analyzer: Open Bench Logic Sniffer (for $50 from Cute Digi). It was my first time playing with a logic analyzer and it was very helpful in figuring stuff out (because inserting print statements doesn't cut it for debugging this sort of stuff). I highly recommend this product! Code is listed below (MMBasic V4) and hopefully it should be fairly readable. It's based on code from these two sources: http://www.picaxeforum.co.uk/showthread.php?21006-Driving-JY -LKM1638-from-08M2 http://code.google.com/p/tm1638-library/ (mostly this link) And the following page is a good overview: http://tronixstuff.wordpress.com/2012/03/11/arduino-and-tm16 38-led-display-modules/ Only the LED code is implemented so far - but the rest is just a matter of porting over the rest of the software - which is the easy stuff for me. When I get that done I'll update this thread with the complete package. Enjoy the blinky lights and if you look at the code and can think of a better way please let me know. (Especially the bitwise operation in TMSend) p.s. I'm hoping that MMBasic 4+n will incorporate some form of "file include" directive to make distributing and using library code easier. ' MMBasic v4.0 Sample ' ' LIBRARY CODE for driving JY-MCU / JY-LKM1638 module availble from: ' http://dx.com/p/8x-digital-tube-8x-key-8x-double-color-led-m odule-81873 ' ' Code copyright 2012 John Harding ' Beer License: if this is of any value to you and our paths should cross ' then buy me a beer. ' you can choose any three pins you want... CLK = 13 : DIO = 14 : STB = 15 ' Setup pins and initialize the module Sub TMSetup SetPin CLK,8 : SetPin DIO,8 : SetPin STB,8 Pin(STB)=1 : Pin(CLK)=1 TMSendCmd(&h40) : TMSendCmd(&h8F) Pin(STB)=0 TMSend(&hC0) Local i ' strange that I have to declare local i for this for/next to work For i=0 To 15 TMSend(&h00) 'zero out everything Next i Pin(STB)=1 End Sub ' Send one byte to the module ' note that this routine produces a clock signal with a "lop-sided" duty cycle ' however the module doesn't seem to care. Sub TMSend(data) j = 1 For i=0 To 7 Pin(CLK)=0 If (data And j) Then Pin(DIO)=1 Else Pin(DIO)=0 EndIf j = j * 2 ' this is an "expensive operation" is there a better way? Pin(CLK)=1 Next i End Sub ' Send a command byte to the module Sub TMSendCmd(cmd) Pin(STB)=0 TMSend(cmd) Pin(STB)=1 End Sub ' Send a data byte to the module Sub TMSendData(address, data) TMSendCmd(&h44) Pin(STB)=0 TMSend(&hC0 Or address) TMSend(data) Pin(STB)=1 End Sub ' Set the LED number (0 based) to the given color ' c=1 - red ' c=2 - green ' c=3 - red + green = orange ' c=any other value switches off LED Sub TMSetLED(p, c) TMSendData( p*2+1, c ) End Sub '''''''''''''''''''''''''''''''''''''''''''''''' ' DEMO code for the above library... TMSetup() Cls ? "watch the pretty lights and press q when bored" led = 0 clr = 1 Do If (Inkey$="q") Then End TMSetLED(led, clr) ? @(0,20) "led " led " set to color (or colour) " clr Pause(200) led = led + 1 : If led > 7 Then led = 0 If led = 0 Then clr = clr + 1 : If clr > 3 Then clr = 0 EndIf Loop |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
Hi JDH, Great I think you might have saved me a lot of heart ache.. I haven't got a lot of time to play with these things until after the Melbourne Cup due to severe work load. But I await your efforts eagerly. That logic analyser looks good too.. I have read that the PicKit 3 can function as a logic analyser as well has anyone used this? And can comment on its usefullness? Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
jdh2550 Regular Member Joined: 16/07/2012 Location: United StatesPosts: 62 |
Mick - I never realized you were a jockey! WRT to the BT module - it will probably take a back seat for a while. I also noticed that DX.com carry several versions of this module - some pre-mounted on some form of carrier board. See this one as an example BT Serial Module on a carrier board. For the extra $5 it would probably suit me better to have it pre-mounted with the few extra components already taken care of - not to mention the fact that did I mention how bad I am at soldering? WRT to the logic analyzer - I imagine a lot comes down to the software that you use to interact with it. The software for the OLS is open-source and could probably be adapted for the PicKit 3 if someone wanted to go that route. |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
Yeah I am always on the `TOP WEIGHT' Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Great - and thanks for the URLs for those devices! For this: Sub TMSend(data) j = 1 For i=0 To 7 Pin(CLK)=0 If (data And j) Then Pin(DIO)=1 Else Pin(DIO)=0 EndIf j = j * 2 ' this is an "expensive operation" is there a better way? Pin(CLK)=1 Next i End Sub Maybe (but I can't test it!): Sub TMSend(data)
For i=0 To 7 Pin(CLK)=0 Pin(DIO) = data And 1 data = data \ 2 ' still expensive (slow) - note \ is integer division Pin(CLK)=1 Next i End Sub |
||||
jdh2550 Regular Member Joined: 16/07/2012 Location: United StatesPosts: 62 |
JohnS - thanks for that. Integer division should definitely be quicker than floating point multiplication! I've actually switched to a lookup based approach: [code] Dim powersOf2(8) powersOf2(0)=1 : powersOf2(1)=2 : powersOf2(2)=4 etc... Sub TMSend(data) For i=0 To 7 Pin(CLK)=0 Pin(DIO) = data And powersOf2(i) Pin(CLK)=1 Next i End Sub [/code] I'll look at the waveform produced with all three methods. |
||||
jdh2550 Regular Member Joined: 16/07/2012 Location: United StatesPosts: 62 |
OK, I've added code for the 8 character 7-segment display but it's not working. I've also added code to read the buttons - and that does work. I actually only want the LEDs and buttons for my project so debugging the 7-segment display routines is left as an exercise for the reader! [code] ' LIBRARY CODE for driving JY-MCU / JY-LKM1638 module availble from: ' http://dx.com/p/8x-digital-tube-8x-key-8x-double-color-led-m odule-81873 ' ' Code copyright 2012 John Harding ' Beer License: if this is of any value to you and our paths should cross ' then buy me a beer. ' ' Naming convention: ' - all library functions start with tm or TM ' - tm functions are part of the "internals" and aren't intended to be called ' - TM functions are the ones which you will use in your code ' - TM functions are listed first, tm ones second ' ' Demo code is at the bottom of this file - you don't need to copy that ' into your code. '''''''''''''''''''''''''''''''''''''''''''''''''' ' Initialization ' you can choose any three pins you want... CLK = 13 : DIO = 14 : STB = 15 ' Setup pins and initialize the module Sub TMSetup SetPin CLK,8 : SetPin DIO,8 : SetPin STB,8 Pin(STB)=1 : Pin(CLK)=1 tmSendCmd(&h40) ' auto-address mode tmSendCmd(&h8F) ' max brightness Pin(STB)=0 tmSend(&hC0) ' start address Local i For i=0 To 15 tmSend(&h00) 'zero out everything Next i Pin(STB)=1 End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ' LED commands ' Set the LED number (0 based) to the given color ' c=1 - red ' c=2 - green ' c=3 - red + green = orange ' c=any other value switches off LED Sub TMSetLED(p, c) tmSendData( p*2+1, c ) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''' ' Button commands ' read the state of the buttons Function TMGetButtons Local a, b, c, d Pin(STB)=0 tmSend(&h42) a = tmReceive() b = tmReceive() c = tmReceive() d = tmReceive() Pin(STB)=1 TMGetButtons = 0 If (a And 1) Then TMGetButtons = TMGetButtons Or p2(0) If (b And 1) Then TMGetButtons = TMGetButtons Or p2(1) If (c And 1) Then TMGetButtons = TMGetButtons Or p2(2) If (d And 1) Then TMGetButtons = TMGetButtons Or p2(3) If (a And 16) Then TMGetButtons = TMGetButtons Or p2(4) If (b And 16) Then TMGetButtons = TMGetButtons Or p2(5) If (c And 16) Then TMGetButtons = TMGetButtons Or p2(6) If (d And 16) Then TMGetButtons = TMGetButtons Or p2(7) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''' ' 7-Segment Display commands ' NOT WORKING :-( ' Turn on the display with a given brightness Sub TMSetupDisplay(active, intensity) If (intensity > 7) Then intensity = 7 If (active <> 0) Then active = 8 tmSendCmd(&h80 Or active Or intensity) Pin(STB)=0 Pin(CLK)=0 Pin(CLK)=1 Pin(STB)=1 End Sub ' Clear a segment Sub TMClearDisplayDigit(p, dot) tmSendChar(p, 0, dot) End Sub ' Send string s$ to the display ' dots is a byte of flags for each of the 8 available dots Sub TMSetDisplay(s$,dots) n = Len(s$) If n>8 Then n=8 Local i For i=1 To n ? i " "; tmSendChar(p2(i), Mid$(s$,i,1),dots And p2(i-1)) Next i End Sub ' clear entire display Sub TMClearDisplay() For i=0 To 7 tmSendData(i*2,0) Next i End Sub ' send character c$ to segment p and light the dot if dot<>0 Sub TMSendChar(p, c$, dot) ? "p = " p " c$ = " c$ " dot = " dot " pattern = " Bin$(tmGetSegPat(c$, dot)) tmSendData(p*2, tmGetSegPat(c$, dot)) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Private code (internal workings of library - you won't use these directly) ' 7 segment display representation of ASCII chars from space (32) to Z (90) Data 0,&b10000110,&b00100010,&b01111110,&b01101101,0,0,&b00000010 Data &b00110000,&b00000110,&b01100011,0,&b00000100,&b01000000,&b1 0000000 Data &b01010010,&b00111111,&b00000110,&b01011011,&b01001111,&b011 00110 Data &b01101101,&b01111101,&b00100111,&b01111111,&b01101111,0,0,0 Data &b01001000,0,&b01010011,&b01011111,&b01110111,&b01111111,&b0 0111001 Data &b00111111,&b01111001,&b01110001,&b00111101,&b01110110,&b000 00110 Data &b00011111,&b01101001,&b00111000,&b00010101,&b00110111,&b001 11111 Data &b01110011,&b01100111,&b00110001,&b01101101,&b01111000,&b001 11110 Data &b00101010,&b00011101,&b01110110,&b01101110,&b01011011 Dim p2(8) p2(0)=1:p2(1)=2:p2(2)=4:p2(3)=8:p2(4)=16:p2(5)=32:p2(6)=64:p 2(7)=128 Dim tmSegPat(59) For i=0 To 58 Read tmSegPat(i) Next i Function tmGetSegPat(c$, dot) i=Asc(c$)-32 If (i<0) Then i=0 If (i>58) Then i=58 tmGetSegPat=tmSegPat(i) If (dot<>0) Then tmGetSegPat = tmGetSegPat Or 128 End Function Sub tmSendCmd(cmd) Pin(STB)=0 TMSend(cmd) Pin(STB)=1 End Sub Sub tmSendData(address, data) TMSendCmd(&h44) Pin(STB)=0 TMSend(&hC0 Or address) TMSend(data) Pin(STB)=1 End Sub Sub tmSend(data) Local i For i=0 To 7 Pin(CLK)=0 If (data And p2(i)) Then Pin(DIO)=1 Else Pin(DIO)=0 EndIf Pin(CLK)=1 Next i End Sub Function tmReceive tmReceive = 0 SetPin DIO,2 ' set pin as input Local i For i=0 To 7 tmReceive = tmReceive \ 2 Pin(CLK)=0 If (Pin(DIO)=1) Then tmReceive = tmReceive Or &h80 Pin(CLK)=1 Next i SetPin DIO,8 ' set pin back to output End Function '''''''''''''''''''''''''''''''''''''''''''''''' ' DEMO code for the above library... TMSetup() TMSetupDisplay(1,7) TMSetLED(0,1) TMSetDisplay("12345678",255) TMSendChar(128,"1",1) Cls ? "watch the pretty lights and press b when bored" led = 0 clr = 1 Do If (Inkey$="b") Then Exit TMSetLED(led, clr) ? @(0,20) "led " led " set to color (or colour) " clr Pause(200) led = led + 1 : If led > 7 Then led = 0 If led = 0 Then clr = clr + 1 : If clr > 3 Then clr = 0 EndIf Loop Sub setLedFromButton(buttons, b) If (buttons And p2(b)) Then TMSetLED(b, 1) Else TMSetLED(b, 0) EndIf End Sub Cls ? "now you can entertain yourself with buttons (and then b when bored)" buttons=0 Do If (Inkey$="b") Then Exit buttons = TMGetButtons() ? @(0,20) " " ? @(0,20) "buttons = " Bin$(buttons+256) For i=0 To 7 setLedFromButton(buttons, i) Next i Loop [/code] |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
That would not have worked, because your original wanted to output either a 1 or 0 and the above doesn't, but I see you fixed it in the longer post above. |
||||
Ray B Senior Member Joined: 16/02/2007 Location: AustraliaPosts: 219 |
Follow this link to interface to a picaxe fitted with a shield I/O pattern http://www.picaxeforum.co.uk/showthread.php?21884-Interfacin g-the-low-cost-DX-LCD-Keypad-%28shield%29-with-the-PICAXE-AX E401-Shield Enjoy RayB from Perth WA |
||||
James_From_Canb Senior Member Joined: 19/06/2011 Location: AustraliaPosts: 265 |
It may look like it will not work, but it uses the same technique that Geoff used in his demo LCD code. If the entire variable is zero the pin is set to zero; if the variable is non-zero the pin is set to 1. James My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention. Hedley Lamarr, Blazing Saddles (1974) |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
You're right! Sorry. John |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
Hi Fellas, I am not really sure I want to post this now as it will expose me for the inept programmer that I am... I should have looked at this thread for followups as I used Johns original code as a base for my fiddling. Now I will explain that I am not really comfortable with No line Numbers and Do-Loops but I did this as a bit of an experiment and I am getting my head around it all.. I cannot cope with all the high level maths posted above but I did modify Johns Original and get the 7Segs working... If anyone is interested in looking at it please be my guest.. 2013-04-19_122352_7SEG.zip Please dont laugh at me, I am a silly old bugger that has drunk too much of Dons beer in my time... I tried to get the buttons working but as I cant understand C I struggled and failed miserably.. So I will look at Johns later posting for help in that area.. Anyway I am interested in seeing this library completed so I have exposed my shame and posted my measly effort here for all to see. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
Print this page |