lesthegrngo Posted January 5, 2020 Author Posted January 5, 2020 (edited) After my tribulations with other parts of the setup, I'm concentrating on getting a lot of the other bits and pieces running well via USB. I successfully got the landing gear lever, status lights, plus a couple of warning lights (NW steer and Gun ready) working with no problems, plus the flap gauge using an A4988 stepper motor driver, which does seem to be easier to work with. Interestingly all of these are working from a single Nano, although I do have to correctly calibrate the flap gauge for 100% good. My CDU keyboard also is now working using a Bodnar BB-64 unit - but there are so many keys on it that the ones next to the screen will have to be driven by a separate board. The Bodnar boards are super easy to use, they are so fuss free. I hope they come out with a 256 button board next, with all the switches and rotary encoders it will need them! So that brings me to the CWP in this thread. I have made the circuit to take the MAX7219 chip in a socket, with the DIN going to the Nano pin 11, CLK to pin 13 and LOAD to pin 10. I have used the reference shcematics about connecting up the chip, so have used a resistor for the ISET and put a couple of capacitors in. The LED matrix has been tested that there are no short circuits, and will light up the individual segments depending on the two connected pins. It is a 4 across X 12 down matrix, but per the advice given here it is broken into two 4 x 6 matrices one on top of the other. I have edited the sketch given in a separate thread that HanSolo and Vinc pointed me to so using the designated pins, this is the sketch that I have produced #define DCSBIOS_IRQ_SERIAL #include <DcsBios.h> #include <LedControl.h> //pin 11 is connected to the DataIn //pin 13 is connected to the CLK //pin 10 is connected to LOAD LedControl lc=LedControl(11,13,10,1);//DIN,CLK,LOAD,# OF IC's unsigned char cl_row_map[48] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, }; #define SEG_DP (1<<7) #define SEG_A (1<<6) #define SEG_B (1<<5) #define SEG_C (1<<4) #define SEG_D (1<<3) #define SEG_E (1<<2) #define SEG_F (1<<1) #define SEG_G (1<<0) unsigned char cl_mask_map[48]= { SEG_DP, SEG_B, SEG_D, SEG_F, SEG_DP, SEG_B, SEG_D, SEG_F, SEG_DP, SEG_B, SEG_D, SEG_F, SEG_DP, SEG_B, SEG_D, SEG_F, SEG_DP, SEG_B, SEG_D, SEG_F, SEG_DP, SEG_B, SEG_D, SEG_F, SEG_A, SEG_C, SEG_E, SEG_G, SEG_A, SEG_C, SEG_E, SEG_G, SEG_A, SEG_C, SEG_E, SEG_G, SEG_A, SEG_C, SEG_E, SEG_G, SEG_A, SEG_C, SEG_E, SEG_G, SEG_A, SEG_C, SEG_E, SEG_G, }; unsigned char max7219_rows[8]; void setup() { DcsBios::setup(); memset(max7219_rows, 0xff, sizeof(max7219_rows)); lc.shutdown(0,false); //turn on the display lc.setIntensity(0,8);//set the brightness lc.clearDisplay(0); //clear rthe display and get ready for new data } void updateCautionLights(unsigned int address, unsigned int data) { unsigned char clp_row = (address - 0x10d4) * 2; unsigned char start_index = clp_row * 4; unsigned char column = 0; unsigned char i; bool is_on; for (i=0; i<16; i++) { is_on = data & 0x01; // set caution light state (clp_row, column, is_on) if (is_on) { max7219_rows[cl_row_map[start_index+i]] |= cl_mask_map[start_index+i]; } else { max7219_rows[cl_row_map[start_index+i]] &= ~(cl_mask_map[start_index+i]); } data >>= 1; column++; if (column == 4) { clp_row++; column = 0; } } } void onClpData1Change(unsigned int newValue) { updateCautionLights(0x10d4, newValue); } DcsBios::IntegerBuffer clpData1(0x10d4, 0xffff, 0, onClpData1Change); void onClpData2Change(unsigned int newValue) { updateCautionLights(0x10d6, newValue); } DcsBios::IntegerBuffer clpData2(0x10d6, 0xffff, 0, onClpData2Change); void onClpData3Change(unsigned int newValue) { updateCautionLights(0x10d8, newValue); } DcsBios::IntegerBuffer clpData3(0x10d8, 0xffff, 0, onClpData3Change); void loop() { DcsBios::loop(); // update MAX7219 unsigned char i; for (i=0; i<8; i++) { lc.setRow(0, i, max7219_rows[i]); } } Now while I accept that the actual mapping of the individual lights may not match the mapping in the sketch, I did at least hope that once connected some lights would light depending on the input. The sketch shows two 4 x 6 matrices, so seems to match what I have produced. When I plug it in via USB, I can see the Nano communicating with the PC but unfortunately all the segments light up at the same time. I don't know if maybe I have fried the MAX7219 chip, and of course am reluctant to put my only spare in to test this theory, but would appreciate a quick once over of my sketch to ensure there isn't a silly mistake somewhere I must say, even though not working 100% yet, I'm very happy with the look of it Any other thoughts appreciated as ever Cheers Edited January 5, 2020 by lesthegrngo
lesthegrngo Posted January 15, 2020 Author Posted January 15, 2020 Hi again guys. I have the CWP working, however it's clear that the mapping of the lights is not right for my sketch, as the wrong lights go on when DCS illuminates a particular one. This is the sketch that's working #define DCSBIOS_IRQ_SERIAL #include <DcsBios.h> #include <LedControl.h> //pin 11 is connected to the DataIn //pin 13 is connected to the CLK //pin 10 is connected to LOAD LedControl lc=LedControl(3,5,4,1);//DIN,CLK,LOAD,# OF IC's unsigned char cl_row_map[48] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, }; #define SEG_DP (1<<7) #define SEG_A (1<<6) #define SEG_B (1<<5) #define SEG_C (1<<4) #define SEG_D (1<<3) #define SEG_E (1<<2) #define SEG_F (1<<1) #define SEG_G (1<<0) unsigned char cl_mask_map[48]= { SEG_C, SEG_D, SEG_F, SEG_A, SEG_C, SEG_D, SEG_F, SEG_A, SEG_C, SEG_D, SEG_F, SEG_A, SEG_C, SEG_D, SEG_F, SEG_A, SEG_C, SEG_D, SEG_F, SEG_A, SEG_C, SEG_D, SEG_F, SEG_A, SEG_DP, SEG_G, SEG_E, SEG_B, SEG_DP, SEG_G, SEG_E, SEG_B, SEG_DP, SEG_G, SEG_E, SEG_B, SEG_DP, SEG_G, SEG_E, SEG_B, SEG_DP, SEG_G, SEG_E, SEG_B, SEG_DP, SEG_G, SEG_E, SEG_B, }; unsigned char max7219_rows[8]; void setup() { DcsBios::setup(); memset(max7219_rows, 0xff, sizeof(max7219_rows)); lc.shutdown(0,false); //turn on the display lc.setIntensity(0,8);//set the brightness lc.clearDisplay(0); //clear rthe display and get ready for new data } void updateCautionLights(unsigned int address, unsigned int data) { unsigned char clp_row = (address - 0x10d4) * 2; unsigned char start_index = clp_row * 4; unsigned char column = 0; unsigned char i; bool is_on; for (i=0; i<16; i++) { is_on = data & 0x01; // set caution light state (clp_row, column, is_on) if (is_on) { max7219_rows[cl_row_map[start_index+i]] |= cl_mask_map[start_index+i]; } else { max7219_rows[cl_row_map[start_index+i]] &= ~(cl_mask_map[start_index+i]); } data >>= 1; column++; if (column == 4) { clp_row++; column = 0; } } } void onClpData1Change(unsigned int newValue) { updateCautionLights(0x10d4, newValue); } DcsBios::IntegerBuffer clpData1(0x10d4, 0xffff, 0, onClpData1Change); void onClpData2Change(unsigned int newValue) { updateCautionLights(0x10d6, newValue); } DcsBios::IntegerBuffer clpData2(0x10d6, 0xffff, 0, onClpData2Change); void onClpData3Change(unsigned int newValue) { updateCautionLights(0x10d8, newValue); } DcsBios::IntegerBuffer clpData3(0x10d8, 0xffff, 0, onClpData3Change); void loop() { DcsBios::loop(); // update MAX7219 unsigned char i; for (i=0; i<8; i++) { lc.setRow(0, i, max7219_rows[i]); } } So it seems to me that my mapping addresses are wrong, so firstly this is how the PCB is currently wired up to the MAX7219 pins (matrix in pinout connected, DIGX / SEGX) 0/ SEG_C, 0/ SEG_D, 0/ SEG_F, 0/ SEG_A, 1/ SEG_C, 1/ SEG_D, 1/ SEG_F, 1/ SEG_A, 2/ SEG_C, 2/ SEG_D, 2/ SEG_F, 2/ SEG_A, 3/ SEG_C, 3/ SEG_D, 3/ SEG_F, 3/ SEG_A, 4/ SEG_C, 4/ SEG_D, 4/ SEG_F, 4/ SEG_A, 5/ SEG_C, 5/ SEG_D, 5/ SEG_F, 5/ SEG_A, 0/ SEG_DP, 0/ SEG_G, 0/ SEG_E, 0/ SEG_B, 1/ SEG_DP, 1/ SEG_G, 1/ SEG_E, 1/ SEG_B, 2/ SEG_DP, 2/ SEG_G, 2/ SEG_E, 2/ SEG_B, 3/ SEG_DP, 3/ SEG_G, 3/ SEG_E, 3/ SEG_B, 4/ SEG_DP, 4/ SEG_G, 4/ SEG_E, 4/ SEG_B, 5/ SEG_DP, 5/ SEG_G, 5/ SEG_E, 5/ SEG_B, Some are transposed, for example the left and right wing and main pumps - left light actually illuminates right light. Others are one row below where they should be, and then some just don't light at all. So I am wondering whether I am getting the syntax of the mapping right. I am treating it like two four wide by six deep matrices, one on top of another, and that maybe I should be treating it as them being side by side? Cheers Les
Vinc_Vega Posted January 15, 2020 Posted January 15, 2020 (edited) deleted Edited January 16, 2020 by Vinc_Vega Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC]
lesthegrngo Posted January 17, 2020 Author Posted January 17, 2020 Got this working, there were two errors in my mapping, one due to my matrix PCB having two pins transposed due to ease of production needs, and another due to me reading the columns back to front - the contacts came back through the board so I mistakenly mirrored the input pins in the sketch. It's looking great, again many thanks to everyone for their help Cheers Les
Vinc_Vega Posted January 17, 2020 Posted January 17, 2020 (edited) Congrats Les! I built the CLP matrix on a breadboard and got it working with ClayM's layout to proof the concept. Just found out that by using "setIntensity" and two variables the whole CLP easily can be dimmed by the lights control panel. That's cool! These values have to be adjusted by your needs, from 0 (dark) to 15 (full brightnes) // variables to dimm by the LCP "SIGNAL LTS" switch (BRT / DIM) byte BRT = 14; // normal brightnes byte DIM = 5; // dimmedand the object to communicate with DCS Bios // dimm the CLP matrix by the LCP "SIGNAL LTS" switch void onLcpSignalLightsChange(unsigned int newValue) { if (newValue == 1) lc.setIntensity(0,BRT); else lc.setIntensity(0,DIM); } DcsBios::IntegerBuffer lcpSignalLightsBuffer(0x1144, 0x0200, 9, onLcpSignalLightsChange); Edited January 17, 2020 by Vinc_Vega Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC]
lesthegrngo Posted June 22, 2020 Author Posted June 22, 2020 Oh well, my Jonah touch with RS485 seems to be spreading. I had a question about my CWP and how to use the matrix, so to try and help I connected it up to try some different matrix mapping to see how it went. But of course I hadn't figured on my reverse Midas touch. The bloody thing will not work now, despite using the same hardware and software. It either lights up all the lights, or doesn't light up at all, and despite checking the wiring, and replacing the MAX7219 chip there's nothing else to check, and I've done that. I can see the RX light on the Nano flashing away, and I tried different Nano's just in case, but I have a dead CWP. **sigh** Oh well, another thing to try and come back to in the future I suppose Les
lesthegrngo Posted June 22, 2020 Author Posted June 22, 2020 Guys, this was a very good lesson today in complacency. My 'good' cable that I checked was not. I had checked it for continuity on my desk by weighting it down with some bits of metal so that I could put the ohmmeter probes on each end. Unfortunately in doing so I inadvertently was masking the issue that was causing the problem. It seems that the conductor wire was broken between the connector pin insulation crimp and the bit that actually crimps the wire itself. When I was weighing down the cable to make it easier to check, I was actually making the broken ends touch, so making contact. The moment you released the weights and flexed the cable, it opened up again and so the problem returned. I hope you learn from my mistake, if you can swap the cable to check do so as well as testing the continuity. Cheers Les
Recommended Posts