Is this community still alive? If yes I've got a Rust-question.
I'm trying to run an LED matrix display (with a Max7219 controller) from a raspberry pi pico using rust.
There is a max7219-crate that I used. But i am unsure about how to prepare the pins I want to use. Can I Use any of the pins? Do I have to set them to push-pull-output?
Looks like that crate uses the standard embedded-hal abstractions. There are two functions you want to look at on the MAX7219 struct, from_pins and from_spi depending on whether you're using hardware SPI or bit bashing. If you notice the signature for from_pins specifies they must be OutputPin instances.
If you don't already have a HAL crate for the pico you should first grab that and familiarize yourself with the process of initializing the hardware and the HAL.
Hey! Thank you very much! It's very cool to see that there's still people around here :-)
Yes, i am using the rp-pico-hal. I guess I have to somehow activate the spi-funcrtonality first then, right?
I found an example where someone uses a Max7219-attached 8x8 Matrix with a Pico in rust. But in this example the MAX7219-crate isn't used. Instead some SPI-structs/functionality is written directly in the main. This example managed to write stuff on my LED-matrix.
I will read more into the stuff you mentioned. Thanks a lot!
If you follow that link I provided there's an example in there of exactly how to initialize SPI. The example uses it to control a MMC, but most of the setup (except the speed) should be essentially identical for you.
Also the example code on the crate itself is a pretty good place to start. It's using bit bashing rather than hardware SPI, but if you follow everything after the from_pins call and use most of the stuff from the SPI SD card example but init the MAX7219 using from_spi instead you should be up an running in no time.
I realize that I mixed two things together. Or misunderstood what spi is. I thought using the pins to communicate to another chip (the max7219) is the same as "spi". But it isn't.
The sd-card example is a little too big for me to understand right now.
I see that apparently I can use the max7219 via pins or via spi. Does this mean, that SPI is preferrable? ( im imagine with the pins I have to set the pin high and low manually, whereas with the spi i can use more abstract commands like "send out this byte".
I don't really have an exact answer to your question, as I don't write Rust, and I've never used a Raspberry Pi for electronics, but I have some educated input:
There is a max7219-crate that used. But i am unsure about how to prepare the pins want to use.
Presumably, the crate just exposes pre-defined config objects that you call in your code.
Can Use any of the pins?
From what I recall, no, you can't use any of the pins on the Raspberry Pi as generic IO (all this information that you are looking for is in the datasheets of the devices that you are using) -- some pins are dedicated for power, etc.
Do have to set them to push-pull-output?
Generally speaking, yes, if you want to use a generic I/O as an output, then you must configure it as such.