mrrwa / NmraDcc

NMRA Digital Command Control (DCC) Library
GNU Lesser General Public License v2.1
135 stars 53 forks source link

Cant get runing on RP2040 (Pi Pico) #68

Closed Ecksteher closed 1 year ago

Ecksteher commented 1 year ago

Hello i trying to get it runing on My Pi Pico. i head read a fiew times "ARDUINO_ARCH_RP2040" so i thinked it wud work. but as i uploaded my simple sniffer sketch it just output "Sniffer Start". and dhat's it. I tried also on an Arduino Nano and it worked.

#include <NmraDcc.h>
#define DCC_PIN   2
#define DCC_DECODER_VERSION_NUM 11  // Set the Decoder Version - Used by JMRI to Identify the decoder
NmraDcc  Dcc ;
DCC_MSG  Packet ;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Dcc.pin(0, DCC_PIN, 1);
  Dcc.init( MAN_ID_DIY, DCC_DECODER_VERSION_NUM,  FLAGS_DCC_ACCESSORY_DECODER , 0 );
  while (!Serial) {

  }
  Serial.println("Sniffer Start");

}

void loop() {
  // put your main code here, to run repeatedly:
  Dcc.process();
}
void notifyDccMsg( DCC_MSG * Msg)
{
  Serial.print("notifyDccMsg: ") ;
  for (uint8_t i = 0; i < Msg->Size; i++)
  {
    Serial.print(Msg->Data[i], HEX);
    Serial.write(' ');
  }
  Serial.println();
}

On the Hardware side i used bridge rectifier for Ground and a voltage devider that converts the rail voltage to 3.3V clamped with a zener diode and feed it through an schmittrigger. than into my Controller.

Can somone help me pleas?

kiwi64ajs commented 1 year ago

Hi @Ecksteher I think the problem is the definition of the DCC Input Pin. Try changing:

Dcc.pin(0, DCC_PIN, 1);

to:

Dcc.pin(DCC_PIN, 1);

Doing the above code change makes your code work for me on a RPI-Pico

Ecksteher commented 1 year ago

Yes this solved my problem. but i tried bevore and it din't run before, probably I changed somting else to. Thank you verry much.