Last few inputs are unresponsive
Hello, so I have an Arduino Mega on Uduino 2.1.8 that has 7 potentiometers and 6 buttons. I have tested each input individually, and they all work, however when I try to get an input from all of them at once, the last 2 or 3 inputs to be called in my script (whether they're buttons or pots) will be unresponsive. there is no error or warning thrown in Unity to acknowledge this. I have tried fiddling with the serial settings in uduino and it hasn't gotten me any closer to hearing them all at once.
Here is my code for the script for all my inputs and I have attached an image of the inspector so you can see:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Uduino;
public class ArduinoReader : MonoBehaviour
{
public float[] potValue;
public AnalogPin[] pinsPots;
public int[] pinsButtons;
public int[] buttonValue;
// Use this for initialization
void Start()
{
for (int i = 0; i < pinsPots.Length; i++)
{
UduinoManager.Instance.pinMode(pinsPots[i], PinMode.Input);
}
for (int i = 0; i < pinsButtons.Length; i++)
{
UduinoManager.Instance.pinMode(pinsButtons[i], PinMode.Input_pullup);
}
}
void Update()
{
for (int i = 0; i < potValue.Length; i++)
{
potValue[i] = UduinoManager.Instance.analogRead(pinsPots[i]);
}
for (int i = 0; i < buttonValue.Length; i++)
{
buttonValue[i] = UduinoManager.Instance.digitalRead(pinsButtons[i]);
}
}
}
Comments (5)
-
repo owner -
Thank you for the quick response! I will try these fixes out.
-
All of these together solved the problem! Once I added the analog bundle I didn't even need to change maxQueueLength anymore. However, on the line
buttonValue[i] = UduinoManager.Instance.digitalRead(pinsButtons[i],"ReadButton");
I'm getting the error
Assets/ArduinoReader.cs(52,53): error CS1502: The best overloaded method match for `Uduino.UduinoManager.digitalRead(Uduino.UduinoDevice, int)' has some invalid arguments
and
Assets/ArduinoReader.cs(52,76): error CS1503: Argument
#1' cannot convert
int' expression to type `Uduino.UduinoDevice'I looked at the unity script reference on the Uduino site and then checked through Visual studio's auto complete, and it looks like there is no [string bundle=null] method in digitalRead's overload methods while analogRead does! Any idea how to remedy that? for now it doesn't hinder what I'm doing, but might be something to update or remedy in some way.
Thank you for your help!!!
-
repo owner Thank you for your feedback, I'm glad it's working now.
I probably removed the
UduinoManager.Instance.digitalRead(int,string)
function in the previous build, I'll work on that tomorrow and add it in the next version. -
repo owner - changed status to resolved
- Log in to comment
Hi,
I'll look at that. I think I know were this issue comes from, however, I don't know yet how to fix it. I'll definitely address this issue. There are few possibilities to fix that:
maxQueueLength
to 20 .Advanced > Serial setting > thread frequency
, reduce it to 3 or 5)I acutally never tried with that maybe buttons reading. It should work just fine. You might run into two issues:
Uduino has a specific features called 'Bundles' (documentation). It's a parameter (string) that you can add at the end of your Uduino command. By doing that, rather than sending right avay the commant to the arduino board, it will wait until you call a function to send the bundle.
Concretely, it increases the performance and reduce the lost packets : Rather than sending 12 times the command 'read pin X',' read pin Y' it will send once the command ' read pin X & Y & Z & ....'
Examples can be find in
Examples > Basic > AnalogRead
andExamples > Advanced > Bundle
. For your code, it will be :Hope it helps !