OSD Battery Monitoring for Helder's AIO Boards

Various user-contributed guides for hardware-related things
JackReacher
Posts: 14
Joined: Fri May 11, 2018 12:49 am
Location: Rome, Italy
Has thanked: 2 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by JackReacher » Tue May 15, 2018 4:55 am

Ok, tried again,unsuccesful. reinstalled all software, tried again, still no luck..
I hope someone already using a teensy extends a helping hand..
Thanks wailer for your support!

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Wed May 16, 2018 3:55 am

Hey JackReacher,

Not giving up on you,

Try this:

Code: Select all


#include <Bounce.h>

#define NUM_KEYS 12

struct Key {
  char keycode;
  Bounce* bounce;
};

Key keys[NUM_KEYS];

Key key(char keycode, int pin) {
  Key *ret = new Key;
  ret->keycode = keycode;
  ret->bounce = new Bounce(pin, 10);
  pinMode(pin, INPUT_PULLUP);
  return *ret;
}

void setupKeys() {
  keys[0] = key('w', 0);
  keys[1] = key('s', 1);
  keys[2] = key('a', 2);
  keys[3] = key('d', 3);
  keys[4] = key('p', 4);
  keys[5] = key('l', 5);
  keys[6] = key('o', 6);
  keys[7] = key('k', 7);
  keys[8] = key('x', 8);
  keys[9] = key('z', 9);
  keys[10] = key('q',10);
  keys[11] = key('e',11);
}

const int ledPin =  20;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
char i;

void setup() {
  setupKeys();
  Keyboard.begin();
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
  //  pinMode(0, INPUT_PULLUP);
}

void loop() {
  for (int i = 0; i < NUM_KEYS; i++) {
    keys[i].bounce->update();
    if (keys[i].bounce->fallingEdge()) {
      Keyboard.press(keys[i].keycode);
    } else if (keys[i].bounce->risingEdge()) {
      Keyboard.release(keys[i].keycode);
    }
  }
  int sensorValue = analogRead(21); // read the input on analog pin 0:
//Serial.println(sensorValue); // print out the value you read
float voltage = sensorValue * (4.88 / 1023.00); 
//Serial.println(voltage);
if(Serial.available())
{
i=Serial.read();
}
if(i=='1')
{
Serial.println(sensorValue);
}
i='0';

if (voltage > 4.5) 
 {
 digitalWrite(16, HIGH);
 }
else
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);
}
  }
  delay(10);
}
A couple of things you have to do before compiling and loading the sketch on your teensy:

The analog input is set to pin 21 on your teensy, change that if you wan't to use an other (analog) input.
The ledpin is set to pin 20 (so you have the two pins for battery monitoring close to each other) but you can change that also to your liking.
You also can edit the input (buttons) pins to your setup that's in the "void setupKeys()" part, every number after "keys[0] = key("letter", "number")" is the pin you want to assign to a button (do NOT edit the number between the two []).
You can find a keyboard/retropie listing here https://github.com/RetroPie/RetroPie-Se ... ontrollers

And one more other thing, set up your board like this:
screenshot.jpg
screenshot.jpg (234.7 KiB) Viewed 519 times
(the screenshot is the dutch version of the ide but i thing you will get it)
Its important to do this or you will (again) get a lot of annoying errors (and you've had enough of those).
Now your sketch should compile and upload without any errors!
The sketch handles keypresses but the result is the same!

Hope this does the trick, and battery monitoring will work...
Keep me posted!

And one final edit, if you realy want to go to joystick mode take a look at this page https://www.pjrc.com/teensy/td_joystick.html

JackReacher
Posts: 14
Joined: Fri May 11, 2018 12:49 am
Location: Rome, Italy
Has thanked: 2 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by JackReacher » Wed May 16, 2018 9:52 am

Hi Wailer,

yehaaaaaaaa

I was able to upload the sketch to my teensy and configure it succesfully as a joystick + buttons.
I am waiting for a set of resistors coming in through the mail and I will immediately test the battery monitoring feature but so far I have no doubt it will work!!!!

if I get it right I will just need to solder pin 21 and a 10k ohm resistor to the positive end of my battery (so to speak, there will be a dpdt switch in between) and that's it (plus the python script on the rasp). Can I consider as Vcc and GND the ones coming in from the usb connection or should I wire them separately (I am referring to the monitoring feature not the controls )?

Wailer you have been a great help and really made my day.
thanks for not giving up on me and, again, for your patience..

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Wed May 16, 2018 10:35 am

Great!
Glad i could be of help.
Right only pin 21/resistor/switch/lipo in that order ;) .
No extra wires are needed Vcc an ground are all connected through usb.
Hopefully your resistors arrive soon, let me/us know when everything is hooked up and working.
And if you any questions, just ask, no problem.

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Wed May 16, 2018 11:24 am

