1602

ksilius
Offline
Зарегистрирован: 12.04.2022

Здравствуйте, хочу повторить схему металлоискателя на ардуино, есть такой код, в коде есть дисплей 1602 без адаптера I2C у меня адаптер запаян и не хочется отпаивать. Прошу помощи в прописке данного адаптера в этот код. Сам пробовал вставлять адаптер с адресом закоментировав при этом выводы на дисплей но вылазит ошибка.

001// Induction balance metal detector
002 
003// We run the CPU at 16MHz and the ADC clock at 1MHz. ADC resolution is reduced to 8 bits at this speed.
004 
005// Timer 1 is used to divide the system clock by about 256 to produce a 62.5kHz square wave.
006// This is used to drive timer 0 and also to trigger ADC conversions.
007// Timer 0 is used to divide the output of timer 1 by 8, giving a 7.8125kHz signal for driving the transmit coil.
008// This gives us 16 ADC clock cycles for each ADC conversion (it actually takes 13.5 cycles), and we take 8 samples per cycle of the coil drive voltage.
009// The ADC implements four phase-sensitive detectors at 45 degree intervals. Using 4 instead of just 2 allows us to cancel the third harmonic of the
010// coil frequency.
011 
012// Timer 2 will be used to generate a tone for the earpiece or headset.
013 
014// Other division ratios for timer 1 are possible, from about 235 upwards.
015 
016// Wiring:
017// Connect digital pin 4 (alias T0) to digital pin 9
018// Connect digital pin 5 through resistor to primary coil and tuning capacitor
019// Connect output from receive amplifier to analog pin 0. Output of receive amplifier should be biased to about half of the analog reference.
020// When using USB power, change analog reference to the 3.3V pin, because there is too much noise on the +5V rail to get good sensitivity.
021#include <LiquidCrystal.h>
022#include <LcdBarGraph.h>
023#define max_ampAverage 200
024LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
025LcdBarGraph lbg(&lcd, 16, 0, 1);
026 
027#define TIMER1_TOP  (259)        // can adjust this to fine-tune the frequency to get the coil tuned (see above)
028 
029#define USE_3V3_AREF  (1)        // set to 1 of running on an Arduino with USB power, 0 for an embedded atmega28p with no 3.3V supply available
030 
031// Digital pin definitions
032// Digital pin 0 not used, however if we are using the serial port for debugging then it's serial input
033const int debugTxPin = 1;        // transmit pin reserved for debugging
034const int encoderButtonPin = 2;  // encoder button, also IN0 for waking up from sleep mode
035const int earpiecePin = 3;       // earpiece, aka OCR2B for tone generation
036const int T0InputPin = 4;
037const int coilDrivePin = 5;
038const int LcdRsPin = 6;
039const int LcdEnPin = 7;
040const int LcdPowerPin = 8;       // LCD power and backlight enable
041const int T0OutputPin = 9;
042const int lcdD4Pin = 10;
043const int lcdD5Pin = 11;         // pins 11-13 also used for ICSP
044const int LcdD6Pin = 12;
045const int LcdD7Pin = 13;
046 
047// Analog pin definitions
048const int receiverInputPin = 0;
049const int encoderAPin = A1;
050const int encoderBpin = A2;
051// Analog pins 3-5 not used
052 
053// Variables used only by the ISR
054int16_t bins[4];                 // bins used to accumulate ADC readings, one for each of the 4 phases
055uint16_t numSamples = 0;
056const uint16_t numSamplesToAverage = 1024;
057 
058// Variables used by the ISR and outside it
059volatile int16_t averages[4];    // when we've accumulated enough readings in the bins, the ISR copies them to here and starts again
060volatile uint32_t ticks = 0;     // system tick counter for timekeeping
061volatile bool sampleReady = false// indicates that the averages array has been updated
062 
063// Variables used only outside the ISR
064int16_t calib[4];                // values (set during calibration) that we subtract from the averages
065 
066volatile uint8_t lastctr;
067volatile uint16_t misses = 0;    // this counts how many times the ISR has been executed too late. Should remain at zero if everything is working properly.
068 
069const double halfRoot2 = sqrt(0.5);
070const double quarterPi = 3.1415927/4.0;
071const double radiansToDegrees = 180.0/3.1415927;
072 
073// The ADC sample and hold occurs 2 ADC clocks (= 32 system clocks) after the timer 1 overflow flag is set.
074// This introduces a slight phase error, which we adjust for in the calculations.
075const float phaseAdjust = (45.0 * 32.0)/(float)(TIMER1_TOP + 1);
076 
077float threshold = 5.0;          // lower = greater sensitivity. 10 is just about usable with a well-balanced coil.
078                                 // The user will be able to adjust this via a pot or rotary encoder.
079 
080void setup()
081{
082  lcd.begin(16, 2);// LCD 16X2
083  pinMode(encoderButtonPin, INPUT_PULLUP); 
084  digitalWrite(T0OutputPin, LOW);
085  pinMode(T0OutputPin, OUTPUT);       // pulse pin from timer 1 used to feed timer 0
086  digitalWrite(coilDrivePin, LOW);
087  pinMode(coilDrivePin, OUTPUT);      // timer 0 output, square wave to drive transmit coil
088   
089  cli();
090  // Stop timer 0 which was set up by the Arduino core
091  TCCR0B = 0;        // stop the timer
092  TIMSK0 = 0;        // disable interrupt
093  TIFR0 = 0x07;      // clear any pending interrupt
094   
095  // Set up ADC to trigger and read channel 0 on timer 1 overflow
096#if USE_3V3_AREF
097  ADMUX = (1 << ADLAR);                   // use AREF pin (connected to 3.3V) as voltage reference, read pin A0, left-adjust result
098#else
099  ADMUX = (1 << REFS0) | (1 << ADLAR);    // use Avcc as voltage reference, read pin A0, left-adjust result
100#endif 
101  ADCSRB = (1 << ADTS2) | (1 << ADTS1);   // auto-trigger ADC on timer/counter 1 overflow
102  ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | (1 << ADPS2);  // enable adc, enable auto-trigger, prescaler = 16 (1MHz ADC clock)
103  DIDR0 = 1;
104 
105  // Set up timer 1.
106  // Prescaler = 1, phase correct PWM mode, TOP = ICR1A
107  TCCR1A = (1 << COM1A1) | (1 << WGM11);
108  TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10);    // CTC mode, prescaler = 1
109  TCCR1C = 0;
110  OCR1AH = (TIMER1_TOP/2 >> 8);
111  OCR1AL = (TIMER1_TOP/2 & 0xFF);
112  ICR1H = (TIMER1_TOP >> 8);
113  ICR1L = (TIMER1_TOP & 0xFF);
114  TCNT1H = 0;
115  TCNT1L = 0;
116  TIFR1 = 0x07;      // clear any pending interrupt
117  TIMSK1 = (1 << TOIE1);
118 
119  // Set up timer 0
120  // Clock source = T0, fast PWM mode, TOP (OCR0A) = 7, PWM output on OC0B
121  TCCR0A = (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
122  TCCR0B = (1 << CS00) | (1 << CS01) | (1 << CS02) | (1 << WGM02);
123  OCR0A = 7;
124  OCR0B = 3;
125  TCNT0 = 0;
126  sei();
127   
128  while (!sampleReady) {}    // discard the first sample
129  misses = 0;
130  sampleReady = false;
131   
132  Serial.begin(19200);
133}
134 
135// Timer 0 overflow interrupt. This serves 2 purposes:
136// 1. It clears the timer 0 overflow flag. If we don't do this, the ADC will not see any more Timer 0 overflows and we will not get any more conversions.
137// 2. It increments the tick counter, allowing is to do timekeeping. We get 62500 ticks/second.
138// We now read the ADC in the timer interrupt routine instead of having a separate comversion complete interrupt.
139ISR(TIMER1_OVF_vect)
140{
141  ++ticks;
142  uint8_t ctr = TCNT0;
143  int16_t val = (int16_t)(uint16_t)ADCH;    // only need to read most significant 8 bits
144  if (ctr != ((lastctr + 1) & 7))
145  {
146    ++misses;
147  }
148  lastctr = ctr;
149  int16_t *p = &bins[ctr & 3];
150  if (ctr < 4)
151  {
152    *p += (val);
153    if (*p > 15000) *p = 15000;
154  }
155  else
156  {
157    *p -= val;
158    if (*p < -15000) *p = -15000;
159  }
160  if (ctr == 7)
161  {
162    ++numSamples;
163    if (numSamples == numSamplesToAverage)
164    {
165      numSamples = 0;
166      if (!sampleReady)      // if previous sample has been consumed
167      {
168        memcpy((void*)averages, bins, sizeof(averages));
169        sampleReady = true;
170      }
171      memset(bins, 0, sizeof(bins));
172    }
173  }
174}
175 
176void loop()
177{
178  while (!sampleReady) {}
179  uint32_t oldTicks = ticks;
180   
181  if (digitalRead(encoderButtonPin) == LOW)
182  {
183    // Calibrate button pressed. We save the current phase detector outputs and subtract them from future results.
184    // This lets us use the detector if the coil is slightly off-balance.
185    // It would be better to everage several samples instead of taking just one.
186    for (int i = 0; i < 4; ++i)
187    {
188      calib[i] = averages[i];
189    }
190    sampleReady = false;
191    Serial.print("Calibrated: ");
192     
193    lcd.setCursor(0,0);
194    lcd.print("Calibrating...  ");   
195    for (int i = 0; i < 4; ++i)
196    {
197      Serial.write(' ');
198       
199      Serial.print(calib[i]);
200     
201    lcd.setCursor(0,1);   
202    lcd.print(' ');   
203    lcd.print(calib[4]);
204    lcd.print("        ");    
205    }
206    Serial.println();
207  }
208  else
209  
210    for (int i = 0; i < 4; ++i)
211    {
212      averages[i] -= calib[i];
213    }
214    const double f = 200.0;
215     
216    // Massage the results to eliminate sensitivity to the 3rd harmonic, and divide by 200
217    double bin0 = (averages[0] + halfRoot2 * (averages[1] - averages[3]))/f;
218    double bin1 = (averages[1] + halfRoot2 * (averages[0] + averages[2]))/f;
219    double bin2 = (averages[2] + halfRoot2 * (averages[1] + averages[3]))/f;
220    double bin3 = (averages[3] + halfRoot2 * (averages[2] - averages[0]))/f;
221    sampleReady = false;          // we've finished reading the averages, so the ISR is free to overwrite them again
222 
223    double amp1 = sqrt((bin0 * bin0) + (bin2 * bin2));
224    double amp2 = sqrt((bin1 * bin1) + (bin3 * bin3));
225    double ampAverage = (amp1 + amp2)/2.0;
226     
227    // The ADC sample/hold takes place 2 clocks after the timer overflow
228    double phase1 = atan2(bin0, bin2) * radiansToDegrees + 45.0;
229    double phase2 = atan2(bin1, bin3) * radiansToDegrees;
230   
231    if (phase1 > phase2)
232    {
233      double temp = phase1;
234      phase1 = phase2;
235      phase2 = temp;
236    }
237     
238    double phaseAverage = ((phase1 + phase2)/2.0) - phaseAdjust;
239    if (phase2 - phase1 > 180.0)
240    {
241      if (phaseAverage < 0.0)
242      {
243        phaseAverage += 180.0;
244      }
245      else
246      {
247        phaseAverage -= 180.0;
248      }
249    }
250         
251    // For diagnostic purposes, print the individual bin counts and the 2 indepedently-calculated gains and phases                                                       
252    Serial.print(misses);
253    Serial.write(' ');
254     
255    if (bin0 >= 0.0) Serial.write(' ');
256    Serial.print(bin0, 2);
257    Serial.write(' ');
258    if (bin1 >= 0.0) Serial.write(' ');
259    Serial.print(bin1, 2);
260    Serial.write(' ');
261    if (bin2 >= 0.0) Serial.write(' ');
262    Serial.print(bin2, 2);
263    Serial.write(' ');
264    if (bin3 >= 0.0) Serial.write(' ');
265    Serial.print(bin3, 2);
266    Serial.print("    ");
267    Serial.print(amp1, 2);
268    Serial.write(' ');
269    Serial.print(amp2, 2);
270    Serial.write(' ');
271    if (phase1 >= 0.0) Serial.write(' ');
272    Serial.print(phase1, 2);
273    Serial.write(' ');
274    if (phase2 >= 0.0) Serial.write(' ');
275    Serial.print(phase2, 2);
276    Serial.print("    ");
277     
278    // Print the final amplitude and phase, which we use to decide what (if anything) we have found)
279    if (ampAverage >= 0.0) Serial.write(' ');
280    Serial.print(ampAverage, 1);
281    Serial.write(' ');
282         
283        lcd.setCursor(0,0);
284        lcd.print("          ");
285        lcd.print(ampAverage);       
286        lcd.setCursor(0,1);
287        lbg.drawValue(ampAverage, max_ampAverage);
288 
289    if (phaseAverage >= 0.0) Serial.write(' ');
290    Serial.print((int)phaseAverage);
291     
292    // Decide what we have found and tell the user
293    if (ampAverage >= threshold)
294    {
295      // When held in line with the centre of the coil:
296      // - non-ferrous metals give a negative phase shift, e.g. -90deg for thick copper or aluminium, a copper olive, -30deg for thin alumimium.
297      // Ferrous metals give zero phase shift or a small positive phase shift.
298      // So we'll say that anything with a phase shift below -20deg is non-ferrous.
299      if (phaseAverage < -20.0)
300      {
301        Serial.print(" Non-ferrous");
302        lcd.setCursor(0,0);       
303        lcd.print("NonFerous ");     
304      
305      }
306      else
307      {
308        Serial.print(" Ferrous");       
309        lcd.setCursor(0,0);      
310        lcd.print("Ferrous    ");                
311      }
312      float temp = ampAverage;
313               
314       int thisPitch = map (temp, 10, 200, 100, 1500);
315       tone(3, thisPitch,120);
316        
317      while (temp > threshold)
318      {
319        Serial.write('!');     
320        temp -= (threshold/2);
321      }
322    }  
323    Serial.println();
324    
325   }
326  while (ticks - oldTicks < 8000)
327  {
328  }     
329}

 

