Jump to content

i2c дисплей и зависание ардуино


 Share

Recommended Posts

имеем: ардуино нано дисплей 1602 с i2c переходником блок релюшек 4 кнопки. все работало около часа при различних кнопкотыканиях. и на испытании произошла непонятная програмная ошибка: сначала вылезли случайные символы потом потухла подсветка, хотя как понял она управляется перемычкой. при дальнейшем перезапуске на выходах висит 0 и нет никакой реакции на нажатия. убрал из программы дисплей и она заработала. пробовал переустановить библиотеки liquid cristal i2c но не помогло. пробовал отключать дисплей. даже инвертированные выходы лежат в 0. код прилагаю

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
const byte _menuParametrsArray[]  PROGMEM =  {1, 3, 2, 0, 0, 0, 5, 6, 1, 8, 3, 0, 2, 3, 1, 0, 0, 0, 5, 6, 1, 8, 1, 0, 3, 4, 1, 0, 0, 0, 2, 3, 1, 4, 2, 0, 4, 3, 3, 0, 0, 0, 5, 6, 1, 8, 4, 0};
bool _menuValueArray_bool[3];
const bool _menuConstantValuesArray_bool[]  PROGMEM =  {1, 0};
int _menuValueArray_int[1];
const int _menuConstantValuesArray_int[]  PROGMEM =  {3, 15, -3};
const char _flprogMenuNameString1[] PROGMEM = "dislink";
const char _flprogMenuNameString2[] PROGMEM = "attenuator";
const char _flprogMenuNameString3[] PROGMEM = "cross line";
const char _flprogMenuNameString4[] PROGMEM = "noise generaror";
const char _flprogMenuNameString5[] PROGMEM = "ON";
const char _flprogMenuNameString6[] PROGMEM = "OFF";
const char* const _flprogMenuStringsArray[] PROGMEM = { _flprogMenuNameString1,  _flprogMenuNameString2,  _flprogMenuNameString3,  _flprogMenuNameString4,  _flprogMenuNameString5,  _flprogMenuNameString6};
struct _menuItemStricture 
{
     int startInArrayIndex;
}
;
struct _menuMainStricture 
{
    byte startIndex;
    byte stopIndex;
    bool isSwitchMenuAroundRing;
    _menuItemStricture  currentItem;
}
;
_menuItemStricture _MenuItems[4];
_menuMainStricture _MainMenus[1];
String _MenuBlock_41244328_MNO;
String _MenuBlock_41244328_VNO;
bool _MenuBlock_41244328_OEIS = 0;
bool _MenuBlock_41244328_OMUIS = 0;
bool _MenuBlock_41244328_OMDIS = 0;
bool _MenuBlock_41244328_OVUIS = 0;
bool _MenuBlock_41244328_OVDIS = 0;
bool _bounseInputD0S = 0;
bool _bounseInputD0O = 0;
unsigned long _bounseInputD0P = 0UL;
int _disp2oldLength = 0;
bool _bounseInputD2S = 0;
bool _bounseInputD2O = 0;
unsigned long _bounseInputD2P = 0UL;
int _disp1oldLength = 0;
bool _bounseInputD1S = 0;
bool _bounseInputD1O = 0;
unsigned long _bounseInputD1P = 0UL;
bool _bounseInputD3S = 0;
bool _bounseInputD3O = 0;
unsigned long _bounseInputD3P = 0UL;
bool _tempVariable_bool;
byte _tempVariable_byte;
void setup()
{
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(4, OUTPUT);
    digitalWrite(4, 0);
    pinMode(5, OUTPUT);
    digitalWrite(5, 0);
    pinMode(6, OUTPUT);
    digitalWrite(6, 0);
    pinMode(7, OUTPUT);
    digitalWrite(7, 0);
    pinMode(8, OUTPUT);
    digitalWrite(8, 0);
    pinMode(9, OUTPUT);
    digitalWrite(9, 0);
    pinMode(10, OUTPUT);
    digitalWrite(10, 0);
    pinMode(11, OUTPUT);
    digitalWrite(11, 0);
    pinMode(12, OUTPUT);
    digitalWrite(12, 0);
    pinMode(13, OUTPUT);
    digitalWrite(13, 0);
    Wire.begin();
    delay(10);
    _lcd1.init();
    _lcd1.backlight();
    _bounseInputD0O =  digitalRead(0);
    _bounseInputD3O =  digitalRead(3);
    _bounseInputD1O =  digitalRead(1);
    _bounseInputD2O =  digitalRead(2);
    _MenuItems[0].startInArrayIndex = 0;
    _MenuItems[1].startInArrayIndex = 12;
    _MenuItems[2].startInArrayIndex = 24;
    _MenuItems[3].startInArrayIndex = 36;
    _MainMenus[0].startIndex = 1;
    _MainMenus[0].isSwitchMenuAroundRing = 1;
    _MainMenus[0].stopIndex = 4;
    _MainMenus[0].currentItem = _MenuItems[0];
}
void loop()
{
    if (_isNeedClearDisp1) 
    {
        _lcd1.clear();
        _isNeedClearDisp1= 0;
    }
    bool  _bounceInputTmpD0 =  (digitalRead (0));
    if (_bounseInputD0S)
    {
        if (millis() >= (_bounseInputD0P + 40))
        {
            _bounseInputD0O= _bounceInputTmpD0;
            _bounseInputD0S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD0 != _bounseInputD0O)
        {
            _bounseInputD0S=1;
            _bounseInputD0P = millis();
        }
    }
    bool  _bounceInputTmpD3 =  (digitalRead (3));
    if (_bounseInputD3S)
    {
        if (millis() >= (_bounseInputD3P + 40))
        {
            _bounseInputD3O= _bounceInputTmpD3;
            _bounseInputD3S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD3 != _bounseInputD3O)
        {
            _bounseInputD3S=1;
            _bounseInputD3P = millis();
        }
    }
    bool  _bounceInputTmpD1 =  (digitalRead (1));
    if (_bounseInputD1S)
    {
        if (millis() >= (_bounseInputD1P + 40))
        {
            _bounseInputD1O= _bounceInputTmpD1;
            _bounseInputD1S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD1 != _bounseInputD1O)
        {
            _bounseInputD1S=1;
            _bounseInputD1P = millis();
        }
    }
    bool  _bounceInputTmpD2 =  (digitalRead (2));
    if (_bounseInputD2S)
    {
        if (millis() >= (_bounseInputD2P + 40))
        {
            _bounseInputD2O= _bounceInputTmpD2;
            _bounseInputD2S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD2 != _bounseInputD2O)
        {
            _bounseInputD2S=1;
            _bounseInputD2P = millis();
        }
    }
    //Плата:1
    digitalWrite(4, (_menuValueArray_bool[1]));
    digitalWrite(5, !((_menuValueArray_bool[0])));
    digitalWrite(13, ((((_bounseInputD0O) || (_bounseInputD1O))) || (((_bounseInputD3O) || (_bounseInputD2O)))));
    if (1) 
    {
        _tempVariable_bool  =  1;
        if (! _MenuBlock_41244328_OEIS) 
        {
            _MenuBlock_41244328_OEIS = 1;
        }
        _tempVariable_byte = pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+10]);
        _MenuBlock_41244328_MNO = _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[_tempVariable_byte - 1])));
        _MenuBlock_41244328_VNO = _menuOutputValueString (0);
    }
     else 
    {
        _tempVariable_bool  =  0;
        if (_MenuBlock_41244328_OEIS)
        {
            _MenuBlock_41244328_OEIS = 0;
        }
        _MenuBlock_41244328_MNO = "";
        _MenuBlock_41244328_VNO = "";
    }
    if(_bounseInputD0O) 
    {
         if (! _MenuBlock_41244328_OMUIS) 
        {
            _MenuBlock_41244328_OMUIS = 1;
            if(_tempVariable_bool)
            {
                  _menuUpEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_41244328_OMUIS = 0;
    }
    if(_bounseInputD1O) 
    {
         if (! _MenuBlock_41244328_OMDIS) 
        {
            _MenuBlock_41244328_OMDIS = 1;
            if(_tempVariable_bool)
            {
                   _menuDownEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_41244328_OMDIS = 0;
    }
    if(_bounseInputD3O) 
    {
         if (! _MenuBlock_41244328_OVUIS) 
        {
            _MenuBlock_41244328_OVUIS = 1;
            if(_tempVariable_bool)
            {
                  _valueUpEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_41244328_OVUIS = 0;
    }
    if(_bounseInputD2O) 
    {
         if (! _MenuBlock_41244328_OVDIS) 
        {
            _MenuBlock_41244328_OVDIS = 1;
            if(_tempVariable_bool)
            {
                  _valueDownEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_41244328_OVDIS = 0;
    }
    if (1) 
    {
        _dispTempLength1 = ((_MenuBlock_41244328_VNO)).length();
        if (_disp2oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp2oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 1);
        _lcd1.print((_MenuBlock_41244328_VNO));
    }
     else 
    {
        if (_disp2oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp2oldLength = 0;
        }
    }
    if (1) 
    {
        _dispTempLength1 = ((_MenuBlock_41244328_MNO)).length();
        if (_disp1oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp1oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 0);
        _lcd1.print((_MenuBlock_41244328_MNO));
    }
     else 
    {
        if (_disp1oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp1oldLength = 0;
        }
    }
    digitalWrite(6, !((_menuValueArray_bool[2])));
    digitalWrite(7, !(((String("0")).equals((String(0, DEC))))));
    digitalWrite(8, !(((String("3")).equals((String(0, DEC))))));
    digitalWrite(9, !(((String("6")).equals((String(0, DEC))))));
    digitalWrite(10, !(((String("9")).equals((String(0, DEC))))));
    digitalWrite(11, !(((String("12")).equals((String(0, DEC))))));
    digitalWrite(12, !(((String("-3")).equals((String(0, DEC))))));
}
String _readStringFromProgmem (char *string)
{
    String result = String("");
    while (pgm_read_byte(string)!='\0')
    {
        result=result+ char(pgm_read_byte(string));
        	string++;
        	
    }
    return result;
}
void _menuUpEvents (byte menuIndex)
{
    byte tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
    byte parIndex = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
    byte parentStartIndex;
    byte parentStopIndex;
    if (parIndex == 0) 
    {
        parentStartIndex = (_MainMenus[menuIndex]).startIndex;
        parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
    }
    else 
    {
        parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex - 1]).startInArrayIndex)+3]);
        parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
    }
    if (tempIndex == parentStartIndex) 
    {
        if((_MainMenus[menuIndex]).isSwitchMenuAroundRing) 
        {
            (_MainMenus[menuIndex]).currentItem = _MenuItems[parentStopIndex -1];
            return;
        }
         else
        {
            return;
        }
    }
    (_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex - 2];
    return;
}
void _menuDownEvents (byte menuIndex)
{
    byte tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
    byte parIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
    byte parentStartIndex;
    byte parentStopIndex;
    if (parIndex == 0) 
    {
        parentStartIndex = (_MainMenus[menuIndex]).startIndex;
        parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
    }
    else 
    {
        parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+3]);
        parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
    }
    if (tempIndex == parentStopIndex) 
    {
        if((_MainMenus[menuIndex]).isSwitchMenuAroundRing) 
        {
            (_MainMenus[menuIndex]).currentItem = _MenuItems[parentStartIndex -1];
            return;
        }
         else
        {
            return;
        }
    }
    (_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex];
    return;
}
void _valueUpEvents (byte menuIndex)
{
    byte valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    byte itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    byte indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
    byte indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
    if(itemType ==3) 
    {
        _menuValueArray_bool[valIndex - 1 ] = 1;
        return;
    }
    if (itemType == 4) 
    {
        if (! indexMax == 0) 
        {
             if (! (int(pgm_read_word(&_menuConstantValuesArray_int[indexMax -1])) > int(_menuValueArray_int[valIndex -1]))) 
            {
                return;
            }
        }
        _menuValueArray_int[valIndex -1] = _menuValueArray_int[valIndex -1] + (pgm_read_word(&_menuConstantValuesArray_int[indexStep -1]));
    }
}
void _valueDownEvents (byte menuIndex)
{
    byte valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    byte itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    byte indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
    byte indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
    if(itemType ==3) 
    {
        _menuValueArray_bool[valIndex -1] = 0;
        return;
    }
    if (itemType == 4) 
    {
        if (! indexMin == 0) 
        {
             if (! ((int(pgm_read_word(&_menuConstantValuesArray_int[indexMin - 1]))) < int(_menuValueArray_int[valIndex - 1]))) 
            {
                return;
            }
        }
        _menuValueArray_int[valIndex - 1] = _menuValueArray_int[valIndex - 1] - (pgm_read_word(&_menuConstantValuesArray_int[indexStep - 1]));
    }
}
String _menuOutputValueString (byte menuIndex)
{
    byte itemType = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    byte valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    byte indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
    byte indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
    if(valIndex == 0)
    {
         return "";
    }
    byte convFormat = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+9]);
    if(itemType == 3) 
    {
         return _convertBoolean(itemType, convFormat, valIndex, indexMax, indexMin);
    }
    if(itemType == 4) 
    {
         return _convertNamber(itemType, convFormat, valIndex, indexMax, indexMin);
    }
    return "";
}
String _convertNamber(byte itemType, byte convFormat, byte valIndex, byte indexMax, byte indexMin)
{
    if (itemType== 4) 
    {
        if (convFormat == 4) 
        {
             return String((_menuValueArray_int[valIndex - 1 ]),DEC);
        }
        if (convFormat == 5) 
        {
             return String((_menuValueArray_int[valIndex - 1]),HEX);
        }
        if (convFormat == 6) 
        {
             return String((_menuValueArray_int[valIndex -1]),BIN);
        }
    }
}
String _convertBoolean(byte itemType, byte convFormat, byte valIndex, byte indexMax, byte indexMin)
{
    if (convFormat == 1) 
    {
         if(_menuValueArray_bool[valIndex -1]) 
        {
            return "1";
        }
         else
        {
             return "0";
        }
    }
    if (convFormat == 2) 
    {
         if(_menuValueArray_bool[valIndex -1]) 
        {
            return "True";
        }
         else
        {
             return "False";
        }
    }
    if (convFormat == 3) 
    {
         if(_menuValueArray_bool[valIndex -1 ]) 
        {
            return "Да";
        }
         else
        {
             return "Нет";
        }
    }
    if(_menuValueArray_bool[valIndex -1]) 
    {
        return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMax - 1])));
    }
     else 
    {
         return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMin - 1])));
    }
}

 

пишу в flprog

i2c сканер тоже молчит и не отправляет данные через порт

 

Link to comment
Share on other sites

16 минут назад, демидос сказал:

выходах висит 0

16 минут назад, демидос сказал:

даже инвертированные выходы лежат в 0

за что люблю стм32, замкнул ногу, она покраснела, пошел дым, сгорела дорожка, но МК цел. А в АВР постоянно даже если чихнуть у меня сгорали выходы :D

Может стоит просто тестовую прошивку для начала сделать которая тупо раз в секунду переключает выводы чтоб проверить выводы МК? Толку от кода если нет схемы например и не понятно чем подтянуты ноги i2c. Если внутренними резюками то может выгорели. А программа что? Если она работала, а потом ее не переписывали и перестало работать то есть вероятность проблемы в железе.

Link to comment
Share on other sites

Реле, разъемы, вентиляторы, корпуса, микросхемы, конденсаторы и много другое!

Скидки до 20% на сайте электронного дискаунтера ТМ Электроникс.

Бесплатная доставка в любую точку России + кэшбэк 15%.

Всем кто сделает заказ в сентябре, начислим 3000 баллов на аккаунт. 1 балл = 1 рублю!

Подробнее

22 минуты назад, DrobyshevAlex сказал:

за что люблю стм32, замкнул ногу, она покраснела, пошел дым, сгорела дорожка, но МК цел. А в АВР постоянно даже если чихнуть у меня сгорали выходы :D

Может стоит просто тестовую прошивку для начала сделать которая тупо раз в секунду переключает выводы чтоб проверить выводы МК? Толку от кода если нет схемы например и не понятно чем подтянуты ноги i2c. Если внутренними резюками то может выгорели. А программа что? Если она работала, а потом ее не переписывали и перестало работать то есть вероятность проблемы в железе.

тестовая прошибка без дисплея работает. програмно подтяжку не указывал. блинк тоже работает

Link to comment
Share on other sites

Литиевые батарейки и аккумуляторы от мирового лидера  EVE в Компэл

Компания Компэл, официальный дистрибьютор EVE Energy, бренда №1 по производству химических источников тока (ХИТ) в мире, предлагает продукцию EVE как со склада, так и под заказ. Компания EVE широко известна в странах Европы, Америки и Юго-Восточной Азии уже более 20 лет. Недавно EVE была объявлена поставщиком новых аккумуляторных элементов круглого формата для электрических моделей «нового класса» компании BMW.

Продукция EVE предназначена для самого широкого спектра применений – от бытового до промышленного. Подробнее>>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...