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

Raspberry Pi Pico as a potential target #1415

Open
marinasundstrom opened this issue Jan 21, 2021 · 20 comments
Open

Raspberry Pi Pico as a potential target #1415

marinasundstrom opened this issue Jan 21, 2021 · 20 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation blocked Issue/PR is blocked on something - see comments

Comments

@marinasundstrom
Copy link

Would it be possible to target Raspberry Pi Pico?

See my discussion: dotnet/runtime#47270

@marinasundstrom marinasundstrom added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 21, 2021
@krwq
Copy link
Member

krwq commented Jan 21, 2021

Hey @RobertSundstrom, did you check if you can get it to work with Mono or nano-framework? If any of those two work we will likely be able to give you some pointers

@pgrawehr
Copy link
Contributor

What likely will work is put a Firmata Firmware on it and access it using the Arduino binding. But of course that's not quite the same as running .NET code on the MCU itself.

@krwq
Copy link
Member

krwq commented Jan 21, 2021

nano-framework should work too I think but it's not straightforward yet how to get .NET IoT run on it

@Ellerbach
Copy link
Member

+1 for .NET nanoFramework which is a more reasonable target for such a processor. Check it out https://github.com/nanoframework/Home. There are already some contacts to see how to make that happening!

@Ellerbach
Copy link
Member

[Triage] The .NET nanoFramework community is working on a port to have .NET nanoFramework supported. This will take a little time.
The other element is that as soon as there will be a support for Arduino IDE, you'll be able to upload a Firmata firmware that will allow you to be used with .NET IoT from your Windows machine for example. This support is coming soon on our side, see #1039.

@Ellerbach Ellerbach added the blocked Issue/PR is blocked on something - see comments label Feb 18, 2021
@nh43de
Copy link

nh43de commented Feb 26, 2021

The only issue is that nanoFramework doesn't support .NET standard libs (yet?) as far as I'm aware. Makes sharing code between platforms a little more tricky, and all the IoT libs here unusable. NanoFramework has it's own specialized packages.

@pgrawehr
Copy link
Contributor

@nh43de Yes, that's absolutelly a limitation. We'll certainly be trying to support the Raspberry Pico trough our new Firmata binding. Unfortunatelly, there's currently no support to build for the Pico using the Arduino IDE (yet), which will cause an unknown extra effort in building that library. I also don't have the hardware so far. But please don't expect that you'll be able to run a full framework on the Pico, it's hardware (especially the memory) is to limited for that.

@Ellerbach
Copy link
Member

@nh43de it has the possibility to use .NET standard as project reference, then everything needs to be compiled for nanoFramework. mscorlib is a small subset of the full framework. With minimum numbers of methods.
You can check an example project using .NET Standard project reference between a reach .NET code base and a nano based one in the nanoFramework Unit Test Framework: https://github.com/nanoframework/nanoFramework.TestFramework
And yes, nanoFramewok has specific packages.

@Mallon94
Copy link

Mallon94 commented Apr 21, 2021

@nh43de Yes, that's absolutelly a limitation. We'll certainly be trying to support the Raspberry Pico trough our new Firmata binding. Unfortunatelly, there's currently no support to build for the Pico using the Arduino IDE (yet), which will cause an unknown extra effort in building that library. I also don't have the hardware so far. But please don't expect that you'll be able to run a full framework on the Pico, it's hardware (especially the memory) is to limited for that.

Now that the Pico does have Arduino IDE support, can we expect some firmata capabilities? @pgrawehr

@pgrawehr
Copy link
Contributor

@Mallon94 As far as I know, there are only projects in Beta state right now (or are you looking at a specific toolkit)? I have not tested any of those yet, for lack of time.

In theory, it should be easy: Check out https://github.com/pgrawehr/ConfigurableFirmata (branch develop!), and update the file "Boards.h" to include the hardware configuration for the pico.

@Mallon94
Copy link

@pgrawehr Thanks for the advice. I had a quick look at using configurablefirmata and updating the Boards.h file, however it still would not recognise the board everytime I tried to compile. It appeared like the name was wrong in the Boards.h file but i was using the correct build identifer from the boards.txt pico file.

I found there is something in works http://abyz.me.uk/picod/index.html that looks like a nice firmata alternative.

@pgrawehr
Copy link
Contributor

@Mallon94 Can you tell me which pico-for-arduino library you tried? I might give it a go if you want (I do not have the hardware, but maybe at least I could get it to compile)

