deptowicz 0 Posted May 10, 2013 Share Posted May 10, 2013 Hello, I've just started learning the basics of launchpad programming thru the samples in energia. As an exercise, I'm trying to control the green LED intensity from the PC keyboard using code from the PhysicalPixel and Fade samples. I'm sending keyboard input via the Serial Monitor window of energia. The code successfully uploads to the msp430g2231 but I'm not getting the result I'm expecting. That is press 'H' and 'L' to increase and decrease the LED intensity. Here's the code: int brightness = 128; int incomingByte; // a variable to read incoming serial data into void setup() { Serial.begin(4800); // initialize serial communication: pinMode(GREEN_LED, OUTPUT); // initialize the LED pin as an output: } void loop() { if (Serial.available() > 0) { // see if there's incoming serial data: incomingByte = Serial.read(); // read the oldest byte in the serial buffer: if (incomingByte == 'H') { brightness = brightness + 5; if (brightness >= 255) { brightness = 255; } analogWrite(GREEN_LED, brightness); } if (incomingByte == 'L') { brightness = brightness - 5; if (brightness <= 0) { brightness = 0; } analogWrite(GREEN_LED, brightness); } } } The Communication>Dimmer sample also does not work for me. I'm under the impression that the cause of the problem is similar. Quote Link to post Share on other sites
simpleavr 399 Posted May 11, 2013 Share Posted May 11, 2013 i am not a energia user but for similar serial control do something projects, i always try to make sure the comm is ok. u can jumper the tx / rx line (join them together, crisscrossed, instead of jumper them onto the mcu device) on the launchpad and use a terminal to see if what u type actually echos back. oPossum 1 Quote Link to post Share on other sites
deptowicz 0 Posted May 11, 2013 Author Share Posted May 11, 2013 Hi, I'm pretty sure the comm is working because if I rewrite the code without the brightness settings, that is, if (incomingByte == 'H') { analogWrite(GREEN_LED, 255); } if (incomingByte == 'L') { analogWrite(GREEN_LED, 0); } the code acts exactly the way I want it. Sending 'H' switches the LED ON(255) while sending 'L' switches the LED OFF(0). It is only when I try to control the brightness values that it fails to respond. Out of curiosity, how do I use terminal to see that what I type echoes back? Quote Link to post Share on other sites
simpleavr 399 Posted May 11, 2013 Share Posted May 11, 2013 you need a serial terminal program. i don't know the capability of the comm windows on energia but it is likely it can receive chars back from the LP. i use minicom on linux and putty on windows. on the 5x2 jumper block on the LP. look for the RX and TX, pull out the jumpers for these 2. and tie the TX and RX (PC side, or USB side) together w/ a jumper cable or something. this will route what u type from the PC side immediately back to the PC. by doing so it will confirm the comm driver on the PC side (and the LP side) works properly. many times when i had comm problems, it was caused by comm drivers, etc (especially under linux when the LP was new). i can't help u w/ the pwm as i don't use energia. Quote Link to post Share on other sites
simpleavr 399 Posted May 11, 2013 Share Posted May 11, 2013 oh, it probably doesn't matter, but int brightness = 128; int incomingByte; // a variable to read incoming serial data into would usually be written as uint8_t brightness = 128; uint8_t incomingByte; // a variable to read incoming serial data into (or may be unsigned char) Quote Link to post Share on other sites
deptowicz 0 Posted May 11, 2013 Author Share Posted May 11, 2013 Thanks simpleavr for the info on using terminal. I tried using unsigned and got the same result. Quote Link to post Share on other sites
canibalimao 2 Posted June 14, 2013 Share Posted June 14, 2013 Sorry for the late reply, but maybe the problem you're getting is with analogWrite. I think that MSP430G2231 don't support analogWrite. Look at Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.