Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C Wire Library not working with G2553 LP #486

Closed
mringwal opened this issue Oct 7, 2014 · 57 comments
Closed

I2C Wire Library not working with G2553 LP #486

mringwal opened this issue Oct 7, 2014 · 57 comments

Comments

@mringwal
Copy link

mringwal commented Oct 7, 2014

I don't see anything happen on pins 9/10 (p2.1/p2.2) or 14/15 (p1.6/p1.7) when running the master_write example from the Wire library.

Same example with the 5529LP has a working I2C on 14/15 (p3.0/p3.1).

It would be great, if the details of the Wire lib (it's not on the 9/10 as shown on the Booster Pack docu) could be added somewhere.

(I've connected a Logic16 to check the output)

@rei-vilo
Copy link
Member

rei-vilo commented Oct 7, 2014

How surprising! Can you share the code?
Don't forget about external pull-up resistors. 10 kΩ are fine.

@mringwal
Copy link
Author

mringwal commented Oct 7, 2014

It's just the master_write code from the examples. I have the pull ups and the same "booster pack" works (at least there's an i2c signal) with the 5529 LP

@rei-vilo
Copy link
Member

rei-vilo commented Oct 7, 2014

The I²C bus on pins 9/10 isn't available for the MSP430G2553.

You need to use the software I²C library instead.

@mringwal
Copy link
Author

mringwal commented Oct 7, 2014

I understand that i2c isn't available on 9/10. On the 5529LP it is available (without additional config) on 14/15. I assumed that it would also be available on 14/15 on the G2553.

@rei-vilo
Copy link
Member

rei-vilo commented Oct 7, 2014

Yes, that's the case.

The I²C bus uses pins 14/15 on the MSP430G2553 and I'm using them on a daily basis.

@mringwal
Copy link
Author

mringwal commented Oct 7, 2014

Ok, so that's what's not working. I don't see any data on 14/15 on the MSP-EXP430G2 with G2553 chip using Energia 13

@rei-vilo
Copy link
Member

rei-vilo commented Oct 7, 2014

Ok, now try the very same sketch with the previous release of Energia 0101E0012.

@mringwal
Copy link
Author

mringwal commented Oct 7, 2014

Energia 12, same behavior -> nothing happens.
Can I use the twi implementation directly?

@mringwal
Copy link
Author

mringwal commented Oct 8, 2014

I just realized that there also might be a hardware problem with this particular LP. I'll try once more with a second board (should be still be packaged up).

@robertinant
Copy link
Member

@mringwal were you able to get this working?

@mringwal
Copy link
Author

Thanks for reminding. So, I've just unwrapped another 430G2 and uploaded the master_writer example. Same result: I don't see anything on 14/15 yet.

I did solve my actual problem using Rei's Software I2C, but using the lower level i2c routines directly. My I2c chip requires to check ACK/NACK after writing the address. I didn't see how to do that with the original Wire interface.

So, if somebody has a few minutes of time and two extra pull-ups to VCC, please check i2c on a G2 board. .. and/or.. add the I2C docu from Arduino.cc plus mention where/how it can be used.

@robertinant
Copy link
Member

Will try reproduce on monday.

@robertinant
Copy link
Member

I just tried to reproduce but it's working for me. Make sure that you remove J5 (P1.6) to disable the connection to LED2 which interferes with SCL.

@mringwal
Copy link
Author

Hi. Confirmed to be working after removing JP (P1.6), thanks for this little detail!

So the new "issue" is: where/how should have I read that:

  • I2C is on 14/15 and not on 9/10 as indicated on the LaunchPad pin outs
  • I have to remove JP5 to get it working?

While technically obvious/trivial, almost everyone that will try to use i2c will just fail and be at the mercy of an issue tracker (filing non-issues) or the 430oh IRC channel (very helpful), or just complain on their favorite communication channel.

@rei-vilo
Copy link
Member

Please refer to the pins maps specifically designed for Energia.

for MSP430G2, http://energia.nu/pin-maps/guide_msp430g2launchpad/

@mringwal
Copy link
Author

Thank you! I remember that I was directed to this page after I couldn't get UART debut output as the jumpers had to be "rotated".
Can we add a short paragraph on i2c there? Like..

== Wire interface, I2C ==
Please note that the I2C peripheral is on pins 14/15 instead of pin 9/10 as indicated on newer LaunchPad BoosterPack Pinouts. Please refer to the pin mapping here.
Also, LED2 is controlled via P1.6, which is used for I2C SCL. too. To use I2C, please remove jumper JP 5/P1.6

@rei-vilo
Copy link
Member

Unfortunately, I don't have access to the wiki section. But everything is clearly stated on the map:

capture 2014-10-16 a 12 52 35

@mringwal
Copy link
Author

Robert has :0)

I'm not saying the map is incorrect. It is correct.

@spirilis
Copy link

Yeah, probably worth a footnote on the Energia page. paging @robertinant ... Right under the "Serial port communication, Hardware UART" section near the bottom, something like this-

I2C support

  • All G2 LaunchPads - If you want to use Hardware I2C (Wire library) with SCL on P1.6 and SDA on P1.7, you need to supply external pullup resistors between P1.6-Vcc and P1.7-Vcc. Values under 10K ohm typically work; 4.7K is often quoted as a default. Note you should remove the P1.6 jumper down below (GREEN LED) so the LED doesn't interfere with the I2C SCL signal.

@robertinant
Copy link
Member

Website has been updated with a note on I2C.

@mringwal
Copy link
Author

Thanks!

@martin43211
Copy link

Hey guys,
sorry to warm up this post again but I experience a problem with the I2C device addresses ALTHOUGH I took the jumper from Pin 1.6 to the LED out. I connected a GY-521 gyrosensor to Pin1.6 (SCA) and Pin1.7 (SCL). Pin AD0 is going to GND. VCC to VCC. I use the I2C scanner code from: http://playground.arduino.cc/Main/I2cScanner

I get this output in the Serial Monitor:
Scanning...Found Address 0x01,
Scanning...
I2C device found at address 0x01 !
I2C device found at address 0x02 !
I2C device found at address 0x03 !
I2C device found at address 0x04 !
I2C device found at address 0x05 !
I2C device found at address 0x06 !
I2C device found at address 0x07 !
I2C device found at address 0x08 !
I2C device found at address 0x09 !
I2C device found at address 0x0A !
I2C device found at address 0x0B !
I2C device found at address 0x0C !
I2C device found at address 0x0D !
I2C device found at address 0x0E !
I2C device found at address 0x0F !
I2C device found at address 0x10 !
I2C device found at address 0x11 !
I2C device found at address 0x12 !
I2C device found at address 0x13 !
I2C device found at address 0x14 !
I2C device found at address 0x15 !
I2C device found at address 0x16 !
I2C device found at address 0x17 !
I2C device found at address 0x18 !
I2C device found at address 0x19 !
I2C device found at address 0x1A !
I2C device found at address 0x1B !
I2C device found at address 0x1C !
I2C device found at address 0x1D !
I2C device found at address 0x1E !
I2C device found at address 0x1F !
I2C device found at address 0x20 !
I2C device found at address 0x21 !
I2C device found at address 0x22 !
I2C device found at address 0x23 !
I2C device found at address 0x24 !
I2C device found at address 0x25 !
I2C device found at address 0x26 !
I2C device found at address 0x27 !
I2C device found at address 0x28 !
I2C device found at address 0x29 !
I2C device found at address 0x2A !
I2C device found at address 0x2B !
I2C device found at address 0x2C !
I2C device found at address 0x2D !
I2C device found at address 0x2E !
I2C device found at address 0x2F !
I2C device found at address 0x30 !
I2C device found at address 0x31 !
I2C device found at address 0x32 !
I2C device found at address 0x33 !
I2C device found at address 0x34 !
I2C device found at address 0x35 !
I2C device found at address 0x36 !
I2C device found at address 0x37 !
I2C device found at address 0x38 !
I2C device found at address 0x39 !
I2C device found at address 0x3A !
I2C device found at address 0x3B !
I2C device found at address 0x3C !
I2C device found at address 0x3D !
I2C device found at address 0x3E !
I2C device found at address 0x3F !
I2C device found at address 0x40 !
I2C device found at address 0x41 !
I2C device found at address 0x42 !
I2C device found at address 0x43 !
I2C device found at address 0x44 !
I2C device found at address 0x45 !
I2C device found at address 0x46 !
I2C device found at address 0x47 !
I2C device found at address 0x48 !
I2C device found at address 0x49 !
I2C device found at address 0x4A !
I2C device found at address 0x4B !
I2C device found at address 0x4C !
I2C device found at address 0x4D !
I2C device found at address 0x4E !
I2C device found at address 0x4F !
I2C device found at address 0x50 !
I2C device found at address 0x51 !
I2C device found at address 0x52 !
I2C device found at address 0x53 !
I2C device found at address 0x54 !
I2C device found at address 0x55 !
I2C device found at address 0x56 !
I2C device found at address 0x57 !
I2C device found at address 0x58 !
I2C device found at address 0x59 !
I2C device found at address 0x5A !
I2C device found at address 0x5B !
I2C device found at address 0x5C !
I2C device found at address 0x5D !
I2C device found at address 0x5E !
I2C device found at address 0x5F !
I2C device found at address 0x60 !
I2C device found at address 0x61 !
I2C device found at address 0x62 !
I2C device found at address 0x63 !
I2C device found at address 0x64 !
I2C device found at address 0x65 !
I2C device found at address 0x66 !
I2C device found at address 0x67 !
I2C device found at address 0x68 !
I2C device found at address 0x69 !
I2C device found at address 0x6A !
I2C device found at address 0x6B !
I2C device found at address 0x6C !
I2C device found at address 0x6D !
I2C device found at address 0x6E !
I2C device found at address 0x6F !
I2C device found at address 0x70 !
I2C device found at address 0x71 !
I2C device found at address 0x72 !
I2C device found at address 0x73 !
I2C device found at address 0x74 !
I2C device found at address 0x75 !
I2C device found at address 0x76 !
I2C device found at address 0x77 !
I2C device found at address 0x78 !
I2C device found at address 0x79 !
I2C device found at address 0x7A !
I2C device found at address 0x7B !
I2C device found at address 0x7C !
I2C device found at address 0x7D !
I2C device found at address 0x7E !
done

