ATtiny85

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ATtiny85

192 Views
Robert11
Contributor II
hi , I have writing code on arduino ide platform for a scenario.
scenario: attiny85 should measure the frequency from the astable multivibrator circuit using 555 timer where the one of resistance is replaced by the force sensing resistor (Force-sensing resistors (FSR) are devices whose resistance changes when a force is applied to them) , astable multivibrator circuit using 555 timer output is given to the pb4 of attiny85 and then attiny85(master) should send the measured frequency value to arduino uno(slave) using i2c communication and arduino uno should receive the frequency value and print in the serial monitor. i have pasted the below attiny85 master code and arduino uno slave code.
 
master code ( ATtiny85)
 

const int inputPin = 4; // Input pin PB4
unsigned long pulseStartTime = 0;
unsigned long pulseEndTime = 0;
#define I2C_SLAVE_ADDRESS 0x48 // Address of the slave

#include <TinyWireM.h>

void setup() {
pinMode(inputPin, INPUT);
TinyWireM.begin();
TinyWireM.beginTransmission(I2C_SLAVE_ADDRESS); // Initialize I2C communication
}

void loop() {
// Wait for the rising edge
while (digitalRead(inputPin) == LOW) {
// Do nothing
}

// Record the start time of the pulse
pulseStartTime = micros();

// Wait for the falling edge
while (digitalRead(inputPin) == HIGH) {
// Do nothing
}

// Record the end time of the pulse
pulseEndTime = micros();

// Calculate pulse width
unsigned long pulseWidth = pulseEndTime - pulseStartTime;
float frequency = 1000000.0 / pulseWidth; // Calculate frequency in Hz

// Convert frequency to bytes for I2C transmission
uint8_t frequencyBytes[4]; // Assuming frequency will fit within 4 bytes
memcpy(frequencyBytes, &frequency, sizeof(frequency));

// Send frequency bytes over I2C
TinyWireM.write(frequencyBytes, sizeof(frequencyBytes));

// End transmission
TinyWireM.endTransmission();

// Delay before next measurement
delay(100);
}

 

slave code ( arduino uno )

 

#include <Wire.h>

const int slaveAddress = 0x48;

void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps.
Wire.begin(slaveAddress); // Join i2c bus with the address specified as slaveAddress
Wire.onReceive(receiveEvent); // Register the receive event function
Serial.println("Ready to receive frequency data...");
}

void loop() {
// Nothing to do here, all processing occurs in the receiveEvent function.
delay(100); // Optional: slight delay to ease the CPU workload if needed.
}

// Function called by the Wire library when data is received.
void receiveEvent(int howMany) {
if (howMany >= 4) { // Ensure we have at least 4 bytes for a float value
byte frequencyBytes[4];
for (int i = 0; i < 4; ++i) {
if (Wire.available()) {
frequencyBytes[i] = Wire.read(); // Read a byte from the I2C buffer
}
}
float frequency;
memcpy(&frequency, frequencyBytes, sizeof(frequency)); // Recompile the bytes back into the single float

// Print the frequency to Serial Monitor
Serial.print("Received Frequency: ");
Serial.print(frequency);
Serial.println(" Hz");
}
else {
Serial.println("Error: Not enough bytes received");
}
}

 
when i implement this code in hardware  , the code is working but its output value printing in arduino ide is  largely fluctuating and showing wrong values. I dont know how to rectify it.
 
 
0 Kudos
4 Replies

132 Views
Robert11
Contributor II

First of all thanks for the response from your side.

Yes, I am using NTAG I2C PLUS (NT3H2111)

At present ,I have problem in capturing and measuring he frequency from the 555 timer using AVR 8 bit microcontroller ATtiny85.

At the moment , the main query is "I want do ndef format the measured frequency data and store it in the EEPROM of NT3H2111 where the data should be available for NFC communication. NT3H2111 is powered by external power supply not by energy harvesting and fd pin kept open. Is there any library or resource that helpfull in doing the above specified work"

0 Kudos

150 Views
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello,

 

Hope you are doing well.

 

You are using NTAG I2C Plus, right?

 

If my understanding is correct, the current issue you are having is related to getting the frequency from your sensor, right?

 

Or are you presenting an issue with NTAG I2C Plus?

 

Regards,

Ricardo

0 Kudos

132 Views
Robert11
Contributor II
First of all thanks for the response from your side.

Yes, I am using NTAG I2C PLUS (NT3H2111)

At present ,I have problem in capturing and measuring he frequency from the 555 timer using AVR 8 bit microcontroller ATtiny85.

At the moment , the main query is "I want do ndef format the measured frequency data and store it in the EEPROM of NT3H2111 where the data should be available for NFC communication. NT3H2111 is powered by external power supply not by energy harvesting and fd pin kept open. Is there any library or resource that helpfull in doing the above specified work"
0 Kudos

76 Views
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello,

 

Some of our MCU's have support for NTAG I2C Plus. You can check the Select Middleware | MCUXpresso SDK Builder.

 

And also, you could check this UM10950.

 

Regards,

Ricardo

0 Kudos