v258
v258 аватар
Offline
Зарегистрирован: 25.05.2020

Вместо библиотеки LiquidCrystal используйте библиотеку LiquidCrystal_I2C

ksilius
Offline
Зарегистрирован: 12.04.2022

Все библиотеки на месте и работаю проверено на хало ворлд. Я может чуть знаю что такое ардуино верхушек нахватался но осоцилограф на ардуино спаял.

 

b707
Offline
Зарегистрирован: 26.05.2017

ksilius пишет:

Все библиотеки на месте и работаю проверено на хало ворлд.

если "все библиотеки на месте и работают" - в чем тогда вопрос?

v258
v258 аватар
Offline
Зарегистрирован: 25.05.2020

Еще раз - Вместо библиотеки LiquidCrystal используйте библиотеку LiquidCrystal_I2C

Или буковки I2C в конце названия ни о чем не говорят?

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

v258 пишет:

Еще раз - Вместо библиотеки LiquidCrystal используйте библиотеку LiquidCrystal_I2C

Или буковки I2C в конце названия ни о чем не говорят?

Этого мало, библиотеку LcdBarGraph.h тоже надо под I2C переписать, это не сложно, но ведь надо )))

как-то так:
 

1Скетч использует 11164 байт (34%) памяти устройства. Всего доступно 32256 байт.
2Глобальные переменные используют 588 байт (28%) динамической памяти, оставляя 1460 байт для локальных переменных. Максимум: 2048 байт.

 

BOOM
BOOM аватар
Offline
Зарегистрирован: 14.11.2018

Мошт #ifndef  твой "наоборот" ? ))

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

BOOM пишет:

Мошт #ifndef  твой "наоборот" ? ))

НЕА, так задумано, если библиотекаф  i2c НЕТУ КОМПИЛИРОВАТЬСЯ ПОД ОБЫЧНЫЕ

01//#define LCDI2C
02 
03#ifndef LCDI2C
04#include <LiquidCrystal.h>
05#include <LcdBarGraph.h>
06LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
07LcdBarGraph lbg(&lcd, 16, 0, 1);        // <a href="https://github.com/prampec/LcdBarGraph" title="https://github.com/prampec/LcdBarGraph" rel="nofollow">https://github.com/prampec/LcdBarGraph</a>
08#else
10#include <LcdBarGraph_I2C.h> 
11LiquidCrystal_I2C lcd(0x27,16,2);
12LcdBarGraph_I2C lbg(&lcd, 16, 0, 1);
13#endif

 

1Скетч использует 10702 байт (33%) памяти устройства. Всего доступно 32256 байт.
2Глобальные переменные используют 526 байт (25%) динамической памяти, оставляя 1522 байт для локальных переменных. Максимум: 2048 байт.

 

ksilius
Offline
Зарегистрирован: 12.04.2022

В холоу ворде работают в этом коде видимо нет.

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

ksilius пишет:

В холоу ворде работают в этом коде видимо нет.

блюда надо уметь готовить )))

BOOM
BOOM аватар
Offline
Зарегистрирован: 14.11.2018

ua6em пишет:

BOOM пишет:

Мошт #ifndef  твой "наоборот" ? ))

НЕА, так задумано, если библиотекаф  i2c НЕТУ КОМПИЛИРОВАТЬСЯ ПОД ОБЫЧНЫЕ

01//#define LCDI2C
02 
03#ifndef LCDI2C
04#include <LiquidCrystal.h>
05#include <LcdBarGraph.h>
06LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
07LcdBarGraph lbg(&lcd, 16, 0, 1);        // <a href="https://github.com/prampec/LcdBarGraph" title="https://github.com/prampec/LcdBarGraph" rel="nofollow">https://github.com/prampec/LcdBarGraph</a>
08#else
10#include <LcdBarGraph_I2C.h> 
11LiquidCrystal_I2C lcd(0x27,16,2);
12LcdBarGraph_I2C lbg(&lcd, 16, 0, 1);
13#endif

 

1Скетч использует 10702 байт (33%) памяти устройства. Всего доступно 32256 байт.
2Глобальные переменные используют 526 байт (25%) динамической памяти, оставляя 1522 байт для локальных переменных. Максимум: 2048 байт.

Не логично. Если ты объявляешь LCDI2C, то и подключай I2C-бибилиотеки. Так же по логике должно быть?...

ksilius
Offline
Зарегистрирован: 12.04.2022

Я правил так но у меня вылетает ошибка при компеляции.

001// Induction balance metal detector
002 
003// We run the CPU at 16MHz and the ADC clock at 1MHz. ADC resolution is reduced to 8 bits at this speed.
004 
005// Timer 1 is used to divide the system clock by about 256 to produce a 62.5kHz square wave.
006// This is used to drive timer 0 and also to trigger ADC conversions.
007// Timer 0 is used to divide the output of timer 1 by 8, giving a 7.8125kHz signal for driving the transmit coil.
008// This gives us 16 ADC clock cycles for each ADC conversion (it actually takes 13.5 cycles), and we take 8 samples per cycle of the coil drive voltage.
009// The ADC implements four phase-sensitive detectors at 45 degree intervals. Using 4 instead of just 2 allows us to cancel the third harmonic of the
010// coil frequency.
011 
012// Timer 2 will be used to generate a tone for the earpiece or headset.
013 
014// Other division ratios for timer 1 are possible, from about 235 upwards.
015 
016// Wiring:
017// Connect digital pin 4 (alias T0) to digital pin 9
018// Connect digital pin 5 through resistor to primary coil and tuning capacitor
019// Connect output from receive amplifier to analog pin 0. Output of receive amplifier should be biased to about half of the analog reference.
020// When using USB power, change analog reference to the 3.3V pin, because there is too much noise on the +5V rail to get good sensitivity.
021//#include <LiquidCrystal.h>
022//#include <LcdBarGraph.h>
023//#define max_ampAverage 200
024//LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
025//LcdBarGraph lbg(&lcd, 16, 0, 1);
026#include <Wire.h>
027#include <LiquidCrystal_I2C.h>
028#include <EEPROM.h>
029LiquidCrystal_I2C lcd(0x27,16,2); //0x20 ; ox27 ; 0x3F
030#define TIMER1_TOP  (259)        // can adjust this to fine-tune the frequency to get the coil tuned (see above)
031 
032#define USE_3V3_AREF  (1)        // set to 1 of running on an Arduino with USB power, 0 for an embedded atmega28p with no 3.3V supply available
033 
034// Digital pin definitions
035// Digital pin 0 not used, however if we are using the serial port for debugging then it's serial input
036const int debugTxPin = 1;        // transmit pin reserved for debugging
037const int encoderButtonPin = 2;  // encoder button, also IN0 for waking up from sleep mode
038const int earpiecePin = 3;       // earpiece, aka OCR2B for tone generation
039const int T0InputPin = 4;
040const int coilDrivePin = 5;
041const int LcdRsPin = 6;
042const int LcdEnPin = 7;
043const int LcdPowerPin = 8;       // LCD power and backlight enable
044const int T0OutputPin = 9;
045const int lcdD4Pin = 10;
046const int lcdD5Pin = 11;         // pins 11-13 also used for ICSP
047const int LcdD6Pin = 12;
048const int LcdD7Pin = 13;
049 
050// Analog pin definitions
051const int receiverInputPin = 0;
052const int encoderAPin = A1;
053const int encoderBpin = A2;
054// Analog pins 3-5 not used
055 
056// Variables used only by the ISR
057int16_t bins[4];                 // bins used to accumulate ADC readings, one for each of the 4 phases
058uint16_t numSamples = 0;
059const uint16_t numSamplesToAverage = 1024;
060 
061// Variables used by the ISR and outside it
062volatile int16_t averages[4];    // when we've accumulated enough readings in the bins, the ISR copies them to here and starts again
063volatile uint32_t ticks = 0;     // system tick counter for timekeeping
064volatile bool sampleReady = false// indicates that the averages array has been updated
065 
066// Variables used only outside the ISR
067int16_t calib[4];                // values (set during calibration) that we subtract from the averages
068 
069volatile uint8_t lastctr;
070volatile uint16_t misses = 0;    // this counts how many times the ISR has been executed too late. Should remain at zero if everything is working properly.
071 
072const double halfRoot2 = sqrt(0.5);
073const double quarterPi = 3.1415927/4.0;
074const double radiansToDegrees = 180.0/3.1415927;
075 
076// The ADC sample and hold occurs 2 ADC clocks (= 32 system clocks) after the timer 1 overflow flag is set.
077// This introduces a slight phase error, which we adjust for in the calculations.
078const float phaseAdjust = (45.0 * 32.0)/(float)(TIMER1_TOP + 1);
079 
080float threshold = 5.0;          // lower = greater sensitivity. 10 is just about usable with a well-balanced coil.
081                                 // The user will be able to adjust this via a pot or rotary encoder.
082 
083void setup()
084{
085  lcd.begin(16, 2);// LCD 16X2
086  pinMode(encoderButtonPin, INPUT_PULLUP); 
087  digitalWrite(T0OutputPin, LOW);
088  pinMode(T0OutputPin, OUTPUT);       // pulse pin from timer 1 used to feed timer 0
089  digitalWrite(coilDrivePin, LOW);
090  pinMode(coilDrivePin, OUTPUT);      // timer 0 output, square wave to drive transmit coil
091   
092  cli();
093  // Stop timer 0 which was set up by the Arduino core
094  TCCR0B = 0;        // stop the timer
095  TIMSK0 = 0;        // disable interrupt
096  TIFR0 = 0x07;      // clear any pending interrupt
097   
098  // Set up ADC to trigger and read channel 0 on timer 1 overflow
099#if USE_3V3_AREF
100  ADMUX = (1 << ADLAR);                   // use AREF pin (connected to 3.3V) as voltage reference, read pin A0, left-adjust result
101#else
102  ADMUX = (1 << REFS0) | (1 << ADLAR);    // use Avcc as voltage reference, read pin A0, left-adjust result
103#endif 
104  ADCSRB = (1 << ADTS2) | (1 << ADTS1);   // auto-trigger ADC on timer/counter 1 overflow
105  ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | (1 << ADPS2);  // enable adc, enable auto-trigger, prescaler = 16 (1MHz ADC clock)
106  DIDR0 = 1;
107 
108  // Set up timer 1.
109  // Prescaler = 1, phase correct PWM mode, TOP = ICR1A
110  TCCR1A = (1 << COM1A1) | (1 << WGM11);
111  TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10);    // CTC mode, prescaler = 1
112  TCCR1C = 0;
113  OCR1AH = (TIMER1_TOP/2 >> 8);
114  OCR1AL = (TIMER1_TOP/2 & 0xFF);
115  ICR1H = (TIMER1_TOP >> 8);
116  ICR1L = (TIMER1_TOP & 0xFF);
117  TCNT1H = 0;
118  TCNT1L = 0;
119  TIFR1 = 0x07;      // clear any pending interrupt
120  TIMSK1 = (1 << TOIE1);
121 
122  // Set up timer 0
123  // Clock source = T0, fast PWM mode, TOP (OCR0A) = 7, PWM output on OC0B
124  TCCR0A = (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
125  TCCR0B = (1 << CS00) | (1 << CS01) | (1 << CS02) | (1 << WGM02);
126  OCR0A = 7;
127  OCR0B = 3;
128  TCNT0 = 0;
129  sei();
130   
131  while (!sampleReady) {}    // discard the first sample
132  misses = 0;
133  sampleReady = false;
134   
135  Serial.begin(19200);
136}
137 
138// Timer 0 overflow interrupt. This serves 2 purposes:
139// 1. It clears the timer 0 overflow flag. If we don't do this, the ADC will not see any more Timer 0 overflows and we will not get any more conversions.
140// 2. It increments the tick counter, allowing is to do timekeeping. We get 62500 ticks/second.
141// We now read the ADC in the timer interrupt routine instead of having a separate comversion complete interrupt.
142ISR(TIMER1_OVF_vect)
143{
144  ++ticks;
145  uint8_t ctr = TCNT0;
146  int16_t val = (int16_t)(uint16_t)ADCH;    // only need to read most significant 8 bits
147  if (ctr != ((lastctr + 1) & 7))
148  {
149    ++misses;
150  }
151  lastctr = ctr;
152  int16_t *p = &bins[ctr & 3];
153  if (ctr < 4)
154  {
155    *p += (val);
156    if (*p > 15000) *p = 15000;
157  }
158  else
159  {
160    *p -= val;
161    if (*p < -15000) *p = -15000;
162  }
163  if (ctr == 7)
164  {
165    ++numSamples;
166    if (numSamples == numSamplesToAverage)
167    {
168      numSamples = 0;
169      if (!sampleReady)      // if previous sample has been consumed
170      {
171        memcpy((void*)averages, bins, sizeof(averages));
172        sampleReady = true;
173      }
174      memset(bins, 0, sizeof(bins));
175    }
176  }
177}
178 
179void loop()
180{
181  while (!sampleReady) {}
182  uint32_t oldTicks = ticks;
183   
184  if (digitalRead(encoderButtonPin) == LOW)
185  {
186    // Calibrate button pressed. We save the current phase detector outputs and subtract them from future results.
187    // This lets us use the detector if the coil is slightly off-balance.
188    // It would be better to everage several samples instead of taking just one.
189    for (int i = 0; i < 4; ++i)
190    {
191      calib[i] = averages[i];
192    }
193    sampleReady = false;
194    Serial.print("Calibrated: ");
195     
196    lcd.setCursor(0,0);
197    lcd.print("Calibrating...  ");   
198    for (int i = 0; i < 4; ++i)
199    {
200      Serial.write(' ');
201       
202      Serial.print(calib[i]);
203     
204    lcd.setCursor(0,1);   
205    lcd.print(' ');   
206    lcd.print(calib[4]);
207    lcd.print("        ");    
208    }
209    Serial.println();
210  }
211  else
212  
213    for (int i = 0; i < 4; ++i)
214    {
215      averages[i] -= calib[i];
216    }
217    const double f = 200.0;
218     
219    // Massage the results to eliminate sensitivity to the 3rd harmonic, and divide by 200
220    double bin0 = (averages[0] + halfRoot2 * (averages[1] - averages[3]))/f;
221    double bin1 = (averages[1] + halfRoot2 * (averages[0] + averages[2]))/f;
222    double bin2 = (averages[2] + halfRoot2 * (averages[1] + averages[3]))/f;
223    double bin3 = (averages[3] + halfRoot2 * (averages[2] - averages[0]))/f;
224    sampleReady = false;          // we've finished reading the averages, so the ISR is free to overwrite them again
225 
226    double amp1 = sqrt((bin0 * bin0) + (bin2 * bin2));
227    double amp2 = sqrt((bin1 * bin1) + (bin3 * bin3));
228    double ampAverage = (amp1 + amp2)/2.0;
229     
230    // The ADC sample/hold takes place 2 clocks after the timer overflow
231    double phase1 = atan2(bin0, bin2) * radiansToDegrees + 45.0;
232    double phase2 = atan2(bin1, bin3) * radiansToDegrees;
233   
234    if (phase1 > phase2)
235    {
236      double temp = phase1;
237      phase1 = phase2;
238      phase2 = temp;
239    }
240     
241    double phaseAverage = ((phase1 + phase2)/2.0) - phaseAdjust;
242    if (phase2 - phase1 > 180.0)
243    {
244      if (phaseAverage < 0.0)
245      {
246        phaseAverage += 180.0;
247      }
248      else
249      {
250        phaseAverage -= 180.0;
251      }
252    }
253         
254    // For diagnostic purposes, print the individual bin counts and the 2 indepedently-calculated gains and phases                                                       
255    Serial.print(misses);
256    Serial.write(' ');
257     
258    if (bin0 >= 0.0) Serial.write(' ');
259    Serial.print(bin0, 2);
260    Serial.write(' ');
261    if (bin1 >= 0.0) Serial.write(' ');
262    Serial.print(bin1, 2);
263    Serial.write(' ');
264    if (bin2 >= 0.0) Serial.write(' ');
265    Serial.print(bin2, 2);
266    Serial.write(' ');
267    if (bin3 >= 0.0) Serial.write(' ');
268    Serial.print(bin3, 2);
269    Serial.print("    ");
270    Serial.print(amp1, 2);
271    Serial.write(' ');
272    Serial.print(amp2, 2);
273    Serial.write(' ');
274    if (phase1 >= 0.0) Serial.write(' ');
275    Serial.print(phase1, 2);
276    Serial.write(' ');
277    if (phase2 >= 0.0) Serial.write(' ');
278    Serial.print(phase2, 2);
279    Serial.print("    ");
280     
281    // Print the final amplitude and phase, which we use to decide what (if anything) we have found)
282    if (ampAverage >= 0.0) Serial.write(' ');
283    Serial.print(ampAverage, 1);
284    Serial.write(' ');
285         
286        lcd.setCursor(0,0);
287        lcd.print("          ");
288        lcd.print(ampAverage);       
289        lcd.setCursor(0,1);
290        lbg.drawValue(ampAverage, max_ampAverage);
291 
292    if (phaseAverage >= 0.0) Serial.write(' ');
293    Serial.print((int)phaseAverage);
294     
295    // Decide what we have found and tell the user
296    if (ampAverage >= threshold)
297    {
298      // When held in line with the centre of the coil:
299      // - non-ferrous metals give a negative phase shift, e.g. -90deg for thick copper or aluminium, a copper olive, -30deg for thin alumimium.
300      // Ferrous metals give zero phase shift or a small positive phase shift.
301      // So we'll say that anything with a phase shift below -20deg is non-ferrous.
302      if (phaseAverage < -20.0)
303      {
304        Serial.print(" Non-ferrous");
305        lcd.setCursor(0,0);       
306        lcd.print("NonFerous ");     
307      
308      }
309      else
310      {
311        Serial.print(" Ferrous");       
312        lcd.setCursor(0,0);      
313        lcd.print("Ferrous    ");                
314      }
315      float temp = ampAverage;
316               
317       int thisPitch = map (temp, 10, 200, 100, 1500);
318       tone(3, thisPitch,120);
319        
320      while (temp > threshold)
321      {
322        Serial.write('!');     
323        temp -= (threshold/2);
324      }
325    }  
326    Serial.println();
327    
328   }
329  while (ticks - oldTicks < 8000)
330  {
331  }     
332}

 

BOOM
BOOM аватар
Offline
Зарегистрирован: 14.11.2018

ksilius пишет:

Я правил так но у меня вылетает ошибка при компеляции.

Знаешь сколько ошибок компиляции бывает? Нет? Так выкладывай текстом - что за ошибка!

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

BOOM пишет:

ua6em пишет:

BOOM пишет:

Мошт #ifndef  твой "наоборот" ? ))

НЕА, так задумано, если библиотекаф  i2c НЕТУ КОМПИЛИРОВАТЬСЯ ПОД ОБЫЧНЫЕ

01//#define LCDI2C
02 
03#ifndef LCDI2C
04#include <LiquidCrystal.h>
05#include <LcdBarGraph.h>
06LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
07LcdBarGraph lbg(&lcd, 16, 0, 1);        // <a href="https://github.com/prampec/LcdBarGraph" title="https://github.com/prampec/LcdBarGraph" rel="nofollow">https://github.com/prampec/LcdBarGraph</a>
08#else
10#include <LcdBarGraph_I2C.h> 
11LiquidCrystal_I2C lcd(0x27,16,2);
12LcdBarGraph_I2C lbg(&lcd, 16, 0, 1);
13#endif

 

1Скетч использует 10702 байт (33%) памяти устройства. Всего доступно 32256 байт.
2Глобальные переменные используют 526 байт (25%) динамической памяти, оставляя 1522 байт для локальных переменных. Максимум: 2048 байт.

Не логично. Если ты объявляешь LCDI2C, то и подключай I2C-бибилиотеки. Так же по логике должно быть?...

а если не объявляешь )))
(ifndef)

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

BOOM пишет:

ksilius пишет:

Я правил так но у меня вылетает ошибка при компеляции.

Знаешь сколько ошибок компиляции бывает? Нет? Так выкладывай текстом - что за ошибка!

на правильных библиотеках нет там никаких ошибок

 

ksilius
Offline
Зарегистрирован: 12.04.2022

Согласен, я готовлю:) но не в ардуино, яж говорю только верхушек нахватался.

 

ksilius
Offline
Зарегистрирован: 12.04.2022
Arduino: 1.8.19 (Windows 10), Плата:"Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
D:\arduino_code\arduino_code.ino: In function 'void setup()':
 
arduino_code:85:18: error: no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'
 
   lcd.begin(16, 2);// LCD 16X2
 
                  ^
 
In file included from D:\arduino_code\arduino_code.ino:27:0:
 
D:\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: candidate: void LiquidCrystal_I2C::begin()
 
  void begin();
 
       ^~~~~
 
D:\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note:   candidate expects 0 arguments, 2 provided
 
D:\arduino_code\arduino_code.ino: In function 'void loop()':
 
arduino_code:290:9: error: 'lbg' was not declared in this scope
 
         lbg.drawValue(ampAverage, max_ampAverage);
 
         ^~~
 
D:\arduino_code\arduino_code.ino:290:9: note: suggested alternative: 'log'
 
         lbg.drawValue(ampAverage, max_ampAverage);
 
         ^~~
 
         log
 
arduino_code:290:35: error: 'max_ampAverage' was not declared in this scope
 
         lbg.drawValue(ampAverage, max_ampAverage);
 
                                   ^~~~~~~~~~~~~~
 
D:\arduino_code\arduino_code.ino:290:35: note: suggested alternative: 'ampAverage'
 
         lbg.drawValue(ampAverage, max_ampAverage);
 
                                   ^~~~~~~~~~~~~~
 
                                   ampAverage
 
exit status 1
 
no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'
 
 
 
Этот отчёт будет иметь больше информации с
включенной опцией Файл -> Настройки ->
"Показать подробный вывод во время компиляции"
 
ksilius
Offline
Зарегистрирован: 12.04.2022

Согласен долго я искал библиотеку что бы хоть холо ворл заработал.

ksilius
Offline
Зарегистрирован: 12.04.2022

Вод подробная ошибка.

001Arduino: 1.8.19 (Windows 10), Плата:"Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"
002 
003 
004 
005 
006 
007 
008 
009 
010 
011 
012 
013 
014 
015 
016 
017 
018 
019 
020 
021 
022 
023D:\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Arduino\hardware -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -built-in-libraries D:\Arduino\libraries -libraries C:\Users\Алексей\Documents\Arduino\libraries -fqbn=arduino:avr:pro:cpu=16MHzatmega328 -ide-version=10819 -build-path C:\Temp\arduino_build_851454 -warnings=none -build-cache C:\Temp\arduino_cache_715681 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -verbose D:\arduino_code\arduino_code.ino
024 
025D:\Arduino\arduino-builder -compile -logger=machine -hardware D:\Arduino\hardware -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -built-in-libraries D:\Arduino\libraries -libraries C:\Users\Алексей\Documents\Arduino\libraries -fqbn=arduino:avr:pro:cpu=16MHzatmega328 -ide-version=10819 -build-path C:\Temp\arduino_build_851454 -warnings=none -build-cache C:\Temp\arduino_cache_715681 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -verbose D:\arduino_code\arduino_code.ino
026 
027Using board 'pro' from platform in folder: D:\Arduino\hardware\arduino\avr
028 
029Using core 'arduino' from platform in folder: D:\Arduino\hardware\arduino\avr
030 
031Detecting libraries used...
032 
033"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o nul
034 
035Alternatives for Wire.h: [Wire@1.0]
036 
037ResolveLibrary(Wire.h)
038 
039  -> candidates: [Wire@1.0]
040 
041"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o nul
042 
043Alternatives for LiquidCrystal_I2C.h: [Arduino-LiquidCrystal-I2C-library-master]
044 
045ResolveLibrary(LiquidCrystal_I2C.h)
046 
047  -> candidates: [Arduino-LiquidCrystal-I2C-library-master]
048 
049"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o nul
050 
051Alternatives for EEPROM.h: [EEPROM@2.0]
052 
053ResolveLibrary(EEPROM.h)
054 
055  -> candidates: [EEPROM@2.0]
056 
057"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o nul
058 
059"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "D:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src\\Wire.cpp" -o nul
060 
061"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "D:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src\\utility\\twi.c" -o nul
062 
063"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "D:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master\\LiquidCrystal_I2C.cpp" -o nul
064 
065Generating function prototypes...
066 
067"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o "C:\\Temp\\arduino_build_851454\\preproc\\ctags_target_for_gcc_minus_e.cpp"
068 
069"D:\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Temp\\arduino_build_851454\\preproc\\ctags_target_for_gcc_minus_e.cpp"
070 
071Компиляция скетча...
072 
073"D:\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-ID:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\Wire\\src" "-ID:\\Arduino\\libraries\\Arduino-LiquidCrystal-I2C-library-master" "-ID:\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp" -o "C:\\Temp\\arduino_build_851454\\sketch\\arduino_code.ino.cpp.o"
074 
075D:\arduino_code\arduino_code.ino: In function 'void setup()':
076 
077arduino_code:85:18: error: no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'
078 
079   lcd.begin(16, 2);// LCD 16X2
080 
081                  ^
082 
083In file included from D:\arduino_code\arduino_code.ino:27:0:
084 
085D:\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: candidate: void LiquidCrystal_I2C::begin()
086 
087  void begin();
088 
089       ^~~~~
090 
091D:\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note:   candidate expects 0 arguments, 2 provided
092 
093D:\arduino_code\arduino_code.ino: In function 'void loop()':
094 
095arduino_code:290:9: error: 'lbg' was not declared in this scope
096 
097         lbg.drawValue(ampAverage, max_ampAverage);
098 
099         ^~~
100 
101D:\arduino_code\arduino_code.ino:290:9: note: suggested alternative: 'log'
102 
103         lbg.drawValue(ampAverage, max_ampAverage);
104 
105         ^~~
106 
107         log
108 
109arduino_code:290:35: error: 'max_ampAverage' was not declared in this scope
110 
111         lbg.drawValue(ampAverage, max_ampAverage);
112 
113                                   ^~~~~~~~~~~~~~
114 
115D:\arduino_code\arduino_code.ino:290:35: note: suggested alternative: 'ampAverage'
116 
117         lbg.drawValue(ampAverage, max_ampAverage);
118 
119                                   ^~~~~~~~~~~~~~
120 
121                                   ampAverage
122 
123Используем библиотеку Wire версии 1.0 из папки: D:\Arduino\hardware\arduino\avr\libraries\Wire
124 
125Используем библиотеку Arduino-LiquidCrystal-I2C-library-master в папке: D:\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master (legacy)
126 
127Используем библиотеку EEPROM версии 2.0 из папки: D:\Arduino\hardware\arduino\avr\libraries\EEPROM
128 
129exit status 1
130 
131no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'

 

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

библиотеку LcdBarGraph.h тоже надо под I2C переписать

ksilius
Offline
Зарегистрирован: 12.04.2022

Как? наверное потому я и здесь со своей просьбой.

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

ksilius пишет:

Как? наверное потому я и здесь со своей просьбой.

обычно если сам не можешь заказываешь компетентный сервис )))

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

ksilius пишет:

Так научите это ... как сложно. Да и зачем нужна lcdbargraph.h если я собираюсь под i2c переписать код. С меня в контакте ардуинщик-бизнесмен запросил 1000 рублей это не вы случайно?

это не я и, ...так как ты просишь чтобы один неуч  учил второго неуча в этом случае ставка будет сильно выше, 4 часа 7 тыр )))
PS это не договор оферты...размышления вслух...

ksilius
Offline
Зарегистрирован: 12.04.2022

Ясно зря зашёл, ну всё равно спасибо, здоровья вам и удачи.

ksilius
Offline
Зарегистрирован: 12.04.2022

Ты богатый и очереди у тебя? Удачи в бизнесе.

Kakmyc
Offline
Зарегистрирован: 15.01.2018

ksilius пишет:

Ты богатый и очереди у тебя? Удачи в бизнесе.


А ты бедный и безмозглый.
Готовое купи, это дешевле.

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

ksilius пишет:

Ясно зря зашёл, ну всё равно спасибо, здоровья вам и удачи.

почему же зря, скетч тебе дали поправленный (заметь - безвозмездно), осталось решить или новый дисплей купить, или у этого выпаять контроллер или штуку заплатить тому, кто тебе предлагал ...это если по быстрому...
PS обычно хорошим тоном считается приводить ссылку на автора проекта

Не забываем, что не все библиотеки LCD_I2C  поддерживают необходимые нам функции, официальная - нет.
 

01// unsupported API functions
02void LiquidCrystal_I2C::off(){}
03void LiquidCrystal_I2C::on(){}
04void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
05uint8_t LiquidCrystal_I2C::status(){return 0;}
06uint8_t LiquidCrystal_I2C::keypad (){return 0;}
07uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
08void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end){}
09void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_row_end){}
10void LiquidCrystal_I2C::setContrast(uint8_t new_val){}

 

BOOM
BOOM аватар
Offline
Зарегистрирован: 14.11.2018

Проще гребенку снять ))))

ua6em
ua6em аватар
Offline
Зарегистрирован: 17.08.2016

BOOM пишет:

Проще гребенку снять ))))

проще новый дисплей купить )))