The GY-521 has pull-up resistors on-board which I measured: The voltage from SDA-GND and SDL-GND is 3.3V. Does anybody have a suggestion how to find my mistake?
Cheers and thanks in advance,
M

@StefanSch
Copy link

Hi,
with Energia17 the default pins for the I2C have been changed to pin 9 and 10 so that it is consistent for all Launchpads. Unfortunately the pin map picture for this Launchpad have not been updated so far.
So either connect to the pins 9 and 10 or switch to the alternate I2C bus with
Wire.begin(0); // join i2c bus (address optional for master)
or
setModule(0);

@rei-vilo
Copy link
Member

I've updated the pins map some time ago but it hasn't been published.

launchpads msp430g2 pins maps

@StefanSch
Copy link

Yes, I just sent a note again and requested the update.

@martin43211
Copy link

Hi Stefan and rei-vilo,
thanks for your fast replies and inputs. So I tried switching the SDA and SCL ports from pins 1.7 and 1.6, respectively to pins 2.2 and 2.1 and did NOT change the Wire.begin(); in the example from:
http://playground.arduino.cc/Main/I2cScanner
Then the I2C scanner gives out this:

I2C Scanner
Scanning...
Unknow error at address 0x01
Unknow error at address 0x02
Unknow error at address 0x03
Unknow error at address 0x04
Unknow error at address 0x05
Unknow error at address 0x06
Unknow error at address 0x07
Unknow error at address 0x08
Unknow error at address 0x09
Unknow error at address 0x0A
Unknow error at address 0x0B
Unknow error at address 0x0C
Unknow error at address 0x0D
Unknow error at address 0x0E
Unknow error at address 0x0F
Unknow error at address 0x10
Unknow error at address 0x11
Unknow error at address 0x12
Unknow error at address 0x13
Unknow error at address 0x14
Unknow error at address 0x15
Unknow error at address 0x16
Unknow error at address 0x17
Unknow error at address 0x18
Unknow error at address 0x19
Unknow error at address 0x1A
Unknow error at address 0x1B
Unknow error at address 0x1C
Unknow error at address 0x1D
Unknow error at address 0x1E
Unknow error at address 0x1F
Unknow error at address 0x20
Unknow error at address 0x21
Unknow error at address 0x22
Unknow error at address 0x23
Unknow error at address 0x24
Unknow error at address 0x25
Unknow error at address 0x26
Unknow error at address 0x27
Unknow error at address 0x28
Unknow error at address 0x29
Unknow error at address 0x2A
Unknow error at address 0x2B
Unknow error at address 0x2C
Unknow error at address 0x2D
Unknow error at address 0x2E
Unknow error at address 0x2F
Unknow error at address 0x30
Unknow error at address 0x31
Unknow error at address 0x32
Unknow error at address 0x33
Unknow error at address 0x34
Unknow error at address 0x35
Unknow error at address 0x36
Unknow error at address 0x37
Unknow error at address 0x38
Unknow error at address 0x39
Unknow error at address 0x3A
Unknow error at address 0x3B
Unknow error at address 0x3C
Unknow error at address 0x3D
Unknow error at address 0x3E
Unknow error at address 0x3F
Unknow error at address 0x40
Unknow error at address 0x41
Unknow error at address 0x42
Unknow error at address 0x43
Unknow error at address 0x44
Unknow error at address 0x45
Unknow error at address 0x46
Unknow error at address 0x47
Unknow error at address 0x48
Unknow error at address 0x49
Unknow error at address 0x4A
Unknow error at address 0x4B
Unknow error at address 0x4C
Unknow error at address 0x4D
Unknow error at address 0x4E
Unknow error at address 0x4F
Unknow error at address 0x50
Unknow error at address 0x51
Unknow error at address 0x52
Unknow error at address 0x53
Unknow error at address 0x54
Unknow error at address 0x55
Unknow error at address 0x56
Unknow error at address 0x57
Unknow error at address 0x58
Unknow error at address 0x59
Unknow error at address 0x5A
Unknow error at address 0x5B
Unknow error at address 0x5C
Unknow error at address 0x5D
Unknow error at address 0x5E
Unknow error at address 0x5F
Unknow error at address 0x60
Unknow error at address 0x61
Unknow error at address 0x62
Unknow error at address 0x63
Unknow error at address 0x64
Unknow error at address 0x65
Unknow error at address 0x66
Unknow error at address 0x67
Unknow error at address 0x68
Unknow error at address 0x69
Unknow error at address 0x6A
Unknow error at address 0x6B
Unknow error at address 0x6C
Unknow error at address 0x6D
Unknow error at address 0x6E
Unknow error at address 0x6F
Unknow error at address 0x70
Unknow error at address 0x71
Unknow error at address 0x72
Unknow error at address 0x73
Unknow error at address 0x74
Unknow error at address 0x75
Unknow error at address 0x76
Unknow error at address 0x77
Unknow error at address 0x78
Unknow error at address 0x79
Unknow error at address 0x7A
Unknow error at address 0x7B
Unknow error at address 0x7C
Unknow error at address 0x7D
Unknow error at address 0x7E
No I2C devices found

