- Posts: 857
Extra inputs for Devo Tx's
- Deal57
- Offline
Cereal_Killer wrote:
Deal57 wrote: The "!=" is "Not equal". In this case you might be able to use "== 0" instead of "!= 1". It probably works either way.
Ok I'm home now and have physically removed the second switch, still the same behavior.
I dont understand why it works on yours and not on mine. Or is my thinking incorrect and you actually want your 3-way switches acting to switch two different channels so you dont have to deal with this?
Yeah, doesn't make sense... If it was me I would trace the wire connections. A 3-way switch is really just two 2-way switches back-to-back with a common ground. For a 3-way, the Arduino sets both digital ports (poles 1 and 2) high, and when you move the switch one direction it shorts that pole, bringing it low. We poll those digital ports (remember if one port is low, the other cannot be low because the switch only shorts one at a time), and we assign a pulse value to the channel based on what we see shorted.
You get a value of -100 to 0 on channel 3 only when sw1_uS is set to pulseMin or pulseMid. That only happens in this code, and only when you short to the first pole, on the Arduino pin 6.
if (digitalRead(swPin_D1) != 1) { // 3-way Switch 1 pole 1 is pin D6 on Arduino
sw1_uS = pulseMin; // 3-way switch 1 pole 1 is ON - so channel 3 is -100
} else {
if (digitalRead(swPin_D2) != 1 ) { // pin D7 on the Arduino
sw1_uS = pulseMax; // 3-way switch 1 pole 1 is off, pole 2 is on - you're not seeing this on channel 3
} else {
sw1_uS = pulseMid; // 3-way switch 1 pole 1 is off and pole 2 is off - channel 3 is 0
}
}
The only way you'll see a value 0 to 100 on channel 4 is when sw3_uS is set to pulseMid or pulseMax, and this only happens in this code here:
if (digitalRead(swPin_D3) != 1) { // 3-way Switch 2 pole 1 is pin D8 on Arduino
sw3_uS = pulseMin; // if 3-way switch 2 is ON on pole 1 - you're not seeing this on channel 4
} else {
if (digitalRead(swPin_D4) != 1 ) { // pin D9 on the Arduino
sw3_uS = pulseMax; // if 3-way switch 2 is ON pole 2 - channel 4 is +100
} else {
sw3_uS = pulseMid; // if 3-way switch 2 is in middle position - channel 4 is 0
}
}
}
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Cereal_Killer
- Offline
// 3-way Switch 1
if ((digitalRead(swPin_D1) == 0 ) && (digitalRead(swPin_D2) != 0 )) { //Pin6 on & 7 off
sw1_uS = pulseMin;
} else {
if ((digitalRead(swPin_D1) != 0 ) && (digitalRead(swPin_D2) == 0 )) { //Pin6 off & 7 on
sw1_uS = pulseMax;
} else {
if ((digitalRead(swPin_D1) != 0 ) && (digitalRead(swPin_D2) != 0 )) { //Pin6 off & 7 off
sw1_uS = pulseMid;
}
}
// 3-way Switch 2
if ((digitalRead(swPin_D3) == 0 ) && (digitalRead(swPin_D4) != 0 )) { //Pin8 on & 9 off
sw2_uS = pulseMin;
} else {
if ((digitalRead(swPin_D3) != 0 ) && (digitalRead(swPin_D4) == 0 )) { //Pin8 off & 9 on
sw2_uS = pulseMax;
} else {
if ((digitalRead(swPin_D3) != 0 ) && (digitalRead(swPin_D4) != 0 )) { //Pin8 off & 9 off
}
}
}
}
}
This should leave no doubt about what each combo of states should be doing, I'm even manually pulling the off switch's pin up for testing (watching both on devo and via the serial monitor with SerialPrint(sw1_uS) so I can see if it's registering) and no matter what it never accepts the pull-down on pin's 7 or 9 (but it does accept them on pin's 6 and 8 which is why I get one pole of each side working)
Note I've also tried using "== 1" in place of "!= 0". No effect...
Edit: Not only have I tried adding external pull-up's I have also manually shorted the input's and again got no change on the upper halves.
Edit2: Hold up, progress is happening...
Taranis X9E | DEVO 10 | Devo U7E | Taranis Q7
What I do in real life: rivergoequestrian.com/
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
Deal57 wrote:
Epitaph wrote: I've just tried out sketch on my Uno, adjusting the inputs and outputs obviously, just to make sure that there was nothing faulty with the rest of the hardware like the mono jack lead or the pots, and it works fine with the Uno, I see all the channels working great, so the problem is definitely in the Digispark.
Try this. I've put the timer and interrupt code into the sketch. Glad to hear the basic code works on the UNO, so that means we need to resolve this timer/interrupt thing.
With the digispark set to 16.5mhz it programs fine with no errors but doesn't work... on 16mhz it doesn't compile, comes up another time error again on the last line (TIMSK)
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
Epitaph wrote:
Deal57 wrote:
Epitaph wrote: I've just tried out sketch on my Uno, adjusting the inputs and outputs obviously, just to make sure that there was nothing faulty with the rest of the hardware like the mono jack lead or the pots, and it works fine with the Uno, I see all the channels working great, so the problem is definitely in the Digispark.
Try this. I've put the timer and interrupt code into the sketch. Glad to hear the basic code works on the UNO, so that means we need to resolve this timer/interrupt thing.
With the digispark set to 16.5mhz it programs fine with no errors but doesn't work... on 16mhz it doesn't compile, comes up another time error again on the last line
Well, the fact that it programs at 16.5 is good. How do you know it doesn't work? If the Devo isn't seeing it, it's probably because my code set the timer interrupt to 50ms, but it needs to be 22ms... And I didn't take the time to do the math. Sorry 'bout that. I'm new with this, too!
You could try setting the
OCR0A = F_CPU/8 * 0.000050 - 1;
to
OCR0A = F_CPU/8 * 0.000022 - 1;
Basically change the .000050 value to .000022. I don't know if it'll be right, but it's worth a try.
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Cereal_Killer
- Offline
Thank you Deal.
// 3-way Switch 1
if ((digitalRead(swPin_D1) == 0 ) && (digitalRead(swPin_D2) != 0 )) { //Pin6 on & 11 off
sw1_uS = pulseMin;
} else {
if ((digitalRead(swPin_D1) != 0 ) && (digitalRead(swPin_D2) == 0 )) { //Pin6 off & 11 on
sw1_uS = pulseMax;
} else {
if ((digitalRead(swPin_D1) != 0 ) && (digitalRead(swPin_D2) != 0 )) { //Pin6 off & 11 off
sw1_uS = pulseMid;
}
}
// 3-way Switch 2
if ((digitalRead(swPin_D3) == 0 ) && (digitalRead(swPin_D4) != 0 )) { //Pin2 on & 3 off
sw2_uS = pulseMin;
} else {
if ((digitalRead(swPin_D3) != 0 ) && (digitalRead(swPin_D4) == 0 )) { //Pin2 off & 3 on
sw2_uS = pulseMax;
} else {
if ((digitalRead(swPin_D3) != 0 ) && (digitalRead(swPin_D4) != 0 )) { //Pin2 off & 3 off
sw2_uS = pulseMid;
}
}
}
}
Edit: Still have one small bug, seems like when I move PPM4 to it's upper position PPM3 is frozen. I'll work on this a little later, maybe switch to one of my known better nano clones ($2.99 /ea instead of $1.09/ea for these really bad mini clones)
Taranis X9E | DEVO 10 | Devo U7E | Taranis Q7
What I do in real life: rivergoequestrian.com/
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
Deal57 wrote:
Epitaph wrote:
Deal57 wrote:
Epitaph wrote: I've just tried out sketch on my Uno, adjusting the inputs and outputs obviously, just to make sure that there was nothing faulty with the rest of the hardware like the mono jack lead or the pots, and it works fine with the Uno, I see all the channels working great, so the problem is definitely in the Digispark.
Try this. I've put the timer and interrupt code into the sketch. Glad to hear the basic code works on the UNO, so that means we need to resolve this timer/interrupt thing.
With the digispark set to 16.5mhz it programs fine with no errors but doesn't work... on 16mhz it doesn't compile, comes up another time error again on the last line
Well, the fact that it programs at 16.5 is good. How do you know it doesn't work? If the Devo isn't seeing it, it's probably because my code set the timer interrupt to 50ms, but it needs to be 22ms... And I didn't take the time to do the math. Sorry 'bout that. I'm new with this, too!
You could try setting the
OCR0A = F_CPU/8 * 0.000050 - 1;
to
OCR0A = F_CPU/8 * 0.000022 - 1;
Basically change the .000050 value to .000022. I don't know if it'll be right, but it's worth a try.
You may be new but you know a hell of a lot more than me!!
I have a model set up in the 7E with the 4 PPM inputs programmed in. When I tried it out with the Uno (with your original code) I had the proper movement on all 4 of the channels on the channel monitor, and just running through the DSC port (I soldered some pins to the mono jack to connect it to the breadboard, and just change the arduino being used at the time on the board with the pins). But when I remove the Uno and connect the Digispark (I completely disconnect it from the breadboard to sketch it... A because it's easier, and B because I don't want conflicts from shared ports) I don't get any results on the channel monitor at all on any of the breadboard channels (2 pots, 1 momentary switch, and 2 more momentaries sharing common to simulate a 3 way switch, as I don't have one available right now). I'm feeding it all with a regulated 5V breadboard PSU fed by a 2S LiPo, and I've checked the output which is at 4.91V, which is what I'm also using to feed the Digispark. Only wires going to the transmitter are on the 3.5mm jack, which are PPM and GND. The jack wire is one I had left over after I converted a transmitter simulator dongle to wireless using a PPM receiver, and before I had it working with the 7E, and it also works perfect with the Uno too...
The problem I am seeing with this is there could be a problem in a number of places, and we don't know which it is... it could be the timer, it could be the PPM output, but it could also be something like the inputs, although I doubt it's to do with port numbering as I've looked over a few Digispark example sketches and the port numbering seems to match up properly, as in from 0 to 5
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
When the Digispark was turning on, the PWM LED was lighting. But when I pressed the momentary switch which is simulating the 2 way switch (port 5), the LED would turn off, remain off for a few seconds, then turn back on, as if the board was resetting. I don't know if that helps at all...
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
And we can also use it to output to a serial port using softwareserial, so it we can do some debugging.
We need a timer to make sure we send the 22ms packets so there's more research needed.
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
Cereal_Killer wrote: Got it. All I can figure is pin D7 on this super cheap mini clone is either dead or is mapped wrong. Switched that pin to D11 and moved switch 2 to D2 and D3 and it's working!!!
Thank you Deal.
...
Glad to help! It occurs to me if you're having problems with pull-up pins, I wonder if your power is sufficient? It may be the cheap parts as you say, and if you're using a USB port, then it's probably a non-issue, or at least not very fixable! I often use tx/rx for programming, and I use a really good BEC or use the RAW port with >7.5 V for my Pro minis.
Anyway, I'm glad you could get it working..
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
Deal57 wrote: Oops. Pin 5 is NRESET, so if you put a switch on it, it may be actually resetting. The reset process takes about 5 seconds, because it's looking for a programming signal. So I guess we may not want to use that one... Although we can probably use it for PPM output once we get this going.
And we can also use it to output to a serial port using softwareserial, so it we can do some debugging.
We need a timer to make sure we send the 22ms packets so there's more research needed.
fingers crossed!!
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
Well, on the breadboard, anyway. The Digispark is tiny but flexible and there are a number of tricks to this. First, the way analog reads number pins is NOT the way digital pins are numbered. So if we need Analog1 as an input, we still have to set pinmode() based on the DIGITAL pin number 0-5. When we read, we use the analog pin number.
Also, I found a library to generate PPM pulses, and handles all the interrupts and timers for us. I was able to configure four channels of PPM and see the movement in the PPM inputs on my Devo7e. You need to download and install the TinyPpmGen and RcTxPop libraries to make this work.
The Digispark needs 5v and ground connected, then I connected the analog and digital pins like this (note pins are P0 through P5). Once I get a better prototype I will see what options we have for pin 5 to avoid having it reset the ATTiny85 when we use it!
// 5k POT's on JP3-2 and -4
// 3-way (On-off-On) switch on JP3-0 and-3 or two 2-ways
// 2-way (On-off) switch on JP3-5 - Currently this is a reset
// PPM output on JP3-1
I've attached my working code based on this configuration. I think the only thing it needs is a way to tweak the min and max timing. And maybe make it a bit more portable, because if we need more inputs, we can easily port this to the Digispark pro.
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
The problem I'm seeing though is the size... says here the Zip is 8kb in size, but the Digispark only has room for 6kb...
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
TinyPpmGen.cpp:66: error: missing binary operator before token "("
#define MS_TIMER_TICK_DURATION_US (MS_TIMER_TICK_EVERY_X_CYCLES / clockCyclesPerMicrosecond())
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
And there is one additional change: you need to edit the file TinyPpmGen.h and change line 47 to show
#define OC_CHANNEL CHANNEL(B)
Mine compiles to 3432 bytes.
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
I have added the libraries as you said, and I assume I have to add the tabs manually as the "add library" button in sketch just adds the "#define" line in the make sketch file... I changed line 47 (which was line 46 on mine) to channel B, but still getting it wrong.
I think I'll just end up going with the Nano in the end because all this is just way beyond me, I am doing things I am told to do with no idea whatsoever of why I am doing it, and I've never felt comfortable like that, I like to understand the basics of "why" when I do something, and this is just well above my level.
I'm glad it's working for you!!
Please Log in or Create an account to join the conversation.
- Cereal_Killer
- Offline
Deal57 wrote: Once I get a better prototype I will see what options we have for pin 5 to avoid having it reset the ATTiny85 when we use it!
Could we not just use that switch as a pull-up? Pin5 should only reset when pulled down, you should still be able to use it as a input for a + signal.
Taranis X9E | DEVO 10 | Devo U7E | Taranis Q7
What I do in real life: rivergoequestrian.com/
Please Log in or Create an account to join the conversation.
- Deal57
- Offline
- Posts: 857
@Cereal_Killer: We could also use pin 5 as an Analog input, maybe move the second POT there. Don't know if it will work, and I've got to get this spaghetti of a prototype cleaned up!
Deviation Devo7e 3way switch mod, A7105, NRF24L01
Devo6s 2x2 switch mod, trim mod, haptic, multimodule, A7105, NRF24L01, CC2500
Devo12e 4-in-1 with voice mod -- it speaks!!
Please Log in or Create an account to join the conversation.
- Epitaph
- Offline
- Posts: 291
In the mean time, I've just made a new battery for the Devo F4, as it is a power hungry one... a 2S2P 2000mAh LiPo out of two 2S 1000mAh Zippy Compacts which were just the right length and width after some cutting in the battery bay, but had plenty of height for 2 of them, so, just stacked 4 cells together!! Also removed the discharge cable and left it with just the balance wire to save space as that's what the transmitter uses, and made an adapter cable a bit like what they use to multiple charge 1S micro heli batteries to balance charge it with my imax charger. All fun and games!!
Please Log in or Create an account to join the conversation.
- Home
- Forum
- Development
- Development
- Extra inputs for Devo Tx's