PowerNodeNG

Uit MakerSpace Leiden
Versie door DirkWillem (overleg | bijdragen) op 11 dec 2023 om 17:50 (i2c scanning)
Ga naar: navigatie, zoeken


Nieuwe generieke power nodes; gemaakt door HansB.

Not yet fully documented, https://github.com/Hans-Beerman/NodeStandard.

In use at the NodeVoordeur, NodeMetal and NodeBandsaw.

Bring up

Scripts to help debugging/testing a new board being build

i2c scanning

An I2C scan should, at least, find the RFID unit (PN532=0x24) and the i2c expander (MCP=0x20). It may find the screen (typically 0x58 or 0x60) if wired in.

````

  1. include <Wire.h>

// Correct values for https://github.com/Hans-Beerman/NodeStandard/blob/master/KiCad_Files/NodeStandard/NodeStandard.pdf // const int I2C_SDA = 13; const int I2C_SCL = 16;

// the setup function runs once when you press reset or power the board void setup() {

 Serial.begin(115200);
 // Required to flush/empty any cruft/different baud-rate during programming.
 //
 while (!Serial) {
   Serial.println();
   delay(10);
 };
 Serial.println("\n\n" __FILE__ "\n" __DATE__ " " __TIME__);
  1. define GPIOPORT_I2C_RECOVER_SWITCH (15)
 pinMode(GPIOPORT_I2C_RECOVER_SWITCH, OUTPUT);
 digitalWrite(GPIOPORT_I2C_RECOVER_SWITCH, 0);
 Wire.begin(I2C_SDA, I2C_SCL /*, clock frequency */);

};

void scan_i2c() {

 Serial.println ();
 Serial.println ("I2C scanning (PN532=0x24, MCP=0x20)");
 byte count = 0;
 for (byte i = 8; i < 128; i++)
 {
   Wire.beginTransmission (i);          // Begin I2C transmission Address (i)
   if (Wire.endTransmission () == 0)  // Receive 0 = success (ACK response)
   {
     Serial.print (" - Device at address: ");
     Serial.print (i, DEC);
     Serial.print (" (0x");
     Serial.print (i, HEX);
     Serial.println (")");
     count++;
   }
 }
 Serial.print ("Found ");
 Serial.print (count, DEC);
 Serial.println (" device(s).");

}

// the loop function runs over and over again forever void loop() { {

 static unsigned long lst = 0;
 if (millis() - lst > 10*1000) {
   lst = millis();
   scan_i2c();
 };

}; {

 static unsigned long lst = 0;
 if (millis() - lst > 1000) {
   lst = millis();
   Serial.println("tok");
 };

}; } '