In this post we are going, just for once, to focus mainly on theoretical concepts, to explain the microcontroller performance when using direct and reciprocal frequency measurement. Direct frequency...
How to use I2C to feed frequency measurements from the Arduino compatible precision frequency counter to another device?
The Arduino compatible precision frequency counter Freq_LF_HF can communicate over an I2C serial network. In the example presented below we will be using Feq_LF_HF board in master mode to send frequency values to an Arduino Nano board in slave mode. It only takes a few lines of Arduino code on each device and relies on the standard library WIRE.
The name I2C refers to the fact that it is a serial 2 wire (synchronous, half duplex) communication protocol. Hence we have to establish the SCL (clock) line and SDA (data) lines between the respective pins of the 2 boards. We should also link the ground pins.
Using this protocol we could add many peripherals to a network, all connected to common SCL and SDA wires, but only one peripheral will be configured as master. All others will respond to the master in slave configuration. These 2 lines must be pulled-up to the power voltage (5 volts).
Freq_LF_HF SCL and SDA lines have 510 Ohm series resistors for protection. A good value for pull-up resistors would be between 4.7 KOhm and 20 KOhm. It depends on the total capacitance of the lines, and sot it depends on the number of devices on the I2C bus. For more information you can read Using the I2C Bus.
To assemble this frequency measurement toolchain we need to connect the pins like this:
- LCD Vss: Gnd
- LCD Vdd: 5 volts rail of the breadboard.
- LCD VO: for this particular LCD I used 3.3KOhm to ground
- LCD RS: to Nano D2 pin
- LCD RW: Gnd
- LCD E: to Nano D3 pin
- LCD D4: to Nano D4 pin
- LCD D5: to Nano D5 pin
- LCD D6: to Nano D6 pin
- LCD D7: to Nano D7 pin
- Freq_LF_HF Gnd pin: to the Gnd rail of the breadboard
- Freq_LF_HF SCL pin to a 10 KOhm pull-up resistor. This resistor is connected to the 5 volts rail of the breadboard
- Freq_LF_HF SDA pin to a 10 KOhm pull-up resistor. This resistor is connected to the 5 volts rail of the breadboard
- Nano A4 pin: to the SDA pull-up resistor (same side of the pull-up as Freq_LF_HF SDA)
- Nano A5 pin: to the SCL pull-up resistor (same side of the pull-up as Freq_LF_HF SCL)
- SCL 10 KOhm pull-up resistor is other side to the 5V rail
- SDA 10 KOhm pull-up resistor is other side to the 5V rail
- Nano Gnd pin: to the Gnd rail of the breadboard
- Nano 5 volts pin: to the 5 volts rail of the breadboard
Programming Freq_LF_HF as master
Programming an Arduino Uno/Nano board as slave
Instead of using I2C to feed frequency measurements we could also use the other buses available on Freq_LF_HF: Serial (for longer distances) and SPI (for faster communication) to achieve the same goal.