Sharing part between usb and an at-09 on a nano 328p

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I am using 328p nano clones to build sprinkler controllers, garden monitors, and the like.  It looks like the best balance of cheap and low consumption (ultimately, these will have solar cells charging batteries . . ).

 

The AT-09 bluetooth modules with CC2541 is also nicely cheap and seems appropriate.

I'm having no problems talking to the AT-09 on a software serial line while the nano is connected to the computer by USB.  But this seems grossly inefficient and inelegant.

I need to program the sketch (and probably dozens of fixes) by the UART, but the USB port will sit empty once deployed.

 

The AT-09 most commonly comes attached as a daughter board to a larger circuit with six pins, power, tx/rx. enable, and reset.

I can find plenty of comments on reset, but can't find anything on Enable (and my web searching is probably impaired by other uses). With Enable floating, the device works.

My thinking on the best way to handle this would be to assert Not-Enable when the USB is connected, taking this to mean that it is being programmed.

 

As near as I can tell, the only way I'll be able to detect this is by the +5 signal being present when connected to USB, and not when I'm running on from a converter. 

 

Does that make sense so far?

 

And if that's the case, I could assert not-enable by using a simple transistor amplifier with a resistor connecting the +5 to the base?

 

And if that's right, would this be NPN with collector on +5 if I want high, and PNP to ground if I want low (it's been a couple of decades since I've worried about transistor amplifiers!)

 

Power efficiency  isn't an issue when connected, and it would seem that this design would use none (save perhaps leakage) when +5 wasn't present.

 

thanks

 

hawk

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem is that serial ports are not intended to multiplex. Yes, you can effectively do that on the M328 but on your two serial clients, there probably is no way. The issue is the Tx on each device is in conflict with the other. Unless you have a way to disable that client output, you will run into problems. You might do it with CMOS logic but that would not be consistent with using an off-the-shelf Arduino.

 

Of course, there is also a conflict on the Rx inputs. When connected together each will also hear what is sent to the other. So, a similar CMOS logic multiplexer (maybe one IC used for both Tx and Rx circuits).

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Nov 21, 2018 - 12:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those are, basically, my concerns.

 

There isn't a situation where I would want both serial going--either it's being programmed and I don't want the bluetooth , or it's not being programmed so I don't need the USB.

 

My focus is on flat-out disabling the AT-09.  It *seems* to have an input  for this, but I can't find any documentation (and from the circuits I've found, it seems to go to a digital input of the CC2541, so I'm looking at an electrical rather than software solution (I could just connect 5v through pulldown to an input, I suppose, but by the time software executed to test this and disable, the AT-09 and USB would already be fighting . . .)

 

Hmm, if the AT-09 starts with its TX in a float state, that could solve things . . .there seems to be a USBDevice.detach() that I could call before initializing it.

 

But it would seem that any project which wants to use the UART for anything other than installing the sketch would have to have dealt with this--unless it physically disconnects the serial project stuff before connecting to the programmer!
 

thanks

 

hawk

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dochawk wrote:
I can find plenty of comments on reset, but can't find anything on Enable (and my web searching is probably impaired by other uses). With Enable floating, the device works.

I did some googling and also did not come up with any useful info on the enable pin, so time to do some experimenting with the pin.

I'd begin with a VOM and see what you find on the pin when unconnected, is it pulled up to 5v or 3.3v?

what happens when it is grounded or if near ground when open, pulled up to 3.3v?

 

Inquiring minds want to know!  smiley

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Consider using the Arduino SoftwareSerial port library to communicate with the AT-09.  I find that it works well up to 115.2Kbaud, as long as the incoming data does not overflow the RX input buffer (32 bytes in size, probably adjustable).  It's fine for sending commands to peripherals and displaying status messages on PC terminals.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

 

I did some googling and also did not come up with any useful info on the enable pin, so time to do some experimenting with the pin.

I'd begin with a VOM and see what you find on the pin when unconnected, is it pulled up to 5v or 3.3v?

what happens when it is grounded or if near ground when open, pulled up to 3.3v?

 

My parts bin has some digital voltage displays.

 

I disconnected TX and RX from the MCU, leaving only VCC & ground connected.

 