@Mallon94
Copy link

@pgrawehr that would be great! Im using this https://github.com/earlephilhower/arduino-pico and using the standard board, not a variant.

@pgrawehr
Copy link
Contributor

pgrawehr commented Apr 21, 2021

@Mallon94 I have created a branch "Pico" that builds (use the ConfigurableFirmata.ino file from the folder with the same name). Since the Firmata protocol doesn't currently support pin selections, I have hardcoded that the I2C bus is on GPIO pins 4 and 5 (if enabled) and SPI is on GPIO pins 6-9. As said, I do not have the hardware, so it would be nice if you could do some testing.

@Mallon94
Copy link

Thanks for your time @pgrawehr I appreciate it. I tried that branch, but it was having compile errors. Did you hardcode the SPI using SetTX and SetRX?
Arduino/libraries/ConfigurableFirmata/src/SpiFirmata.h:296:7: error: 'class arduino::MbedSPI' has no member named 'setTX' SPI.setTX(7); ^~~~~
Seems to happen with MBed12C aswell

@pgrawehr
Copy link
Contributor

It seems you have a different board setting or something like that. If I purposedly missspell that call, the error message is C:\Users\....\Arduino\libraries\ConfigurableFirmata\src/SpiFirmata.h:296:7: error: 'class SPIClassRP2040' has no member named 'set2TX'; did you mean 'setTX'?

Not sure why the type is MbedSPI for you, but SPIClassRP2040 for me. I am using Version 1.1.0 of the Pico library and the board is set to "Raspberry Pi Pico". The code https://github.com/earlephilhower/arduino-pico/blob/master/libraries/SPI/SPI.h clearly suggests that SPIClassRP2040 should be used. It seems that for whatever reason, the system finds another SPI library on your system.

Look for lines such as the following in the output:

Alternatives for Wire.h: [[email protected]]
ResolveLibrary(Wire.h)
  -> candidates: [[email protected]]

and

Alternatives for SPI.h: [[email protected]]
ResolveLibrary(SPI.h)
  -> candidates: [[email protected]]

Does it list more than one candidate?

@Mallon94
Copy link

I fixed it, was defaulting to a different board i had previously installed which was a Mbed OS RP2040 board. Got rid of it and it used 1.1.0 of the Pico lib. DHT was causing a timeout and preventing build so i disabled it and it built! Will get testing this now.

@mattjlewis
Copy link

FYI I updated the Arduino Firmata Boards.h file to include this:

// Raspberry Pi Pico
#elif defined(TARGET_RP2040) || defined(TARGET_RASPBERRY_PI_PICO)
#define TOTAL_ANALOG_PINS       3
#define TOTAL_PINS              29
#define VERSION_BLINK_PIN       LED_BUILTIN
#define IS_PIN_DIGITAL(p)       ((p) >= 0 && (p) < 26)
#define IS_PIN_ANALOG(p)        ((p) >= 26 && (p) < 26 + TOTAL_ANALOG_PINS)
#define IS_PIN_PWM(p)           digitalPinHasPWM(p)
#define IS_PIN_SERVO(p)         IS_PIN_DIGITAL(p)
#define IS_PIN_I2C(p)           0
#define IS_PIN_SPI(p)           0
#define PIN_TO_DIGITAL(p)       (p)
#define PIN_TO_ANALOG(p)        ((p) - 26)
#define PIN_TO_PWM(p)           PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p)         (p)

and so far, so good - I can retrieve the board capabilities and blink an LED. I've not done this before so not sure if the above is entirely correct - I've ignored I2C and SPI for now.

@pgrawehr
Copy link
Contributor

@mattjlewis That sounds good. I have (since a few days) full repo access to firmata and intend to add support for all the never boards (Pico, but also ESP32, Arduino Due) as soon as I get to it - It's all tested and ready, I just need to merge stuff together. So you could be creating a PR on firmata/ConfigurableFirmata if you like (ideally with I2C/SPI).

@mattjlewis
Copy link

mattjlewis commented Jul 24, 2021

FYI I can confirm that I2C works, raised this issue in ConfigurableFirmata: firmata/ConfigurableFirmata#115. I'll retest against the latest codebase (I had used the 2.10.1 release from 2018 and had to modify a couple of files) and submit a pull request instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation blocked Issue/PR is blocked on something - see comments
Projects
None yet
Development

No branches or pull requests

7 participants