Start a new topic

GPIO's - What are the possibilities?

Hi Patrick


I recently had a play with the expansion board, with a view to using a couple of GPIO's as inputs to do a bit of simple square wave pulse counting. What ever method I tried, seem to be hampered by the interpreter only 'allowing' around 10 code executions per second. What have you or other folks found during your experiments?


Steve.


Really slowed by the interpreter.


In my Serial over GPIO, I used a synchronise signal 

   loaded 2 lines with data bits,

raised a third as start - the other end will lower to clear as received.


This was around and effective 23-27 cycles per second.

I am trying to find the other thread where another user reported as well


mp4

Do you think Itead might open the throttle a bit somewhere down the line, such low rates hardly qualify the term GPIO's. Most MCU's including the one on the back of each display would normally be quite happy operating at switching speeds in the Mhz range. Not suggesting we need anything near that for most HMI applications, I was just trying to get a reliable count from a rotary encoder :)

Fast menu access, hardware/software safe locks, timer setting and such like spring to mind.

Oh and of course DCC throttles =)

It would indeed be nicer to see GPIO get an optimization overhaul somewhere.


PWM is holding a valid duty cycle and freq

As far as I can see pio is reading and writing accurately

Input binding mode is holding but the interpreter is not high speed switching.


I need to do a test for just how fast writing to pio is

I am thinking that its upper limit maybe around 2300ish 

but synching with good timing will be the issue

 - a timer has at best 20 times per second

And without a timer .... well, how to catch is going to be tricky at best


Time to break open some gear.

Yeah, I thought I was so near to completing an all Nextion logic DCC++ throttle then hit this little problem.

Input binding mode was my route of choice, is there another way of fabricating 'Interupt Service Routines'?

Mind you, it was like back to school breadboarding some CMOS logic gates in an attempt to give Nextion 'less to do', great fun :) - going to do it with transistors next, my order is in on the auction site.

Before the recent 'bitshift' update I had some fun doing the logic for the 29 DCC function switching.

That was cool, came with up a back to basics method which would allow storage for around 200+ loco's on one page storing each in a standard 32 bit Nextion variable.

Not checked out bitshift as yet.

Playing around with digital output

 - within a loop sub-millisecond control is possible

   haven't nailed it down perfectly

   but somewhere near 12600 to 13300 parts per second toggle

Any call to compare to something else

   these will use time and remove from


reacting to incoming is indeed less

   how complex the routines surrounding it is will indeed play into


In another thread, back around v38

   123 binding toggles with each increasing n0 worked

   but above 125 started giving false positives.

what occurs inside the binding all takes time

I have a few what ifs that I want to work out

Hi Patrick


For a rotary encoder with a 'filtered' output. With some transistor logic one can siphon off either the clockwise or counter-clockwise pulse stream so that only one or the other is ever presented at the GPIO's.

That negates the need for any code to sort out direction as is the usual case. Therefore just a simple count is needed - n0.val++ on one pin and n0.val-- on the other. I can't make it less demanding than that, and would only need something around 150 counts per second maximum. I can't produce the 125 you mention.

 

The irony is, that I can blast this over serial and Nextion performs really well - but I can only do that by connecting another MCU. I'll see if I can do a demo video ;)

Time to register for the New Nextion Forums =)


https://nextion.itead.cc/forums/topic/rotary-encoder-in-nextion-logic/


Hi Patrick,


OK, so I done the registration =)

So what is to become of all the information on this current site?


Was the above link just an example, I get a 404 not found.


I can do rotary encoder 'decoder' in Nextion logic =)

After more tests with a little bit of Arduino code, I've determined the maximum 'input binding mode' code executions to be 15Hz.


This code will do a rough square-wave output on pin 2 of an Uno or similar. Connection to Nextion is via a small signal N channel mosfet (I used 2n7000). Pin 2 is connected to Gate and the line is also pulled low with a 10k resistor to GND. The Nextion GPIO of choice would go to Drain with Source connected to GND. As Input binding mode appears to set the pin to 'input pullup' this arrangement gives us the necessary inverting logic.


Bind some logic in a simple HMI, I just went for a b0 press event to increment n0.val (Number box) with n0.val++. And added a separate reset button so I could reset to zero.


The Arduino code works by typing your Hz value into a connected Serial monitor an hitting Return. 

Were set for 50% duty cycle but that can easily be changed be re-configuring the simple math.

I've tried, and it generally leads to poorer performance from Nextion. 


 

void setup() {

  pinMode(2, OUTPUT);
  digitalWrite(2, LOW); 

  Serial.begin(115200);

}

void pulseGen(uint8_t cycles) {

  uint8_t interval = 1000/(cycles*2);
  Serial.print("\nGot: ");
  Serial.print(cycles);
  Serial.println("Hz.");
  Serial.print("Pulse at: ");
  Serial.print(interval*2);
  Serial.println(" ms.");

  for (uint8_t i = 0; i < cycles; i++) {
    Serial.print(".");
    digitalWrite(2, HIGH);
    delay(interval);
    digitalWrite(2, LOW); 
    delay(interval);
  }
}

void loop() {

  while (Serial.available()) {
    uint8_t n = Serial.parseInt();
    if (n > 0) pulseGen(n);
  }  
}

  

404 is from not logged in

  - Registration first

  - email with link to set password is sent out

  - login

  - the view forums.


All the info in the Current Forum

  - work in progress

  - would be nice to have the best and current info restated

  - would indeed be okay to forget to port some

  - perhaps I can capture a knowledge base

  - work in progress, but selective info for the best of ... is desired


On my 20 p/r encoder, I was getting max 3 to 5 clicks (54-90°) before misses.

On a 360 p/r or 2500 p/r encoder ... ahhh crap.


Login should be working 


OK set me password and got successful login, when is the official switch date?


As for solving this issue, I guess we're on a non-starter. Aside from the lagging problems, there is also the rather obscure connection hardware. Break out boards with a ribbon connector are not impossible to buy, but they are not a common item either. For the average hobbyist, many will baulk at having to source from china on the lesser known online market places. Maybe not so for bulk corporate customers.


An Atmega 328p with some simple code to Nextion serial would be the way to go, and that is because overall it's the cheapest and more available option. 

Nextion GPIO's - I'm not impressed :( 


For reference here's one of very few listings I could track down.

https://www.aliexpress.com/item/DIY-FPC-FFC-10-PIN-1-00-mm-pitch-Connector-SMT-Adapter-to-2-54-mm/32805020816.html?spm=2114.search0306.4.53.u6oxwu


Later I'll show you how one can make this happen with the 328 in a short demo video....it's quite impressive=)  

Breakout with Ribbon (I make my own, but Itead sells too)

https://www.itead.cc/display/nextion/nextion-io-adapter.html

Saves the soldering


To capture a Human pressed button via the GPIO Nextion is okay

But as it being the same as an MCU IO, I have to say not so much.

Login or Signup to post a comment