Unfortunately, TX shows 2.91v with the AT-09 powered and not connected to anything.

 

Rats . . .

 

So then I tried grounding ENABLE, and then connecting it to 3.3v and 5v, and it remained at 2.91.

 

Grr.

 

Then I changed the input power on the 09 to the nominal 3.3v--ant TX registers nothing--but the blinking light on it is still going, 

 

(Note that the voltmeter I'm using only goes down to 2.5v)

 

And at this point . . . retiring to feed 5v to the MCU, when it brings a line high (to drive the LED still having on this test board), it's at 4.2v.  HUH???  aren't these boards supposed to regulate the usb down to 3.3 for the 328p to run on?

 

[and with this, I must reboot this mac, as it's no longer creating /dev/cu** devices when I attach either this or the other board .  grrr.

 

Hopefully, this will be continued in a couple of minutes . . .

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dochawk wrote:
I am using 328p nano clones to build sprinkler controllers, garden monitors, and the like.  It looks like the best balance of cheap and low consumption ...
fyi, the originals are on-sale.

dochawk wrote:
But this seems grossly inefficient and inelegant.
mega328PB has two USARTs.

Four USARTs on mega4809, three on mega4808.

dochawk wrote:
As near as I can tell, the only way I'll be able to detect this is by the +5 signal being present when connected to USB, ...
USB VBUS will be present when USB SUSPEND is active.

Some USB UART have a suspend signal and/or SOF signal to the MCU.

 


Arduino Nano

ATmega328PB - 8-bit AVR Microcontrollers

Third party mega328PB boards though without a USB UART :

ATmega4809 Curiosity Nano

USB in a NutShell - Chapter 2 - Hardware, Suspend Current

 

Edit: SOF

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Nov 23, 2018 - 08:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Life interrupted (the story of my life cheeky)

 

 

Anyway, what I found was that the TXD of the AT09 is high when it comes on.

 

Also, the enable line seems to be completely ignored.

 

And then at the moment, I'm at a standstill for an apparently unrelated reason, for which I'll start a separate thread (arduino can write to serial monitor, but never gets data back).

 

I'll bump this when I get that figured out. 

 

Also, I'm now toying with the idea of powering the AT09 from an output pin of the Arduino once I'm ready for it, so I can check for the USB before bringing it up.  Both send and receive seem well within the sustained 20ma that it could put out.  Alternatively, use that line to drive a mosfet to power the AT09.

 

Or cut a trace to disable usb entirely, and just program through the header . . . though I suppose I'd still have to deal with the AT09 when programming . . .

 

[I certainly appreciate the note that the originals are on sale, but the price differences are overwhelming; I'm paying under $2 (ranges from $1.66 to $1.79) and about $1.65 for the AT-09, and plan on having a couple of dozen of these out in the garden and yard with solar cells.  Now, if someone would combine the AT09 or it's capabilities on board, or (better yet) if TI would release enough that we could program the AT-09 without a $2,000 software kit, it's cc2541 has plenty of power and lines for what I wanted to do . . .]

 

hawk

Last Edited: Sun. Dec 9, 2018 - 04:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If "cheap & low power" are important factors then bluetooth probably is not the best wireless protocol, but I haven't kept up with latest market developments.

 

Another option is to re-program the CC2541 itself. It is a fully capable uC with built in Bluetooth and omitting the AVR altogether would reduce your BOM cost and power consumption.

From what I rember the CC2541 is an 8051 class processor and therefore probably supported by SDCC, but I believe that Ti has a comnpiler and support software available for native code development on this chip.

 

Software from Ti costs USD2000? I thought that windoze compilers were downloadable for free (but not open source) from Ti.

Does Ti have it's own forums to support their hardware? 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For *most* of the TI line, there is a free suite available.  It doesn't include the cc2541.  The only thing that does is $2,000 (although there is a 30 day free trial).  

TI doesn't release the info needed to call the library; that's known only to the high end suite.

 

For most of these, the task is really read temperature/humidty/soil sensor, and transmit; check battery voltage and solar panel voltage and start/end charging if appropriate, and (the only one that needs real juice); receive any instructions from central.  Either by its own program on central, it might flip a water valve  for some interval. (smaller garden valves, not full size sprinkler valves!  Those take a few watts to keep open!)

 

I'm assuming 18650 type  batteries  ($2-$3 each, 3.7v nominal, 3-4AH, and operating them in a restricted charge range for long life).

 

For any of this, minute by minute is overkill (unless water is running).  

 

But no-one without that suite has been able to code a cc2541 yet :(

 

The cc2541 even has 128 bit AES encryption onboard . . .

 

Anyway, I'm assuming BLE, not regular bluetooth.  

 

If I step on something that cost $8-10 in the garden, I can comfort myself with the tomatoes it lets me grow out of season.  But at $30 a unit, and a dozen or two units, it hurts . . . 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assumed you are familar with and/or have considered other RF options. Is this correct?

nRF24L01+ tends to be popular because it is one of the cheapest, but I do not like the internals of this chip. Some crasy stuff about juggling with "data pipes" to get it to work.

 

I've also bought some HopeRF RFM69W modules. These are supposed to have better range, because of the lower operating frequency, but I have not used them yet.

Plenty of software libaries floating around though (Search github directly, it is a great source for source code and it is badly indexed with regular search engines).

Prices of these module's are comparable with BLE modues. But do some research, these modules come in a lot of different variants.

 

If you want some compatibility between a PC and your garden modules you could make a bridge to translate between BLE & the Hope RF modules, but that would still need a working BLE module.

ESP8266  is a very popular and cheap microcontroller with a built in WiFi radio. It is not the lowest power, as keeping a WiFi connection alive takes some power, but if you plug it in a convenient wall socket it could translate between WiFi and Hope_Rf.

 

Have you considered motor powerd ball valves?

I do not know how much energy they need to open or close, but no energy is needed to keep them open.

There are also commercial water timers available, which run of batteries, but I've never looked into how they work.

 

Did a quick peek on Ali. Some have "ball valve" in the description, while others have "solenoid valve" in the description.

http://www.aliexpress.com/wholesale?SearchText=water+timer

 

It might be worth considering buying these for the hardware alone and replace the electronics.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Mon. Dec 10, 2018 - 09:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:

I assumed you are familar with and/or have considered other RF options. Is this correct?

 

In a lukewarm kind of way :)

 

I really hadn't seriously thought of anything but WiFi and bluetooth, and found BLE while checking those out.

 

Quote:

nRF24L01+ tends to be popular because it is one of the cheapest, but I do not like the internals of this chip. Some crasy stuff about juggling with "data pipes" to get it to work.

 

I just ordered a coupe of those to play with.  65 cents is hard to argue with if I can make them work . . . They'll use more pins for the interface, but I'll ned to use SPI for the sensors, anyway (so I save a pin, I think).  I'll look closer tomorrow.

 

Quote:

I've also bought some HopeRF RFM69W modules. These are supposed to have better range, because of the lower operating frequency, but I have not used them yet.

 

I'll check those, too.   I don't think the corners of my lot are more than 100 ft from where the central (a raspberry pi0w?) will sit.

 

Quote:

ESP8266  is a very popular and cheap microcontroller with a built in WiFi radio. It is not the lowest power, as keeping a WiFi connection alive takes some power, but if you plug it in a convenient wall socket it could translate between WiFi and Hope_Rf.

 

The bits about the yard don't need to stay up; checkin every minute would be overkill.  For the dedicated central unit, power won't be a problem, as it will have AC.

 

Quote:

Have you considered motor powerd ball valves?

I do not know how much energy they need to open or close, but no energy is needed to keep them open.

 

I looked a couple of months ago, and didn't find any latching ones that didn't seem to have a significant power budget.  I think the best I came to ws 12v or 6v, and a quarter or half amp.  This time through, I found that some call themselves "pulse" instead, and ordered one of these to play with:

 

https://www.aliexpress.com/item/1-2-DC-3-6V-Water-Valve-Control-Electric-Pulse-Solenoid-Valve-Accessory-Durable-Plastic-White/32883297754.html

 

3.6v , 9 ohm coil, and 30ms puse.  so 400 ma by my calculations, or 12mas.  Assuming that it can actually drop down a bit in voltage, I should be able to just engage the raw battery voltage (I won't be charging to full voltage to enhance battery life).

 

Quote:

There are also commercial water timers available, which run of batteries, but I've never looked into how they work.

 

Now that would hardly be sporting :) 

 

I've gotten fed up with the commercial controllers.  They fail in this climate.   Even the higher end Orbit I got last time lost a couple of lines, and I didn't notice until too late.

 

So something that displays that the soil is to dry will give me warning.

 

 

I have three sprinkler lines in front and one in back.  Also in back are three lines for garden, trees, and berrys/grapes. All currently use 24vac sprinkler valves (with pressure reducers for the non-lawn).

 

In the next month and a half, I need a simple controller to turn on water for a minute every hour during the day and perhaps every two hours between sundown and sunrise.  Otherwise, the new lawn will die a miserable death (I live in the desert).

 

Making that run the other three controllers won't be hard, but the first one implemented will probably mean reprogramming for every change in schedule.

 

That done, I'll start implementing the temperature and moisture sensors that radio in.

 

Stage thee would involve repurposing one of the pvc water circuits to be on full time, using local units, perhaps tree by tree, and groups of wine, berry, and garden sections.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I too have wanted to implement some type of watering control for the backyard garden and looked at solar power and RF, but have decided to experiment using RS-485 or 20ma loop instead as it can provide both command / control as well as power for control valves as well.   A couple of twisted pairs stapled to the ground will quickly be covered by the growing grass and disappear in a week or so.  

Any way, I'm interested in your progress with the project, keep us posted.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Gee, and 20ma would make it *so* say to get a printout cheeky

 

At this point, I think I've discovered enough to conclude that it is *impossible* to share the part with an AT-09 on any arduino with built-in USB without extreme contortions.

 

The AT-09 draws power parasitically from its RX pin, so it functions eve with power cut off to UCC.  So maybe some extreme version of isolating both RX, TX, and VCC with mosfets or something like a 4066 (but that particular would have more than a two volt drop across the switch at 20ma, not leaving much for the AT-09!), and then again for the TX on the USB since it's standby state is also apparently high . . . and enough pulldown/up to make sure that the AT was disabled on boot . . .  *blechh*

 

Edit:  on top of that, even *without* onboard usb, it looks like there will still be a conflict while programming unless I electrical isolate the TX of the bluetooth module (or any other serial device that defaults to TX=HIGH) while programming.

 

Last Edited: Sat. Dec 15, 2018 - 01:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dochawk wrote:
At this point, I think I've discovered enough to conclude that it is *impossible* to share the part with an AT-09 on any arduino with built-in USB without extreme contortions.
mega32U4 has a USB device controller and one USART; so, Arduino Leonardo, Arduino Micro, PJRC Teensy 2, or multiple Pololu boards.

 

Arduino Leonardo with Headers

Arduino Micro

PJRC Store - Teensy 2.0 Pins

ATmega32U4 - 8-bit AVR Microcontrollers - Microcontrollers and Processors

Pololu - A-Star Programmable Controllers

 

P.S.

A megaAVR with external USB on-board (USB UART bridge, EDBG debugger, DGI) with 3 spare USARTs :

ATmega4809 Curiosity Nano

though not Arduino.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A thought that hit me this morning . . .

 

What about putting a resistor (1k? 10k?) between the serial peripheral TX and the arduino RX on a non-usb such as mini pro? Kind of a "strong pullup" to the state of the TX.

 

Then when a programmer attaches at full voltage, that signal would be dominant regardless of what the peripheral doe.

 

There would be some wasted energy, but would this work?  And would it toast anything?

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Two examples of such are "Shared Use of SPI Programming Lines" and "Shared Use of JTAG Lines" in AVR042: AVR Hardware Design Considerations

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

Two examples of such are "Shared Use of SPI Programming Lines" and "Shared Use of JTAG Lines" in AVR042: AVR Hardware Design Considerations

 

 

Wow.  That's a *great* reference.

 

 

Although it doesn't seem to directly reference the UART, those connect to other digital pins, which would presumably be the same.

 

Although my paranoia will probably have me wait until there's a second 3.3v pro mini around just in case :)