Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Yeah, just Google spring shock sensor, they'll come right up. I have a little plastic ball, think marble sized, with one of those and some flashy LEDs. It's lasted literally ten years, somehow gets moved with me, keeps turning up in drawers and surprises me when it gets bumped and starts flashing for a minute

Adbot
ADBOT LOVES YOU

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Not as cool and harder to use though

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

taqueso posted:

They mention using a USB-serial converter so that makes it 99.99% chance its RS232.

Hmm, it connects with a 3.5mm jack so maybe lower that to 98%.

RS232 is specifically -15V / +15V, and it's really doubtful that that's it.


A USB-Serial converter, and this BMS, probably, will be UART (which is pretty standard serial), but that still doesn't answer the question of whether it's 5V or 3.3V. Most modern stuff has moved over to 3.3V, and I'd recommend picking up some sort of 3.3V-compatible Arduino-alike. The Teensy is supposed to be good, I guess.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I dunno if you have a multimeter or scope, or even an Arduino Uno with an analog pin available, but definitely double check that your BMS is using 5V serial.

If it is, yeah, gopher it, use an Arduino Mega or something 5V with multiple UARTs. You seem to be barking up the right tree.


If it's 3.3v, I guess that's still the best route if you need the 5V output, but you'll need a level shifter to get from 5V to 3.3V logic so you don't blow up your BMS's RX pin. Lots of those available on AliExpress for a few pennies. It's just a couple transistors.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Uhh paid software?

PlatformIO is free / OS, built into VS Code, owns bones, and can "import" Arduino projects and there is literally no reason to even download the Arduino IDE anymore, seriously. Drop that hot garbage.

PIO even just opened up their previously paid debugger.

Also it comes preloaded with a million different Arduino clones configs so it can sort through their peculiarities, and automagically does the toolchain stuff for Arduino / Espressif stuff / STM stuff and some others.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Tbh my advocacy of PIO goes way beyond personal preference, and there have been several breaking changes in libraries that would have sunk my projects, had I been using the Arduino IDE.
PIO allows you to fix your libraries and frameworks to specific versions if you like, and use a config file that tells anyone that has your project how to install it automatically, without the version/incompatibility hell that is the Arduino ecosystem.

There are many other reasons to use it over the official stuff, it's just that that one seems relevant to your issue. It's worth the minimal learning curve to figure out how the config file works, to help with future robustness and ease of sharing, and all sorts of customisation

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I don't understand what's making the beep, the Uno does not have any noise making capability

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Yeah, I probably wouldn't run an Arduino directly from a car's 12V line and expect it to survive long, that's real dirty power

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I would classify anything over 10uF as big-ish

Too many unknowns to figure out the exact "right" value, but guess-and-check is an accepted method for this kind of thing. Any value will shift the frequency, just gotta do it enough so it no longer bothers you

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Assuming that it's a clean voltage that is within the range the board claims to be able to handle, it's fine.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Avvy beacons don't actually use RF either, they use magnetostriction, and it's awesome

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Web IDEs own when I'm jumping between three or four different computers. Although I prefer VSCode with an FTP file system to my server

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
How are you triggering programming mode?

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

babyeatingpsychopath posted:

Baud rate on the ESP8266s is 76800 for some reason, so I bet the ESP32 has some arbitrary baudrate that's in the datasheet somewhere.



115200, but what I'm getting at is that I bet he's not properly resetting it to programming mode

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Do you have anything else plugged into the GPIO of the board? There are four or five pins that can't be pulled high or low on startup, they'll change internal flash settings and stuff.

Uuuusually when you have the correct baudrate set, you can listen in with your UART dongle and see boot up messages. Random ascii kinda says wrong baudrate or wrong comm settings in some way to me

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

babyeatingpsychopath posted:

No. The barrel jack goes through a regulator then dumps onto the VIN pin.


Not directly. If you take a look at the official schematic, the barrel jack goes through a P channel MOSFET that cuts off the USB power

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I'm so confused by that diagram

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Gonna repeat that the official Uno does exactly that, with a MOSFET

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Your input pin is floating, so it's basically showing whatever electrical charge is on the pin


Use pull ups, either physical or in software

Edit: oh wait you did that

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Cojawfee posted:

Do any of the other pins do that?

Is pin 2 perhaps tied to the onboard LED? I ran into something like that when making my controller. Pin 6 I think was tied to the onboard LED on my teensy, so when I pushed the button connected to that pin, it would stay pressed. If that is the case, you can't use pullup like normal. You either need to figure out another way to do it, or remove the LED. I put a 1k resistor from the pin to ground and it solved my problem.

He figured it out, I think, from the edit.

I've never used the Teensy or anything for keyboard emulation, but I guess Keyboard.send_now() sends a keydown event, and requires another command to release the key after you're done

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
No it can't

Why do people always neglect shipping on JLCPCB in particular. It's their marketing thing and it really seems to be working. And they've really hosed me on shipping.

Check out pcbshopper.com for price comparisons. The majority of them are in the realm of $14 for 5x5cm, qty 10.
I like PCBWay, or Seeed, but it's mostly all the same

ante fucked around with this message at 19:55 on Jan 2, 2020

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Huh? No I'm saying they literally lie about the price. They're the same price as everyone else, including shipping, because everyone else does "free shipping". Which is obviously also technically incorrect, but a whole lot less dishonest

They also pull some shipping shenanigans that have triggered duties or required me to self clear, and I'm not sure what they're doing differently to make that happen. It's only them, though

ante fucked around with this message at 19:57 on Jan 2, 2020

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
lol there's no part of the USB stack that won't make you want to die

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
LCDs universally fuckin' blow to drive, from the driver side, and then from the interface side

Hth

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Are you using PlatformIO? It makes it pretty easy to use Arduino stuff with the Blue Pill

I think I tried to use the Arduino IDE with the Blue Pill before PIO was a thing, and it was a whole lot of frustrating loving around. Not a lot of reason to use the official IDE tbh

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Yeah, that sounds about right. Just a lot of loving around.
Tbh I liked the power-to-dollar ratio, but the time it took to do anything was ridiculous. I ended up doing everything with ESP32 dev boards instead. They're more powerful, maybe $2 more expensive, and have integrated programmers.

Alternatively, I picked up some $20 ST dev boards with the STLink on board, and they're nice to work with, too.

I can't think of a case where I'd actually want to go back to the Blue Pill, as much as I like the idea.


General_Failure posted:

Mostly arduino-cli. Not for some neckbeard hipster reason though

...

my development platforms are a Jetson Nano and a Pinebook.

Lol

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
You really don't want to ease into it slowly, huh?

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Sucks donkey balls.

I did it professionally for way too long.


Look up "ladder logic", that's how PLCs are programmed. It's kind of a parallel visual programming language, and is designed to be picked up by automation engineers with little programming experience. It gets very unwieldy, very very fast, though, and all the tools suck.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Don't be afraid of SMD, either. Larger pitched packages are actually easier to solder than DIP.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Yeah, don't bother etching. It's more worth your time to send off for professional PCBs, when the time is right for you.

In the meantime, I'd stock up on a bunch of breakout boards of all different sizes of I were you. A lot of ICs, particularly modern microcontrollers only come in SMD packages.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
They're not gougy, you're going to have to adjust your expectations!

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
CMOS is usually 0.7 * VCC, which works out (unfortunately) to 3.5V for 5V systems. It'll be in the datasheet

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
I thought that was a soldering iron at first and was horrified

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Connectors are (usually) rated very conservatively

https://hackaday.io/project/3339/log/50102-tedious-testing-suggests-the-connector-selection-is-sound

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

FetusPorn posted:

I've got a question I'm sure one of you fine folk should be able to answer.

I'm working on using an ATTINY84 to replace an obsolete quadrature encoder counter IC (HCTL-2017-A00) for a hand operated jog-wheel on a motion control system I'm trying to restore.

I've got the project working on a breadboard (programming through Arduino IDE and UNO as ISP) and I have a little PCB designed that'll breakout the TINY pins to the pinout of the HCTL. Since it's a hand-jog I'm not too worried about it not being able to operate as fast as the original chip (32Mhz), but I'm still trying to optimize things as much as possible for an accurate count. So, I turned to port manipulation:

I can post the entire code if needed, but I'm just stuck on this bit in the loop().
code:
  //if (count>255) count = count-256;
  //if (count<0) count = count+256;
  
  //PORTA=count;

  for (byte i = 0; i < numPins; i++) { // this loop outputs the binary equivalent of 'count' to the output pins.
    byte state = bitRead(count, i);
    digitalWrite(pins[i], state);

The uncommented part works great, but still uses digitalWrite() which I guess can be a little slow for these kinds of things. If it could operate faster, I'd be happy.
But, generally, no issues with this code; count may go above 256, but the output just rolls over to 0 as I would expect (ignoring higher bits). NO errors on the rollover regardless of rotation speed.

So I found the delightfully simple (currently commented) "PORTA=count;" line to work quite well because all of my output pins are on the A channel of the TINY84. I, of course comment out the for loop when using this. HOWEVER, when the count rolls over and I keep turning the encoder in the same direction I sometimes get one or more bounces between 256 and zero before continuing up from 0 as normal. The faster I turn the encoder, the more likely this is to happen.

Thinking there was some issue with this line's translation of numbers outside of 0-255, I created the other 2 commented lines to clamp the count, but the issue still occurs.

Any idea how I can tame this beast? When it comes to this lower level coding, I'm a bit out of my depth.

code:
  count = count & 0xFF;
  PORTA=count;
That said, are you sure you're not prematurely optimising? For just reading back an encoder value, I feel like you could do it the least efficient way imaginable, and it would still be fine.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

FetusPorn posted:

Yeah, that seems to almost completely kill it... it must be a slow function. Thank you though!

Regardless of the rollover being constrained to 0-255 (with or without the clamping code I posted), I still get that strange output only with the port manipulation code, and not the for-loop.

The error appears to be something like ...253, 254, 255, 0, 255, 0, 1, 2... as the count goes up. It doesn't happen when going the other direction.

Here's the whole shebang:
code:
#include "PinChangeInterrupt.h" // MANDATORY: enable interrupts on pins 9-10 by changing line 228 to "#define PCINT_ENABLE_PORT1" in PinChangeInterruptSettings.h

const byte numPins = 8;// number of pins to output binary number on.
byte pins[] = {0, 1, 2, 3, 4, 5, 6, 7}; //array of which pins to use for those bits.
int encoderPinA = 9; // Quadrature encoder leg A pin location
int encoderPinB = 10; // Quadrature encoder leg B pin location
volatile unsigned int count = 0; // Holds encoder count.
static boolean rotating = false; // debounce management
boolean A_set = false;
boolean B_set = false;

void setup() {

  DDRA = 0b11111111; // set all output pins.
  DDRB = 0b00000000; // set the interrupt inputs (last 2 bytes are all we need for Pin9-10).
  attachPCINT(digitalPinToPCINT(encoderPinA), encodedA, CHANGE);
  attachPCINT(digitalPinToPCINT(encoderPinB), encodedB, CHANGE);
}

void loop() {
  rotating = true;  // reset the debouncer when interrupt code is not running.
  //if (count>255) count = count-256;
  //if (count<0) count = count+256;
  PORTA=count;
/*  for (byte i = 0; i < numPins; i++) { // this loop outputs the binary equivalent of 'count' to the output pins.
    byte state = bitRead(count, i);
    digitalWrite(pins[i], state);
  }*/
}

void encodedA() {
  if (rotating) delayMicroseconds(250);  // small delay to debounce.
  if (PINB & 0b00000001) { // Low to High transition?
    A_set = true;
    count = (B_set) ? count - 1 : count + 1;
  } else { // High to Low transition
    A_set = false;
    count = (B_set) ? count + 1 : count - 1;
  }
  rotating = false;
}

void encodedB() {
  if (rotating) delayMicroseconds(250);  // small delay to debounce.
  if (PINB & 0b00000010) { // Low to High transition?
    B_set = true;
    count = (A_set) ? count + 1 : count - 1;
  } else { // High to Low transition
    B_set = false;
    count = (A_set) ? count - 1 : count + 1;
  }
  rotating = false;
}

You're probably hitting interrupt encodedB(), and then it delays, and gets interrupted by encodedA()


Usuuuually you'd never ever want to put a delay in your interrupt for that reason, but considering your code is doing nothing else, you should be able to get away with just disabling the interrupt while it's running (also good practice generally)

code:
void encodedB() {
  disablePinChangeInterrupt(digitalPinToPCINT(encoderPinA));
  disablePinChangeInterrupt(digitalPinToPCINT(encoderPinB));
  if (rotating) delayMicroseconds(250);  // small delay to debounce.
  if (PINB & 0b00000010) { // Low to High transition?
    B_set = true;
    count = (A_set) ? count + 1 : count - 1;
  } else { // High to Low transition
    B_set = false;
    count = (A_set) ? count - 1 : count + 1;
  }
  rotating = false;
  enablePinChangeInterrupt(digitalPinToPCINT(encoderPinA));
  enablePinChangeInterrupt(digitalPinToPCINT(encoderPinB));
}

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Doing low power / current sipping is also really tough. But don't let that dissuade you, that's a case of "getting it going once, then see if it's good enough. Then, incrementally optimise the code until it works."


There are lots of kinda on settings / strategies you can use to help.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
He's trying to get remote sensing so they can check while they're not at the property

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Teensy?

Adbot
ADBOT LOVES YOU

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
The price is right, but only if you want A Project and don't value your time.

I've used them a lot, and they're great, but I've definitely put the work in

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply