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

Overhaul API and update for Dart 3 #12

Open
8 of 15 tasks
danrubel opened this issue Jul 12, 2018 · 16 comments
Open
8 of 15 tasks

Overhaul API and update for Dart 3 #12

danrubel opened this issue Jul 12, 2018 · 16 comments

Comments

@danrubel
Copy link
Owner

danrubel commented Jul 12, 2018

There's a lot of unused C code and unnecessary complexity that I aim to remove in the process of readying this package for Dart 2. The work-in-progress API that I'm working towards has a library of abstract classes ...

abstract class Gpio {
  GpioInput input(int physicalPin, [Pull pull = Pull.off]);
  GpioOutput output(int physicalPin);
}

abstract class GpioInput {
  bool get value;
  Stream<bool> get values;
}

abstract class GpioOutput {
  set value(bool newValue);
}

... along with a separate library containing a concrete RpiGpio implementation of Gpio
and associated native code to make it all happen.

Current status:

Dart 3.x Platforms:

  • Upgrade to Dart 3
  • tested on Raspberry Pi 5
  • tested on Raspberry Pi 4
  • tested on Raspberry Pi 3

Dart 2.x Platforms:

  • tested on Raspberry Pi 5
  • tested on Raspberry Pi 4 (thanks to J4ckTh3R1qp3r and khanhnwin)
  • tested on Raspberry Pi 3
  • tested on Raspberry Pi 2
  • tested on Raspberry Pi 1
  • tested on Raspberry Pi 0

OS:

@jimmyff
Copy link

jimmyff commented Aug 2, 2018

Really pleased to hear you're updating this package.

Let me know if you would like some help - although I can't help out with the C code!

@danrubel
Copy link
Owner Author

danrubel commented Aug 3, 2018

Much appreciate the offer of help.
I've partially implemented the above API, but more importantly... is that API enough for your uses?

@jimmyff
Copy link

jimmyff commented Aug 7, 2018

I've been tracking this package for a while and always been keen to see if I can drive an LED matrix from Dart but not yet given it a go. This is a good excuse to try, so once you're ready for a tester give a few weeks and I'll get back to you!

Did you push any of the new code yet? Let me know when it's in a position to test and I'll have a go with it!

@danrubel
Copy link
Owner Author

danrubel commented Aug 24, 2018

Just pushed 0.4.0-dev.1 with the new API.
The basic GPIO works, but still need to deliver the following...

  • pulse width modulation
  • A/D input support
  • tested on Raspberry Pi 4 (thanks to J4ckTh3R1qp3r)
  • tested on Raspberry Pi 3
  • tested on Raspberry Pi 2
  • tested on Raspberry Pi 1
  • tested on Raspberry Pi 0

Good progress, but I still have more work to do

@danrubel
Copy link
Owner Author

Just pushed 0.5.0 with new API.

@J4ckTh3R1qp3r
Copy link

Great package! Thank you a lot. Is there any chance to see update with PWM support soon? I am testing this on Pi4b by the way.

@danrubel
Copy link
Owner Author

danrubel commented Jan 12, 2021

Glad it's useful to you! I am using this package in production but have never needed PWM and thus haven't gotten around to adding it. How do you envision using it? That will give me a better idea of what needs to be added.

And thanks for letting me know that you are on the Pi 4... good to know it works there as well.

@J4ckTh3R1qp3r
Copy link

Actually Dart is my first programming language and Flutter is the first SKD. My needs right now are more about hobby and learning something new and interesting, but not about production or any other serious project/mvp. I want to upgrade a child toy - racing track for two cars. Each car has 2 contacts at the bottom which get 5V and GND (I guess) from contacts on the track and you can control speed of a car with a trigger which is actually a manual resistor. I want to connect track directly to Pi and control the speed of each car with PWM (Angel sdk as API server). I tried to use Dart loops to somehow repeat the PWM process, but they are too slow. If you have any other idea how I can reach my goal please share, that would be great!

@danrubel
Copy link
Owner Author

I did some digging and from it appears that the 2 PWM pins on RPi 4B might not interfere with the audio jack (an issue on earlier Pi models). I don't know for sure and I don't know if you need the audio jack.

I don't think you can drive/power the track directly from the RPi. You'd need some type of relay between the PWM output and the track. I think an optical relay based on the switching frequency needed. It's been quite a while since I played around in this area so consider this advice imperfect at best :-)

It will take me a while but I can look into updating the code to drive LEDs with PWM, but it would be up to you to figure out the rest of the circuit from the PWM to powering the track. Let me know if you are up for that and I can start working towards PWM support in this library.

@J4ckTh3R1qp3r
Copy link

Thank you very much! I already ordered this track and will get it by the end of the week. Will wait for any updates and can help with testing on PRI 4b. This could be the first Dart package that supports PWM 👍🥇🎉

@J4ckTh3R1qp3r
Copy link

Hi! Some updates from me:

  1. Each car consumes about 12V 0.6A
  2. I connected 12V to a 12V light diod through transistor which was controlled by RPI.
  3. I actually could control the brightness of diod through PWM on python:
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

led = GPIO.PWM(17, 500)
led.start(0)

while(1):
 for dc in range(0, 101, 5):
  led.ChangeDutyCycle(dc)
  time.sleep(0.1)

 for dc in range(100, -1, -5):
  led.ChangeDutyCycle(dc)
  time.sleep(0.1)

GPIO.cleanup()
  1. My schema was wrong as I had only 2-3V as an output from transistor and I started digging this problem.
  2. At some point something went wrong as I am total noob and I fried my RPI 😂😜
  3. I decided to order another model 4b and a Zero W as It it less expensive for the next BBQ and possibly help to test dart on it.

Well, I think now It should be clear how I will use PWM (frying RPI, yeah! :) ).

@danrubel
Copy link
Owner Author

Ouch! Welcome to hardware 😄 . I've fried my share of chunks of hardware over the years.

I'm opening a new issue focused on adding PWM support
so that we can deep drive there without overloading this issue with PWM details.

@danrubel
Copy link
Owner Author

danrubel commented Jul 4, 2021

Reworked the code to support PWM in a separate isolate... and published 0.6.0
As part of 0.6.0, I've loosened the SDK requirements so that hopefully it will work on older RPis

@danrubel
Copy link
Owner Author

This package has been updated to use dart:ffi and now runs on Dart SDK 2.18

@danrubel
Copy link
Owner Author

Just pushed version 0.9.1 with fixes for gpio inputs on RPi 4

@danrubel danrubel changed the title Overhaul API and update for Dart 2 Overhaul API and update for Dart 3 Nov 9, 2023
@danrubel
Copy link
Owner Author

danrubel commented Oct 7, 2024

Version 0.10 now relies on libgpiod so that it will work on RPi v5.

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

3 participants