I have just started developing my project with the 8 pin GPIO. I can get writeall to work(although unreliably) in tera term, and can use set 0 or set 1 to turn on a LED. I need to toggle two pins from high to low simultaneously from inside a C++ program. So far I have tried strcpy(cmdBuffer, "gpio writeall 02"); strcpy(cmdBuffer, "gpio writeall 0f"); strcpy(cmdBuffer, "gpio writeall ff"); strcpy(cmdBuffer, "gpio writeall 03"); strcpy(cmdBuffer, "gpio writeall ffffffff"); and other combinations. I have also tried to start the command buffer with strcpy(cmdBuffer, "gpio iodir 00 gpio writeall 02 "); as well as strcpy(cmdBuffer, "gpio iodir 00"); and then clearring the buffer and using one of the above commands. How can I get writeall to work from inside C++?
Ok, after playing with this for hours it appears that iomask has to be set first, but iodir is unnecessary. I can toggle all gpio pins by setting iomask to 0f or ff, but hexadecimal masks of 01 or 02 do not work. Currently, it is all pins or nothing. Getting rid of the char array initialization to 0x0D that is shown in the example, you can use strcpy(cmdBuffer, "\rgpio iomask 0f\r"); strcpy(cmdBuffer, "\rgpio writeall 0f\r); This ensures the carriage returns needed to send commands without needing to count characters in the array.
Hi Senseworld, Setting correct iodir value is important because this dictates if an IO is configured as an input or output when using readall/writeall commands. The readall/writeall command can still work without explicitly setting the iodir depending on the previous iodir value. For example, at power up, iodir value defaults to all inputs. Because of this, readall is going to work right away irrespective setting iodir. But writeall will not work unless iodir is appropriately set. Can you please share the complete code (or relevant part of it) so we can review and find out why you are seeing the all IOs or none behavior ? Each Io should be individually configurable using iomask command and it works just fine as far as we can see (we even use readall/writeall/iomask commands primarily for factory hardware testing since they are faster). You are right about using "\r" at the end of the string instead of appending 0x0D to the string. This is initially done to emphasize the need of the specific character at the end of the command for the command to work. Although well–intentioned, now looking at it, it seems stupid to me. We should probably change it ASAP. Thanks, Tom
Hi Tom, Thanks for your reply. I see now that setting iodir to 00 works for writeall, but I think my enumeration of the pins is causing the trouble. Without setting the mask writeall 01, turns on the first pin, and writeall 03, turns on the second pin. Shouldn't writeall 02 turn on both pins 1 and 2? Writeall 0f turns on all pins, and writeall 13 turns on an unknown number of pins but the 1 and 2 pin are on. With a mask of 03 writeall 03 turns on both pins. With a mask of 05, only one pin is writeable. With a mask of 07 writeall 03 turns on both pins. I think a chart of pins and masks in the documentation would be helpful, as right now I can kind of see a pattern, but have to use trial and error to determine which pins I'm toggling.
I'm not sure if I'm right but my guess the confusion here stems from the fact that the iomask and iodir command arguments are bitfields rather than simple numbers. For example, 01 translates to 0000 0001 in binary and will affect the lowest GPIO number, 03 translates to 0000 0011 and this will affect the first two GPIOs and so on. It looks like the user manual does not talk about in very detail but the command table has the following. I must admit that these commands are slightly bit more complex than the regular commands but they are much more powerful and offer a lot more flexibility. We are working on some knowledge base articles like this one and certainly will write an article about about using readall/writeall and associated commands in the near future. Thanks, Tom
Ok, I get it now. iodir/iomask/writeall/readall all take bitwise arguments. I had misread it initially to say that iodir only took 0 or 1 as an argument, but it was referring to bits being on or off. Thank you for clarifying.
You are most welcome. We have added a new KB article (link below) on how readall/writeall works on relay modules. While this article is specifically written for relay modules in mind, the basic concepts of readall/writeall commands are same on GPIO modules as well. We are working on another articled dedicated for GPIO modules where we talk about iodir and iomask commands as well. https://docs.numato.com/knowledge/understanding-readallwriteall-commands-for-relay-modules/ Thanks, Tom Numato Lab