When I switch back to the old configuration (Pin1.7 -> SDA and Pin 1.6 -> SCL, and Jumper from Pin 1.6 to LED2 removed ) and include change the Wire.begin() to Wire.begin(0), I get the same output as in my first post:

Scanning...
I2C device found at address 0x01 !
...you get the picture.

Do you have any other suggestions? I have a GY-521 connected to the MSP430. The AD0 pin is connected to ground (then the device should have the address 0x68) and there are pull-up resistors on-board. It perfectly works with an Arduino Uno

@martin43211
Copy link

Hey,
the Wire.h and Wire.cpp are in the MPS430/cores/ folder and I found that this should not be a problem. Moved them to MSP430/libraries/Wire and still there is no effect except that I can now add the Wire.h library in Energia via Sketch -> Import Libraries which was not possible before.
Unfortunately I have no idea anymore and will use the Arduino for now since I just started with µCs and don't want to frustrate myself right from the start. Would be interested though if you find a solution.

@martin43211
Copy link

The only last thing I found is that, when I connect the SCL and SDA pins to GND and VCC, respectively, I get different outputs of the I2C scanner. For the connection to GND, I get:

Unknown error at address ... (a long list with all addresses)

and when I connect them both to VCC:

I2C device found at address ... (a long list with all addresses)

@StefanSch
Copy link

Did some more test and found that this might never has worked.
Just commited a version which does support the scanning of the I2C slaves:
https://github.com/energia/Energia/pull/868/files

@StefanSch StefanSch reopened this Apr 6, 2016
@StefanSch
Copy link

fix is available with pull request #868

@simseve
Copy link

simseve commented Apr 7, 2016

Thanks StefanSch. How can I try your mods on my side (procedure to include your changes)?thanks

@StefanSch
Copy link

You can download the raw file from git hub and replace it within your energia system:
https://raw.githubusercontent.com/energia/Energia/issue_486/hardware/msp430/cores/msp430/twi.c
https://raw.githubusercontent.com/energia/Energia/issue_486/hardware/msp430/cores/msp430/twi_sw.c

They are located in this path:
.../hardware/msp430/cores/msp430

@curtis63
Copy link

curtis63 commented Apr 8, 2016

I am having the same problem as above. Just purchased a brand new Launchpad for G2 from TI. I attached a sensor to it. I am able to successfully communicate with the sensor and get data from it, however, when I run the scanner, I get a device found at all addresses, even though there is only a single sensor.

@rei-vilo
Copy link
Member

rei-vilo commented Apr 8, 2016

Which I²C port are you using?

Default I²C port uses pins 9 and 10 now.

@rei-vilo
Copy link
Member

rei-vilo commented Apr 8, 2016

msp430g2553

@curtis63
Copy link

curtis63 commented Apr 8, 2016

Pins 14/15. Aka P1.6/P1.7.

Unable to communicate with my sensor and get valid data however the scanner
program does not work. It shows something at every address.

@rei-vilo
Copy link
Member

rei-vilo commented Apr 8, 2016

Use default port.

@curtis63
Copy link

Excellent !! It does work when I use Pins 9 and 10. I was using pins 14 and 15.

We have already built a circuit board based on the older spec from 2012. It showed pins 14 and 15 as the SCL/SDA pins. Where would I change the code to switch to pins 14 and 15 instead of the defaults. Surely it's configurable...

@StefanSch
Copy link

add a
Wire.setModule(0); // 0: indicates the bus as shown in the pin map
before the
Wire.begin(); // join i2c bus (address optional for master)

@curtis63
Copy link

YAY !!! It works !! I was having grief with it and then pulled my brain out and removed the Jumper that was attaching the LED to P1.6, and all things work correctly now.

Thank you for your assistence !!!

@curtis63
Copy link

So, my Launchpad uses a 20 pin MPS430G2553 chip. On it, P1.6 is pin 14 and P1.7 is pin 15. However, TI makes a 28 pin MPS430G2553 chip. On it, P1.6 is pin 22 and P1.7 is pin 23.
P1.4 is pin 6 and P1.5 is pin 7 on both the 20 pin and the 28 pin MPS430G2553 chip.

Is this going to cause problems using the library with Wire.setModule(0); specified?

@StefanSch
Copy link

If you go to the 28 pin device the I2C should work as well as the I2C is on the same port pins.
And this is set in the
....\hardware\msp430\variants\launchpad\pins_energia.h
file.
But you will get a lot of issues on the other pins as the mapping of the pin assigned to the Launchpad and the device will not map.
So you may should consider to generate a own pins_energia.h if this is required.

@curtis63
Copy link

Sounds good. My colleague will be testing this on the 28 pin chip tomorrow. I have heard people express concerns about the efficiency of using Energia vs standard C code when programming the MSP430G2553 controller. They are worried about efficiency and about battery power. What is your opinion about the pros and cons of using Energia vs standard C code ?

I LOVE the ease of use of the language and libraries. Nice to have a layer of abstraction over the direct calls that standard C requires.

@StefanSch
Copy link

Thanks for the info - it always helps to get the confirmation that a fix is working.

It is a good question to ask about the pros and cons of Energia vs standard c code.
I am sure we could have a discussion over a whole evening with some beers.
... and it could also become very philosophic.....

Finally let me try go give you an answer which expresses my opinion:
If you need to have a code which is optimized to the final line of code for either execution speed or energy consumption Energia is the wrong tool.
If you would like to have a fast prototype or if you not have the time, passion and technical understanding to go down to each configuration bit of a microcontroller energia is a perfect tool.
Anything between is up to the user.
If you look for efficiency and battery power you can also with Energia build systems which are highly efficient and working for a very long time. But there are some considerations and limitations you may need to be aware of. If you ratio of active time to low power mode time is very high - means you are long time in low power modes, then you will most properly not see a big difference.
If you have to wake up very often the it depends if the wake up is mainly handled in an interrupt service routine / handler then it also depends only on your programming skills and on how you have configured the systems.
If you wake up very often and always have to go through the loop function then you can might see a higher current consumption in energia.
But keep in mind this always depends on how well you know the microcontroller and your skills to optimize your application code for the lowest power consumption base on this device and your use case.

Finally - even as i know the msp430 very well for many, many years i am contributing to this tool as i am convinced from the easy of use, the fast way of building applications and the ecosystem of launchpads and boosterpacks where it is build around.
It makes so many things so easy..... just do it .....

@curtis63
Copy link

curtis63 commented Apr 13, 2016

I really appreciate your help. I’m a 20 year Software Engineer, but have never worked with controllers and firmware before. This is a big learning curve, but Energia makes it MUCH easier..

This may not be the place for technical questions, but I’m trying to get Low Power Mode implemented and saw a couple postings where they use:

