Closed wmarkow closed 6 years ago
It may be related to the fact that I'm powering PT2314 with 5V only (not 6V as suggested by the docs, see issue #2). But on one of my laptop it works nice.
I did a small change in the setup() method: I'm trying to call PT2314::init() a few times and put a delay between the calls, like:
uint8_t q = 0;
int res = 0;
for(q = 0 ; q < 10 ; q ++){
res = pt2314.init();
if(res == 0){
break;
}
delay(100);
}
I have noticed that PT2314 is initiated correct mostly at the 7th try. With this solution my board works every time with a wall charger.
I did some further tests. I have modified my setup() method so it looks like below:
void setup()
{
Serial.begin(57600);
Wire.begin();
uint8_t q = 0;
int res = 0;
for(q = 0 ; q < 100 ; q ++)
{
res = pt2314.init();
if(res == 0)
{
break;
}
delay(100);
}
// here I display the **res** and **q** variables on 4x20 alphanumeric LCD.
}
The result is that with the wall charger it takes between 1 and 2 seconds (the for loop breaks where the q variable is between 10...20).
I think this issue is not not a side effect of some bug in this PT2314 library. It may be more or less related to the power supply itself and of course it can be that the PT2314 needs some more time to operate vie I2C correctly.
I see that @ttuksa has put in his example (in a setup() method) a two delays that will wait 2 seconds in total before the PT2314:init() is called.
void setup() {
...
delay(1000);
Wire.begin();
delay(1000);
ledOn();
audioswitch.init();
...
}
Maybe he had some similar issue to me?
I have created a pull request (#5 ) This solution below (a loop) fixed my problem:
void setup()
{
...
uint8_t q = 0;
bool res = false;
for (q = 0 ; q < 20 ; q ++)
{
res = pt2314.init();
if(res == true)
{
break;
}
delay(100);
...
}
Interesting, never catched this issue with init failures... That's strange, but loop with delays seems a nice workaround! Thanks!
I'm calling the PT2314::init() method from Arduino's setup(). It works fine when I power up my Arduino directly from one of my laptop. When I power up Arduino from a wall charger the PT2314 seems to not react to this PT2314::init(). Here is what I have:
PT2314 is initiated correctly with a wall charger but I need to make a "trick":
I have reworked the PT2314::init() method so it will return the I2C error code (returned by Wire.endTransmission()). I learned that PT2314 is not initialized because the I2C peripheral return error 2 which means no ACK received by master after sending address to slave. I feel that PT2314 needs a little more time to operate correctly after powering up the device. It may be related to the power supply itself. When the voltage rises Arduino Uno starts to work but the voltage is not high enough to power up PT2314 correctly.