PDA

View Full Version : Module TM1638 help please.



lucianocamillo
12-10-2013, 04:23 AM
Module TM1638 help please.
Hello everyone. I'm trying to start a project of Autopilot. I have copied the code from this link http://www.mycockpit.org/forums/showthread.php?t=24715, but my module TM1638 does not light anything. Condigo capture and send data Link2fs and arrange for FSX, but my TM1638 module does not respond. can someone try to help me. I've tested the module with the Arduino examples and works normally. Follow my code.


// #include <quadrature.h>


// #define ENCODER_DO_NOT_USE_INTERRUPTS
#include <encoder.h> //http://www.pjrc.com/teensy/td_libs_Encoder.html#include < SoftwareSerial.h >
#include <tm1638.h> // required because the way arduino deals with libraries
#include <tm1640.h> //http://code.google.com/p/tm1638-library/




// define a module on data pin 3, clock pin 2
TM1638 module1(8, 9, 7);



//define rotary encoders
Encoder AltEnc(2, 3);
Encoder HdgEnc(4, 5);
Encoder Crs1Enc (6, 7);
Encoder SpdEnc(8, 9);
Encoder VsEnc(10, 11);


int led=3; // led no pino 13
int botao=2; // botão no pino 12
int var=0; // valor instantaneo enviado pelo botão
int var2=0; // valor guardado
int estado=0; // guarda o valor 0 ou 1 (HIGH ou LOW)


int j1;
int j2;
int pinState;
int pinNo;
int doutpin;
int apLed = 3;


long AltPosition = -999, HdgPosition = -999, CrsPosition = -999, VsPosition = -999, SpdPosition = -999;




String oldpinStateSTR, pinStateSTR, stringnewstate, stringoldstate, com1, com1old, aphdgset, aphdgsetold, apcrs, apcrsold, output, outputold, apalt, apaltold;




void setup()
{


pinMode(led,OUTPUT);
pinMode(botao,INPUT);






Serial.begin(9600);
for (int doutPin = 8; doutPin <= 43; doutPin++)
{
pinMode(doutPin, INPUT);
digitalWrite(doutPin, HIGH);
}
stringoldstate = "1111111111111111111111111111111111111111111";
Serial.flush();
}




void loop() {

var=digitalRead(botao); // ler o valor enviado pelo botão: "HIGH" ou "LOW"
if ((var == HIGH) && (var2 == LOW)) {
estado = 1 - estado;
delay(20); // de-bouncing
}
var2=var;
if (estado == 1) {
digitalWrite(led, HIGH); // liga o led
} else {
digitalWrite(led, LOW); // desliga o led
}


// read the oldest byte in the serial buffer:
if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == 'r'){ // Found the reading "autopilot heading set"
delay (11); // It seems to need a delay here
aphdgset = "";
aphdgset +=(char)Serial.read();
aphdgset += (char)Serial.read();
aphdgset += (char)Serial.read();




if (aphdgset != aphdgsetold){ // checks to see if its different to the "old" reading




aphdgsetold = aphdgset; // Writes the current reading to the "old" string.
}
}




if (j1 == 'a'){ // Found the reading "crs"
delay (11);
apcrs ="";
apcrs += (char)Serial.read();
apcrs += (char)Serial.read();
apcrs += (char)Serial.read();


if (apcrs != apcrsold){
apcrsold = apcrs;
}
}




if (j1 == 'p'){ // Found the reading "AP ALT"
delay (11);
apalt = "";
apalt += (char)Serial.read();
apalt += (char)Serial.read();
apalt += (char)Serial.read();
apalt += (char)Serial.read();
apalt += (char)Serial.read();


if (apalt != apaltold){
apaltold = apalt;
}
}


output = apcrsold;
output += " ";
output += aphdgsetold;
output += " ";
output += apaltold;




// if (output != outputold){
// module1.setDisplayToString(output);
// outputold = output;


// }

}


// Now the bit for the "keys" input
//oldpinStateSTR = "";
//pinStateSTR = "";
stringnewstate = "";
for (int pinNo = 8; pinNo <= 43; pinNo++){ // <= 69 changed to 43 to avoid problems with rotary enc
pinState = (digitalRead(pinNo));
pinStateSTR = "";
pinStateSTR += pinState;
oldpinStateSTR = "";
oldpinStateSTR += stringoldstate.charAt(pinNo-8);




if (pinStateSTR != oldpinStateSTR)
{
Serial.print ("D");
if (pinNo < 10) Serial.print ("0");
Serial.print (pinNo);
Serial.print (pinStateSTR);
delay(11);
}
stringnewstate += pinState;
}




stringoldstate = stringnewstate;
//delay(11);


// Altitude Encoder Output
long newAltPosition = AltEnc.read()/4;
if (newAltPosition != AltPosition) {
if(AltPosition > newAltPosition){
Serial.print("D450");
}
if(AltPosition < newAltPosition){
Serial.print("D440");
}
AltPosition = newAltPosition;
}
//Heading Encoder Output
long newHdgPosition = HdgEnc.read()/4;


if (newHdgPosition != HdgPosition) {
if(HdgPosition > newHdgPosition){


Serial.print("D470");


}
if(HdgPosition < newHdgPosition){


Serial.print("D460");
}
HdgPosition = newHdgPosition;
}


//Course1 Encoder Output




long newCrsPosition = Crs1Enc.read()/4;


if (newCrsPosition != CrsPosition) {
if(CrsPosition > newCrsPosition){
Serial.print("D490");
}
if(CrsPosition < newCrsPosition){
Serial.print("D480");
}
CrsPosition = newCrsPosition;
}
//Speed Encoder Output
long newSpdPosition = SpdEnc.read()/4;
if (newSpdPosition != SpdPosition) {
if(SpdPosition > newSpdPosition){
Serial.print("D510");
}
if(SpdPosition < newSpdPosition){
Serial.print("D500");
}


SpdPosition = newSpdPosition;
}
//Vertical Speed Encoder Output
long newVsPosition = VsEnc.read()/4;
if (newVsPosition != VsPosition) {
if(VsPosition > newVsPosition){
Serial.print("D530");
}
if(VsPosition < newVsPosition){
Serial.print("D520");
}


VsPosition = newVsPosition;
}


}</tm1640.h></tm1638.h></encoder.h></quadrature.h>

Sammy-E
01-27-2014, 08:07 AM
Do you still have an issue here? I might be of help as I use these modules too.

vikingsraven
01-27-2014, 01:48 PM
http://tronixstuff.com/2012/03/11/arduino-and-tm1638-led-display-modules/ this might be of help!

lucianocamillo
01-27-2014, 08:59 PM
I still can not work with the code I sent. You have a code where TM1638 work? You can send me please.

Fess_ter
01-31-2014, 06:55 PM
If you are using the Link2fs_Multi, then the extractions you are trying to read in your code is incorrect.
I believe you will not find a copy and paste solution.
I recommend leaning to crawl, first.
Take a look at Jim's examples of how to read extractions using the "Case" method. Examples come with the Link2fs_Multi package.
If you have tried some other code with the TM1638 and know how to display to it, that is good.

Ultimately there are 3 things you need to learn to do.
1) Read extracted information from Link2fs_Multi into the Arduino.
2) Display that Extracted information on your TM1638 module.
3) Use a rotary encoder or push buttons to send "SimConnect Inputs" from the Arduino to Link2fs_Multi to make changes in FSX.

My best advice is:
First learn these three things separately then put them together.
You will gain knowledge and experience that you can pass along to others.
Also it will decrease the odds of you rage quitting in frustration.

I hope this helps.
~Fess