disableWatchDog();
and
LPM4;

Both of the above statements make my code LOCK up when I attempt to use Serial or delay();
Do you know a good work-around for this?
I want to be in low power mode most of the time, and wake up when a sensor interrupts on a port.
Where should I look for Energia support functions for this?

@spirilis
Copy link

See sleep, sleepSeconds, suspend, and wakeup (the latter is meant for running inside ISRs).

Note you can't use Serial port I/O in low power mode, so you should Serial.flush() (to flush any pending output) before using sleep/sleepSeconds/suspend.

@curtis63
Copy link

I wish I could download your brain... Thanks so much for your help!!
On Apr 13, 2016 11:07 AM, "Eric" notifications@github.com wrote:

See sleep, sleepSeconds, suspend, and wakeup (the latter is meant for
running inside ISRs).

Note you can't use Serial port I/O in low power mode, so you should
Serial.flush() before using sleep/sleepSeconds/suspend.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#486 (comment)

@walber000
Copy link

Hello guys, I'm currently trying to use my GY-521 but I'm having this i2c problem too, the scanner either founds devices everywhere or found nothing. I already replaced the twi files from the git hub solution above, and already tried pins 9/10 and 14/15, wire.setmodule(0) and everything else =/
May anyone help me?
P.S: when I read it, it only gives 0's or -1's

@curtis63
Copy link

Did you accidentally swap SCL with SDA? Did you add pull-up resisters? Did you remove the LED jumper from P1.6?

The TWI files exist in more than one place. Did you replace them in all the places they exist on your machine?

Thanks,
Curtis

On Apr 23, 2016, at 10:15 AM, walber000 notifications@github.com wrote:

Hello guys, I'm currently trying to use my GY-521 but I'm having this i2c problem too, the scanner either founds devices everywhere or found nothing. I already replaced the twi files from the git hub solution above, and already tried pins 9/10 and 14/15, wire.setmodule(0) and everything else =/
May anyone help me?
P.S: when I read it, it only gives 0's or -1's


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@SunicYosen
Copy link

I am a lover of MSP430 launchPad! I have a problem with it. I use a MSP430G2553 as master write,and use another MSP430G2553 as slaver receiver , but slaver may receive none when writer send data to it. Where is Wrong? Thanks !Thanks!Thanks a lot!
code as follow :

slaver receiver

#include <Wire.h>

void setup()
{
pinMode(2,OUTPUT);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
digitalWrite(2,LOW); //pin 2 is a LED
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}

void loop()
{
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(Wire.available()) // loop through all but the last
{
int x = Wire.read(); // receive byte as a int
if(x == 1)
digitalWrite(2 , HIGH);
else
digitalWrite(2 , LOW);

Serial.print("Wire!\t");
Serial.println(x);         // print the integer

}
}

Master Write:

#include <Wire.h>
int x = 0;

void setup()
{
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
pinMode(2,OUTPUT);
digitalWrite(2,LOW);
}

void loop()
{
Wire.beginTransmission(4); // transmit to device #4
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
Serial.print("Send: light is :");
Serial.println(x);
x++;
if(x == 2)
x = 0;
if(x == 0)
digitalWrite(2,HIGH);
if(x == 1)
digitalWrite(2,LOW);
delay(1000);
}

@buihoangan
Copy link

Many thanks to Stefansch, I struggled this problem for few days before read this topic. On launchpadg2553 just one I2C module and the default i2c pins are 9 and 10, not change to pin 14 and 15.

@AB2203
Copy link

AB2203 commented Feb 24, 2018

I'm trying to use the BH1750 light sensor with the MSP430 G2553
I'm new to using the launchpad and microcontrollers.
This is the code:
#include <BH1750FVI.h> // Sensor Library
#include <Wire.h> // I2C Library
uint16_t Light_Intensity=0;
BH1750FVI LightSensor;

void setup() {

Serial.begin(9600);
LightSensor.begin();
LightSensor.SetAddress(Device_Address_H); //Address 0x5C
LightSensor.SetMode(Continuous_H_resolution_Mode);
Serial.println("Running...");
}
void loop()
{
Light_Intensity = LightSensor.GetLightIntensity();
Serial.print ("lux=");
Serial.print (Light_Intensity);
delay(1000);
}

I cant get the sensors to work
I'm confused about giving the connections and which pins to use for SCL and SDA
Any help will be great.

@curtis63
Copy link

curtis63 commented Feb 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests