Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 11 10:26
    hgmarques commented #315
  • Nov 11 09:49
    okelk edited #496
  • Nov 11 09:48
    okelk opened #496
  • Nov 11 09:38
    pgrawehr commented #315
  • Nov 11 09:36
    hgmarques commented #315
  • Nov 11 06:05
    pgrawehr commented #315
  • Nov 10 18:24
    jflamy commented #315
  • Nov 03 09:03
    SKH2800 closed #494
  • Nov 03 09:03
    SKH2800 commented #494
  • Sep 20 07:27

    pgrawehr on master

    Added Teensy 4.1 pins to Boards… Added Teensy 4.1 pins to Boards… (compare)

  • Sep 20 07:27
    pgrawehr closed #495
  • Sep 20 05:22
    pgrawehr commented #495
  • Sep 15 23:27
    ktgilliam opened #495
  • Sep 11 20:04
    hgmarques commented #315
  • Sep 11 19:35
    pgrawehr commented #315
  • Sep 11 19:10
    hgmarques commented #315
  • Sep 11 18:41
    pgrawehr commented #315
  • Sep 11 18:26
    hgmarques commented #315
  • Aug 02 12:50
    hgmarques commented #315
  • Aug 01 19:28
    pgrawehr commented #315
Clive Galway
@evilC
still, by switching to PIN/STATE you lose 50% bandwidth at most, but you could gain a bunch of CPU cycles at the host
maxing out the CPU of the arduino is no big deal
Jeff Hoefs
@soundanalogous
Well it depends on how much the CPU is doing. Firmata is a general protocol. You could have an application that does far more than check a few digital pin values.
Clive Galway
@evilC
input + arduino often means gaming
Jeff Hoefs
@soundanalogous
Currently there is no definition in the protocol for reading an individual digital pin. Once that is added you can do whatever you want in firmware.
firmata/protocol#68
Clive Galway
@evilC
I don't think my suggestion would require deprecating ports
Jeff Hoefs
@soundanalogous
Ports wouldn't be deprecated
A new feature would be added that enables reporting individual pins in addition to ports
A firmware implementation would use one method or the other
Clive Galway
@evilC
At the moment, a packet for a given port always holds all values for the pins in that port yeah, as 8 bits?
Jeff Hoefs
@soundanalogous
correct
1 bit per pin
Clive Galway
@evilC
so port 0 might be like 001234567
but in binary of course
so all I am saying is maybe allow a mode like 00110
Jeff Hoefs
@soundanalogous
That's how it works today
Clive Galway
@evilC
meaning "Port 0/ Pin 0 changed to 1 / Pin 1 changed to 0
but it can be sparse
ah I see, bits
duh
yeah I see, much bigger
4 bits to desribe which pin in port, plus 1 for state
Jeff Hoefs
@soundanalogous
Here's an example of parsing a digital message in firmata.js: https://github.com/firmata/firmata.js/blob/master/lib/firmata.js#L124-L149
Clive Galway
@evilC
I don't think I would have any trouble in doing it, I already have to do similar things when I process DirectInput and XInput
Clive Galway
@evilC
        private Dictionary<int, bool> pinStates = new Dictionary<int, bool>();

        private void Session_OnDigitalStateReceived(object sender, FirmataEventArgs<DigitalPortState> eventArgs)
        {
            var basePin = eventArgs.Value.Port * 8;
            for (var portPin = 0; portPin < 8; portPin++)
            {
                var fullPin = basePin + portPin;
                var isSet = eventArgs.Value.IsSet(portPin);
                if (!pinStates.ContainsKey(fullPin))
                {
                    pinStates.Add(fullPin, !isSet);
                }
                if (isSet == pinStates[fullPin]) continue;
                pinStates[fullPin] = isSet;
                Console.WriteLine($"Port {eventArgs.Value.Port}, Pin {portPin} (Pin #{fullPin}) changed to {isSet}");
            }
        }
I spose I may need to check if mode is pullup and stuff tho?
as from what I can tell, in pullup mode, unpressed is 1, but in normal mode, 0 is unpressed?
Clive Galway
@evilC
Hmm, the C# library does not seem to have a GetDigitalPinMode()
Clive Galway
@evilC
using Solid.Arduino;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Solid.Arduino.Firmata;

namespace FermataTest
{
    public class Class1
    {
        private readonly ArduinoSession _session;
        private readonly Dictionary<int, bool> _pinStates = new Dictionary<int, bool>();
        private readonly Dictionary<int, PinMode> _pinModes = new Dictionary<int, PinMode>();

        public Class1()
        {
            var connection = GetConnection();
            _session = new ArduinoSession(connection);

            SubscribeDigitalPin(2, PinMode.InputPullup);
            SubscribeDigitalPin(3, PinMode.InputPullup);
            SubscribeDigitalPin(4, PinMode.InputPullup);
            SubscribeDigitalPin(5, PinMode.InputPullup);
            SubscribeDigitalPin(6, PinMode.InputPullup);
            SubscribeDigitalPin(7, PinMode.InputPullup);
            SubscribeDigitalPin(8, PinMode.InputPullup);
            SubscribeDigitalPin(9, PinMode.InputPullup);
            SubscribeDigitalPin(10, PinMode.InputPullup);
            SubscribeDigitalPin(11, PinMode.InputPullup);
            SubscribeDigitalPin(12, PinMode.InputPullup);
            SubscribeDigitalPin(13, PinMode.InputPullup);

            _session.DigitalStateReceived += Session_OnDigitalStateReceived;
            Console.ReadLine();
            _session.Dispose();
            connection.Dispose();
        }

        public void SubscribeDigitalPin(int pin, PinMode mode)
        {
            _session.SetDigitalPinMode(pin, mode);
            _pinModes[pin] = mode;
            var port = pin / 8;
            _session.SetDigitalReportMode(port, true);
        }

        private void Session_OnDigitalStateReceived(object sender, FirmataEventArgs<DigitalPortState> eventArgs)
        {
            var basePin = eventArgs.Value.Port * 8;
            for (var portPin = 0; portPin < 8; portPin++)
            {
                var fullPin = basePin + portPin;
                if (!_pinModes.ContainsKey(fullPin))
                {
                    continue;
                }

                var pinMode = _pinModes[fullPin];
                var pressedValue = pinMode != PinMode.InputPullup;
                var isSet = eventArgs.Value.IsSet(portPin) == pressedValue;
                if (!_pinStates.ContainsKey(fullPin))
                {
                    _pinStates.Add(fullPin, false);
                }
                if (isSet == _pinStates[fullPin]) continue;
                _pinStates[fullPin] = isSet;
                Console.WriteLine($"Port {eventArgs.Value.Port}, Pin {portPin} (Pin #{fullPin}) changed to {isSet}");
            }
        }

        private static ISerialConnection GetConnection()
        {
            Console.WriteLine("Searching Arduino connection...");
            var connection = EnhancedSerialConnection.Find();

            Console.WriteLine(connection == null
                ? "No connection found. Make shure your Arduino board is attached to a USB port."
                : $"Connected to port {connection.PortName} at {connection.BaudRate} baud.");

            return connection;
        }
    }
}
Jeff Hoefs
@soundanalogous
Regarding pull-ups, that's correct. The value is 1 normally and 0 if pressed because the current is pulled up to VCC and when you press the button, it's pulled down to ground. You can find a thorough explanation here: https://learn.sparkfun.com/tutorials/pull-up-resistors.
Rabin Shrestha
@jyapujuju
Hello
I set pinb as input
When i read all six pin as it show me 0
It only work upto 31
Why??
KoToZ
@Mohamedtareque
Hey is there any documentation to start with
Giuseppe Giannotti
@giannottigiuseppe
hi all, it is possible to modify firmata in order to receive a digital input and send a digital output in loop?
Philip Poten
@elpollodiablo
Hey guys, I want to use firmata as a way to control relays with a small python script and without a running daemon
Yet firmata apparently does not like that at all and will always reset when serial is disconnected :(
(not the hardware, but the cli python script)
how do I avoid that?
Alan Yorinks
@MrYsLab
@elpollodiablo I am not sure if I understand your question or what you are trying to do. I do not know if this will solve your issue, but pymata4 which was released yesterday may solve your issue. If you set the "shutdown_on_exception" parameter to False, then a Firmata reset will not be sent to the Arduino unless you explicitly send the reset request. That being said, if you lose the serial link and do not shut down gracefully, then if you have analog input that is streaming data, it will continue to stream, and pymata4 will most likely issue an exception.
Mallon94
@Mallon94
Hey guys, now that the pi Pico has Arduino support, will you be implementing it to firmata?
Alan Yorinks
@MrYsLab
@Mallon94 I am not sure which computer language you use for the client, but there is a Python client and Pico C SDK server for something that is similar to Firmata called Telemetrix-RPi-Pico. Here is a link to the documentation: https://mryslab.github.io/telemetrix-rpi-pico/
Denny Nur Ramadhan
@denuradhan
did anyone know how to use pinMode(button, INPUT_PULLUP) but in pyfirmata version?
detail question is here
Alan Yorinks
@MrYsLab
I just posted an answer on stackoverflow.
Tanish Mishra
@amateurexpert1_twitter
Hi, does anyone know how to use interrupts with PyFirmata
HarkeeratSingh
@HarkeeratSingh
can we use the ESP8266 definition in Boards.h for ESP32 board?
Alan Yorinks
@MrYsLab
For the ESP32, you can try a more modern approach, Telemetrix. For The ESP32 https://mryslab.github.io/telemetrix-esp32/