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

For ESP32 #13

Open
DavidCarl opened this issue Mar 14, 2022 · 3 comments
Open

For ESP32 #13

DavidCarl opened this issue Mar 14, 2022 · 3 comments

Comments

@DavidCarl
Copy link

Hello

I am looking to implement this library for a project I am doing with a ESP32.

The issue is the following when I try to instantiate this library in the SPI pin from the ESP32.

    let spi = peripherals.spi2;

    let mut lora = sx127x_lora::LoRa::new(spi, sc, rst, FREQUENCY, delay);

It simply gives me this error:

let spi: SPI2
Go to SPI2

the trait bound `esp_idf_hal::gpio::Gpio14<esp_idf_hal::gpio::Unknown>: embedded_hal::digital::v1::OutputPin` is not satisfied
required because of the requirements on the impl of `embedded_hal::digital::v2::OutputPin` for `esp_idf_hal::gpio::Gpio14<esp_idf_hal::gpio::Unknown>`rustcE0277
the trait bound `esp_idf_hal::spi::SPI2: embedded_hal::blocking::spi::transfer::Default<u8>` is not satisfied
required because of the requirements on the impl of `embedded_hal::blocking::spi::Transfer<u8>` for `esp_idf_hal::spi::SPI2`rustcE0277
main.rs(43, 20): required by a bound introduced by this call
lib.rs(190, 29): required by a bound in `sx127x_lora::LoRa::<SPI, CS, RESET, DELAY>::new`
the trait bound `esp_idf_hal::spi::SPI2: embedded_hal::blocking::spi::write::Default<u8>` is not satisfied
required because of the requirements on the impl of `embedded_hal::blocking::spi::Write<u8>` for `esp_idf_hal::spi::SPI2`rustcE0277
main.rs(43, 20): required by a bound introduced by this call
lib.rs(190, 52): required by a bound in `sx127x_lora::LoRa::<SPI, CS, RESET, DELAY>::new`

Is this anything you have experience with by any chance?

Sincerely

@bernii
Copy link

bernii commented Apr 3, 2022

I just wanted to confirm that this lib is working with TTGO ESP32 LORA v2.0 (esp32 based).

Example quick &dirty code

    let config = <spi::config::Config as Default>::default().baudrate(200.kHz().into());
    let sclk = pins.gpio5;
    let miso = pins.gpio27;
    let mosi = pins.gpio19;
    let cs = pins.gpio18;
    let rst  = pins.gpio12;
    let spi = peripherals.spi2;

    let spi = spi::Master::<spi::SPI2, _, _, _, _>::new(
        spi,
        spi::Pins {
            sclk,
            sdo: miso,
            sdi: Some(mosi),
            cs: Option::<gpio::Gpio18<gpio::Unknown>>::None,
        },
        config,
    ).unwrap();
    
     let mut lora = sx127x_lora::LoRa::new(
        spi,
        cs.into_output().unwrap(),
        rst.into_input_output().unwrap(),
        868,
        Ets
    );

    match lora {
        Ok(_) => info!("lora succes"),
        Err(ref x) => error!("error {:?}", x),
    };

    let mut lora = lora.unwrap();

    let message = b"Hello, world!";
    let mut buff = [0u8; 255];
    buff[..message.len()].clone_from_slice(message);
    let transmit = lora.transmit_payload(
        buff,
        message.len()
    );

    match transmit {
        Ok(_) => info!("Sent packet"),
        Err(e) => error!("Error: {:?}", e),
    }

    loop {
        let poll = lora.poll_irq(Some(30)); //30 Second timeout
        match poll {
            Ok(size) =>{
               info!("with Payload: ");
               let buffer = lora.read_packet().unwrap(); // Received buffer. NOTE: 255 bytes are always returned
               for i in 0..size{
                    print!("{}", buffer[i] as char);
               }
               println!();
            },
            Err(err) => (), //info!("Timeout {:?}", err),
        }
        thread::sleep(Duration::from_millis(100));
    }

@DavidCarl DavidCarl changed the title For ESP32 For ESP32 May 16, 2022
@S3j5b0
Copy link

S3j5b0 commented May 16, 2022

Hi, @bernii, were you able to send messages with the module using this code?

@gmelodie
Copy link

I added a full example that I made for the Lora32 board in #18

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

No branches or pull requests

4 participants