Oh if you're impatient (i would) you can test the battery monitor on your pc as well.

Connect the teensy to your pc, and start the arduino ide.
Start the serial monitor (the litte magnifying glass icon on the right side).
serialst.jpg
serialst.jpg (4.79 KiB) Viewed 499 times
Check if the baudrate is set to 115200 (right side screen bottom).
Then in the input box (small top of the screen) type 1 and push the send button.
serial.jpg
serial.jpg (30.55 KiB) Viewed 499 times
If everything is ok you should get a response from your teensy in the message screen (random number because there is nothing connected to pin 21 yet).
Them take a little piece of wire and connect pin 21 to the vcc pin (its only 5v and the teensy is running so nothing gets damaged trust me, i know the lipo is 3,7 volts but i don't believe the teensy has a 3v3 power pin but it's only for testing) type 1/hit send, and if everything is ok you should get a new number in responce..
Repeat the process again with the test wire to ground type 1/hit send, and again a new number.
Do this a few times (vcc, ground) to see if the number changes (should be roughly the same number with every switch).

If you get a responce and the number changes than break out the champagne/beer/coffee/tea and tell the band to start playing because then you're 99,9% sure you've done it (leave a little margin for errors ;) and keep the fireworks till all is connected in your GBZ).

JackReacher
Posts: 14
Joined: Fri May 11, 2018 12:49 am
Location: Rome, Italy
Has thanked: 2 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by JackReacher » Wed May 16, 2018 11:56 am

allright

tested it and these are the results...
Immagine.png
Immagine.png (22.68 KiB) Viewed 497 times
in order
not connected 3xx
vcc 1023
gnd 0

do you think is working?
I think it is!!!! :shock: :shock:

can't wait to hook up everything!!!

man, thank you!

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Wed May 16, 2018 12:12 pm

That's it, complimenti! :D :D :D

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Wed May 16, 2018 12:16 pm

110.gif
110.gif (253.77 KiB) Viewed 494 times
Couldn't resist ;)

Online
User avatar
Wailer
Posts: 90
Joined: Mon Jan 15, 2018 3:45 pm
Location: Tiel, The Netherlands
Has thanked: 24 times
Been thanked: 20 times

Re: OSD Battery Monitoring for Helder's AIO Boards

Post by Wailer » Fri May 25, 2018 2:56 pm

HoolyHoo wrote:
Sun May 13, 2018 8:22 am
Wailer wrote:
Sun May 13, 2018 8:04 am
JackReacher wrote:
Sat May 12, 2018 1:00 pm
Hi,
I am in the same situation here.. i am really confused on how to use my teensy 2.0 as a gamepad + battery monitor.. i flashed the hex but i am unable to assign the correct pins..if anyone could help would be very appreciated..
I am actually using the sketch found in this thread.
https://sudomod.com/forum/viewtopic.php ... sd+arduino
But I've got a feeling that it's not accurate enough...
A little "nervous" battery symbol (when battery level is getting at a switching point) and the "battery low" message is kicking in quite fast (maybe too soon).
So i wanted to compare this sketch with Hoolyhoo's original arduino sketch.

Just for info, hex files are already compiled sketch files who only need to be uploaded to your arduino.
They cannot be edited.
Sketches can but, you need the arduino ide to compile and upload.
https://www.arduino.cc/en/Main/Software
Hello, actually I looked and couldn’t find the source file I made but it’s very similar to the post in the link.

You should be able to adjust the battery level icons and video kick in by adjusting the values in the python part of the script. The Arduino sketch only passes the battery levels but the python script does the work.

Heya HoolyHoo,

Been so busy helping JackReacher that i totaly missed your adition ;)

I have been snooping around your script and the arduino code, and will do some finetuning to best suit my GBZ.
The arduino indeed only passes the value, but the way it's calculated (in the sketch i use) maybe could use some tweaking (or maybe not, will see)
Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest