Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Arduino SAMD21 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jwgmeligmeyling
Copy link

Made some changes to allow the code to compile under Arduino MKR WAN 1300 and Arduino MKR Zero.

@@ -655,12 +663,15 @@ bool SPS30::setSerialSpeed()
if (_SPS30_Debug) printf("TX/RX line not defined\n");
return false;
}

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(_SAMD21_)
Copy link
Author

@jwgmeligmeyling jwgmeligmeyling May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is technically unrelated, but causes the code to not compile for some bords that do not have Serial1.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see SAMD21 is added to the define. I don't have a SAMD21 and thus have not tested. I was looking at https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/muxing-it-up. It looks that the SAM21D has 6 serial communication options, of which 3 or 4 are already used (depending on the board) : SPI, I2C, Serial and (maybe) debug serial. In the same tutorial (https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-serial) it describes what needs to happen to add a serial port. Have you tried that and does that work ?

regards
Paul

Copy link
Author

@jwgmeligmeyling jwgmeligmeyling May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reassign the SERCOMs and create other serial interfaces too, but you have to declare them yourself (including the IRQ). By default only Serial and Serial1 are declared (and Serial2 for the LoRaWAN enabled device). The standard serials are defined in for example: https://github.com/arduino/ArduinoCore-samd/blob/master/variants/mkr1000/variant.cpp#L173-L180 ). That means that, even though users are technically allowed to create more Serial interfaces, we don't know about the existence of these serials at compile time. The only way to support these other serial ports too would probably be through the means of introducing a mechanism of providing a custom Serial/Stream object to the SPS30 object.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I had a closer look and I think you can use serial1 without any library change. There is already a special workaround for boards that have serial1 and we can force to use that:

set for Serialport usage:
#define SP30_COMMS SERIALPORT1

Set both RX and TX to 8 : (will force Serail1 port with default pins)
#define TX_PIN 8
#define RX_PIN 8

On a SAM21D it will use pin 0 (RX) and 1 (TX).
On an Arduino these pins are used for USB as well, but not on the SAM21D (serialUSB)

can you try that and let me know that works?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to support these other serial ports too would probably be through the means of introducing a mechanism of providing a custom Serial/Stream object to the SPS30 object.

That's exactly why I created this port to enable an easier assignment of interfaces. https://github.com/AdvancedClimateSystems/sps30/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
There are indeed different ways to handle the connection. I had chosen to embed it in this library, in other libraries I have taken a different approach. I have tested this library and many different boards, including SAMx1D boards, and have had no problems in getting connected.
Given there are many copies in use around the world, I want to retain the backward compatibility so people do not have to update their sketches when updating the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants