Help. Simple. AC Frequency measure

My apologies, I am a new member and thus are unable to upload the code in question.
I cannot for the life of me understand how I am getting (exit status 1
expected unqualified-id before ‘.’ token)
I have looked for the missing ; but no luck.
Surley there is a wizard who can resolve this?

#include <LiquidCrystal.h>

// AC Frequency with LCD By Solarduino

// 0- General

int decimalPrecision = 2;

// 1- frequency measurement

unsigned long startMicros;
unsigned long currentMicros;
int expectedFrequency = 50;
int frequencyAnalogPin = A2;
float frequencySampleCount = 0;
float frequency =0 ;
float a;
float switch01 = 0;
float vAnalogRead = 0;

// 2 - LCD Display

// Include Wire Library for I2C
#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>

// Define LCD pinout
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x27;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

void setup()
{

// 0- General

Serial.begin(9600);

// 1- frequency measurement

startMicros = micros();

// 2 - LCD Display

LCD.begin(16,2);
LCD.setCursor(0,0);
startMicrosLCD = micros();
}

void loop()
{

// 1- frequency measurement

currentMicros = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;

if(vAnalogRead >=0 && switch01 == 0)
{
frequencySampleCount = frequencySampleCount +1 ;
switch01 = 1;
}

if(vAnalogRead < 0 && switch01 == 1) { switch01 = 0; } if(frequencySampleCount == expectedFrequency) { a = currentMicros-startMicros ; frequency = 1/((a/1000000)/frequencySampleCount); Serial.print(frequency,decimalPrecision); Serial.println(" Hz"); startMicros = currentMicros; frequencySampleCount = 0; // 2 - LCD Display currentMicrosLCD = micros(); if(currentMicrosLCD - startMicrosLCD >=1000000)
{
LCD.setCursor(0,0);
LCD.print(“f=”);
LCD.print(frequency,decimalPrecision);
LCD.print("Hz “);
LCD.setCursor(0,1);
LCD.print(” ");

There are lots of closing braces missing. Go back to where you found the code and make sure you have copied and pasted it properly. It’s like you’ve missed off the last few lines.

1 Like

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose “copy for forum”
  3. paste clipboard into write-window of a posting

best regards Stefan

1 Like

A similar sketch is here (almost at the bottom): https://solarduino.com/how-to-measure-ac-frequency-with-arduino/.

With this line:

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

A object “lcd” is created from the class “LiquidCrystal_I2C”. In the sketch you should use the object “lcd”.
However, in the sketch you use the object “LCD”, which does not exist:

LCD.begin(16,2);
1 Like

Great tip! problem solved. Thanks a lot.