16/ 2 LCD TEA 5767 I2C BAĞLANTISI LCD SORUNU
  • Merhaba yapmaya çalıştığım bir radyo projesinde 2 adet i2c bağlantısı yaptığım lcd ve radyo modülünde lcd karakter sorunu yaşıyorum.Devre çalışıyor fakat lcd de karakterler bozuk çıkıyor.Nano ile yaptığım projeyi nano reset düğmesinden 3-4 defa resetledikten sonra lcd normalleşiyor.scl ve sda uçlarına 4.7 k direnç bağladım durum değişmedi.
  • lcd ve nano beslemesine10mf elektrolitik kondansator koy. kabloları kontrol et. nanoyu resetledıgınde lcd resetlenmez nano yenıden başladıgında reset komutu gonderır ınıt ederken bu ınıtler arasına bır mıktar bekleme koy 500ms gibi faydası olur.
  • Maalesef olmadı.kondansatör,direnç,gecikmeler,değişik kütüphaneler denedim.
    Kodlar aşagıdaki gibi.Kullandığım ekipman nano,16,2 lcd,tea 5767 ı2c bağlantılı radyo alıcı modülü.Fakat nanonun reset düğmesine birkaçdefa bastığımda karakter sorunu düzeliyor.




    #include < LiquidCrystal_I2C.h>


    #include < Wire.h>

    // Get TEA5767 library at https://github.com/andykarpov/TEA5767
    #include <TEA5767.h>

    // Encoder pins
    #define ENCODER_SW 2
    #define ENCODER_A 3
    #define ENCODER_B 4

    // Custom characters
    #define SCALE_CLEAR 5 // Radio dial scale
    #define STEREO_CHAR_S 6 // Stylized "S"
    #define STEREO_CHAR_T 7 // Stylized "T"

    // Global status flags
    #define ST_AUTO 0 // Auto mode (toggled by the push button)
    #define ST_STEREO 1 // Radio module detected a stereo pilot
    #define ST_GO_UP 2 // Encoder being turned clockwise
    #define ST_GO_DOWN 3 // Encoder being turned counterclockwise
    #define ST_SEARCH 4 // Radio module is perfoming an automatic search
    TEA5767 Radio;
    float frequency = 87.5;
    byte status = 0;
    LiquidCrystal_I2C lcd(0x27, 16, 2);



    /*******************************************\
    * updateScale() *
    * Moves the "needle" over the radio scale *
    \*******************************************/
    void updateScale() {

    int lcdBase = (frequency - 87.5) * 4; // LCD column pixel index (0 <= lcdBase <= (16 * 5))
    if(lcdBase > 79) lcdBase = 79;

    int lcdMajor = lcdBase / 5; // LCD character index (0 <= lcdMajor <= 15)
    int lcdMinor = lcdBase % 5; // LCD pixel column index within the character (0 <= lcdMinor <= 4)

    if(lcdMajor > 0) {
    // The radio dial needle is not at the leftmost position:
    // clean the character on the left (to erase previous neddle position)
    lcd.setCursor(lcdMajor - 1, 0);
    lcd.write(SCALE_CLEAR);
    } else
    lcd.setCursor(lcdMajor, 0);
    lcd.write(lcdMinor);

    if(lcdMajor < 15)
    // Not at rightmost position: clear the character on the right


    lcd.write(SCALE_CLEAR);
    }


    /******************************\
    * isrEncoder() *
    * Catch encoder´s interrupts *
    \******************************/
    void isrEncoder() {

    delay(50); // Debouncing (for crappy encoders)
    if(digitalRead(ENCODER_B) == HIGH){
    bitWrite(status, ST_GO_UP, 1);
    } else
    bitWrite(status, ST_GO_DOWN, 1);
    }


    /*****************************\
    * isrSwitch() *
    * Catch switch´s interrupts *
    \*****************************/
    void isrSwitch() {

    delay(50); // Debouncing
    if(bitRead(status, ST_AUTO))
    bitWrite(status, ST_AUTO, 0);
    else
    bitWrite(status, ST_AUTO, 1);
    }


    /*******************\
    * Arduino Setup() *
    \*******************/
    void setup() {
    Serial.begin (9600);

    int i;
    byte needleChar[8];

    // Stylized "S"
    byte stereoChar1[8] = {
    0b01111,
    0b11000,
    0b11011,
    0b11101,
    0b11110,
    0b11000,
    0b01111,
    0b00000
    };
    lcd.createChar(STEREO_CHAR_S, stereoChar1);

    // Stylized "T"
    byte stereoChar2[8] = {
    0b11110,
    0b00011,
    0b10111,
    0b10111,
    0b10111,
    0b10111,
    0b11110,
    0b00000
    };
    lcd.createChar(STEREO_CHAR_T, stereoChar2);

    // Dial scale background
    byte scaleChar[8] = {
    0b00000,
    0b00000,
    0b00000,
    0b00000,
    0b00000,
    0b00100,
    0b10101,
    0b10101
    };
    lcd.createChar(SCALE_CLEAR, scaleChar);

    // Create custom character to represent all (5) possible needle´s position
    for(int j = 0; j < 5; j++) {
    for(i = 0; i < 8; i++)
    needleChar[i] = scaleChar[i] | (0b10000 >> j);
    lcd.createChar(j, needleChar);
    }

    delay (100);
    lcd.begin();
    delay(100);
    lcd.clear();
    delay(100);

    lcd.backlight();
    lcd.clear();

    // Draw the dial scale´s background
    for(i = 0; i < 16; i++)
    lcd.write(SCALE_CLEAR);



    pinMode(ENCODER_SW, INPUT); digitalWrite(ENCODER_SW, HIGH);
    pinMode(ENCODER_A, INPUT); digitalWrite(ENCODER_A, HIGH);
    pinMode(ENCODER_B, INPUT); digitalWrite(ENCODER_B, HIGH);

    attachInterrupt(0, isrSwitch, RISING);
    attachInterrupt(1, isrEncoder, RISING);

    // Initialize the radio module

    Wire.begin();

    Radio.init();
    Radio.set_frequency(frequency);
    }


    /******************\
    * Arduino Loop() *
    \******************/
    void loop() {

    unsigned char buf[5];
    int stereo;
    int signalLevel;
    int searchDirection;

    // Update the Auto / Manual indicator
    lcd.setCursor(12, 1);
    lcd.write(bitRead(status, ST_AUTO) ? 'A' : 'M');

    if (Radio.read_status(buf) == 1) {
    // Get radio data
    frequency = floor(Radio.frequency_available(buf) / 100000 + .5) / 10;
    stereo = Radio.stereo(buf);
    // 0 <= Radio.signal_level <= 15
    signalLevel = (Radio.signal_level(buf) * 100) / 15;

    // Update the radio dial
    updateScale();

    // Signal level indicator
    lcd.setCursor(0, 1);
    lcd.write(183); // Japanese character that looks like an antenna :)
    if(signalLevel < 100) lcd.write(' ');
    lcd.print(signalLevel);
    lcd.write('%');

    // Frequency indicator
    lcd.setCursor(6, 1);
    if(frequency < 100) lcd.write(' ');
    lcd.print(frequency, 1);

    // Mono / stereo indicator
    lcd.setCursor(14, 1);
    if(stereo){
    lcd.write(STEREO_CHAR_S);
    lcd.write(STEREO_CHAR_T);
    } else
    lcd.print(" ");
    }

    if(bitRead(status, ST_SEARCH)) { // Is the radio performing an automatic search?
    if(Radio.process_search(buf, searchDirection) == 1) {
    bitWrite(status, ST_SEARCH, 0);
    }
    }

    // Encoder being turned clockwise (+)
    if(bitRead(status, ST_GO_UP)) {
    if(bitRead(status, ST_AUTO) && !bitRead(status, ST_SEARCH)) {
    // Automatic search mode (only processed if the radio is not currently performing a search)
    bitWrite(status, ST_SEARCH, 1);
    searchDirection = TEA5767_SEARCH_DIR_UP;
    Radio.search_up(buf);
    delay(50);
    } else {
    // Manual tuning mode
    if(frequency < 108) {
    frequency += 0.1;
    Radio.set_frequency(frequency);
    }
    }
    bitWrite(status, ST_GO_UP, 0);
    }

    // Encoder being turned counterclockwise (-)
    if(bitRead(status, ST_GO_DOWN)) {
    if(bitRead(status, ST_AUTO) && !bitRead(status, ST_SEARCH)) {
    // Automatic search mode (only processed if the radio is not currently performing a search)
    bitWrite(status, ST_SEARCH, 1);
    searchDirection = TEA5767_SEARCH_DIR_DOWN;
    Radio.search_down(buf);
    delay(50);
    } else {
    // Manual tuning mode
    if(frequency > 87.5) {
    frequency -= 0.1;
    Radio.set_frequency(frequency);
    }
    }
    bitWrite(status, ST_GO_DOWN, 0);
    }

    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook
Açık kaynak kültürü gereği, çözdüğünüz problemlerin çözümlerini paylaşmayı lütfen unutmayın.